The Conky Blog The Official Blog for Conky, a Lightweight System Monitor

15Sep/093

Feature Feature: A simple desktop indicator using $desktop

If you don't use a desktop pager in a panel, it's useful to have it displayed on your desktop itself. Here's a quick guide to creating a simple desktop indicator in Conky, using a combination of $image and $desktop.

To give you an idea of what we're aiming for, here's a screenshot, with the desktop indicator in the top right:

Desktop IndicatorStep 1: Make the squares

The first thing to do is to create two simple images in GIMP or similar program. You'll need one semi-transparent black square (I used 75% transparency) and one opaque white square.  You can make them as small as you like, because we'll use $image's -s flag to make them the right size in Conky (I made them 50x50px).

Step 2: Decide on the placement/layout of your desktop indicator boxes

As you can see from the example above, I use my four desktops in a line, but you may use them in a square or rectangle. You'll need to decide where to place all your squares. I did this in my head, but you may also choose to use graph paper to work it out. Conky places images using the top left corner as an anchor, so you'll be interested in the coordinates of that point for each of your squares. In my example above, the size of my Conky dictated that I placed my squares at (3,5) (47,5) (91,5) (135,5) -- starting at x=3, each square was 40px wide with 4px spacing between.

Step 3: Code your Conky!

First, draw all the black, semi-transparent squares:

${image ~/Pictures/bk_semi_trans_sq.png -p 3,5 -s 40x40}${image ~/Pictures/bk_semi_trans_sq.png -p 47,5 -s 40x40}${image ~/Pictures/bk_semi_trans_sq.png -p 91,5 -s 40x40}${image ~/Pictures/bk_semi_trans_sq.png -p 135,5 -s 40x40}

Then, use $if_match and $desktop to choose where to place the white square:

${if_match ${desktop}==1}${image ~/Pictures/wh_sq.png -p 3,5 -s 40x40}${endif}${if_match ${desktop}==2}${image ~/Pictures/wh_sq.png -p 47,5 -s 40x40}${endif}${if_match ${desktop}==3}${image ~/Pictures/wh_sq.png -p 91,5 -s 40x40}${endif}${if_match ${desktop}==4}${image ~/Pictures/wh_sq.png -p 135,5 -s 40x40}${endif}

Et voila! Enjoy your new desktop indicator!

A couple of notes:

You will need to adjust your update_interval config variable (e.g. before TEXT), depending on how responsive you want your indicator to be. I use 0.1.

This method will not work if you are running Compiz. That's because Compiz draws all of your "desktops" as virtual desktops all on one desktop. You will only ever appear to be on desktop 1! The example above was done running OpenBox as a desktop environment, with no compositing.

Filed under: Features Leave a comment
Comments (3) Trackbacks (0)
  1. Excellent howto, while I run compiz on my normal gnome session I can try this on my openbox session.

    A quick question though, if you don’t draw the squares at the size you want them and use the $image flag to scale them, isn’t Conky scaling the four images on *every* refresh, and causing an unnecessary performance hit? (as you may remember from my album art stuff, I don’t like waste) ;) )

  2. Thanks for your comment! You’re right, using a 50×50px square and resizing it isn’t the most efficient method, especially if you are using a 0.1s update interval, like I did above.

    However, I use 50×50px because I have a selection of them saved, ready for scaling and using in backgrounds, that sort of thing! If you’re just doing a one-off, then yes, it’s better to use images at the right size to begin with.

    Incidentally, there is a moderate cpu% improvement if you use 10×10px and scale up, rather than using 50×50px and scale down.

  3. where is the conkyconfig down?


Leave a comment


No trackbacks yet.

Essential Links

Categories

Archive Posts