Lua Cairo Bindings for Conky 1.7.2+…Getting Started
If you saw my last post about Lua Cairo bindings for Conky 1.7.2+, but didn't go any further with it, then you're not alone! It's pretty daunting at first, especially if you haven't programmed in Lua or Cairo before. Perhaps I can persuade you...?
The images in the following two screenshots use only Conky. They were written in Lua, using Cairo bindings:

If I've tickled your fancy, here are a few tips to get you started!
Before you start
First and foremost, grab yourself a copy of the latest Conky release. Â If you are running Ubuntu 9.04 or higher, you can get the .deb here. Â If you are running Ubuntu 9.10 Karmic Koala, version 1.7.2 is in the Karmic repos.
Read through the Cairo tutorial, and familiarise yourself with the Lua documentation. Â Not to say that you should do every exercise word-for-word or read every entry in the Lua reference manual, but it'll give you an idea of the kinds of things you can do, and where to find help if you need it.
Starting out
The easiest way to start is to modify someone else's work, just to get used to the syntax. Just find a script you like and start tweaking. Maybe change colours or shapes, placement of objects, or combine elements from different scripts. Try the following:
- Clock background by Norsetto
- Conky Pies by Brenden Matthews
- Air Clock or Rings, both by me
If you're ready to start making your own ideas come to life, have a go recreating the Cairo snippets on the Cairo website. Then start breaking out your own designs!
Working with Conky
There are a couple of bits you'll definitely need to get your Lua script to work with Conky. First, to define your Cairo surface:
if conky_window==nil then return end
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, onky_window.width, conky_window.height)
cr=cairo_create(cs)
Next, the best bit: you can use the function conky_parse() to evaluate any Conky expression. For instance, you can use:
str=conky_parse('${cpu cpu0}')
to grab the total CPU percent usage of your system. It is saved as a string, so in order to get it as a numerical value, you will need to use:
value=tonumber(str)
conky_parse() and tonumber() together are a powerful combination, because it means that anything you can get in Conky, you can get in your Lua script.
And finally
Don't forget, if you come up with a new weird and wonderful way to use Conky, post it here!
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:
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.
5 Great Sources of Conky Inspiration
So, I think we're all on the same page by now: Conky is a fantastic system monitor, but it can also be a nice little bit of eye-candy for your desktop. Once you've got a handle on the basics, you'll probably be looking for inspiration for your next great Conky config. Here are my top 5 favourite places to look, when I'm after ideas for a new Conky setup...
Browsing the Conky documentation may not seem particularly inspiring, but you'd be surprised! I've found some of my favourite variables just by reading through the variable list...Variables I would probably not have learned about any other way. For instance, it was here that I discovered the $scroll variable, which scrolls text inside a set number of characters. It was also here that I stumbled upon the $if_updatenr variable, which counts the number of updates and can display a different set of outputs for each one.
4. The Ubuntu Forums Conky Screenshot Thread
The biggest active thread I've found devoted to Conky, this baby boasts over 900 pages (at last count)...That's over nine THOUSAND posts of screenshots, hints, tips and troubleshooting. It's also frequented by some of the most prolific and best Conkyists out there, so you're dealing with the best of the best.
3. Conky Wiki
The Conky Wiki is where new releases are described in the most detail, with feature tours, screenshots and code snippets. It's the best place to browse the latest features and get ideas on how to implement them.
2. The Lifehacker Desktop Show and Tell Pool on Flickr
It's not all about Conky in this Flickr pool; it's a real mix of Mac OS, Linux distros and Windows. There are some absolutely awesome shots on here, from Conky to Rainmeter to Geektool to Samurize and beyond...If you want some real artistic inspiration, this is the place to look.
Hands down, the best place to look for Conky inspiration is Conky Hardcore! Captured from all over the 'net, Conky Hardcore! compiles the best and brightest ideas for Conky...and tells you how to achieve them on your own system. Whether you're a novice or an expert, Conky Hardcore! should definitely be in your bookmark list.
And finally...
So those are my top 5 resources for Conky inspiration...What are yours?
Feature Feature: own_window_type panel
Conky 1.7.2 includes support for the panel window-type, which means that you can make your Conky behave like other panels. Here's what it looks like to replace a top panel with a Conky panel, so that system information is always on display, even over a maximised window:
To get Conky to behave like a panel, use the following window configuration before the TEXT in your .conkyrc:
own_window yes
own_window_transparent yes
own_window_type panel
own_window_hints undecorate,sticky,skip_taskbar,skip_pager # NB: normally, below is used here, but we don't want that for our panel
Additionally, if you want your panel to stretch all the way across like in the screenie, and flush against the side of the screen, you'll need:
border_inner_margin 0
border_outer_margin 0
minimum_size 1024 0 # replace 1024 with the horizontal resolution of your monitor, if applicable
A final word of warning: if you want your panel to be all on one line, like the screenie above, be sure to code your Conky all in one line, even if you use $goto and $voffset to control text placement. If your code is on three lines, for instance, the size of the Conky window will be big enough for three lines, even if what they output doesn't stretch down that far.
To get your panel to look just like the one in the screenie, there are a couple of finishing touches:
- Use a program like GIMP to create a small (e.g. 50x50 px) semi-transparent black square, and stretch it with the $image variable's -s (size) flag to the size of the panel you want.
- Normally, if you're using Compiz, you want to disable shadows around your Conky window, but for this one, the shadow is quite nice and makes our panel look even more panel-ish!
The .conkyrc for the screenies above is:
background no
update_interval 1
total_run_times 0
cpu_avg_samples 2
net_avg_samples 2
own_window yes
own_window_type panel
own_window_transparent yes
own_window_class Conky-Panel
own_window_hints undecorate,sticky,skip_taskbar,skip_pager
border_inner_margin 0
border_outer_margin 0
double_buffer yes
no_buffers yes
text_buffer_size 2048
imlib_cache_size 0
override_utf8_locale yes
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
use_spacer none
minimum_size 1024 0
alignment top_middle
gap_x 0
gap_y 0
uppercase no
top_name_width 7
use_xft yes
xftfont Sawasdee Bold:size=8
xftalpha 0.8
default_color ffffffTEXT
${goto 5}${voffset 3}CPU ${cpu}%${goto 60}${voffset -1}${font saxMono:size=8}[${top name 1} (${top cpu 1})] [${top name 2} (${top cpu 2})] [${top name 3} (${top cpu 3})]${font}${goto 425}${voffset -1}MEM ${memperc}%${goto 485}${voffset -1}${font saxMono:size=8}[${top_mem name 1} (${top_mem mem 1})] [${top_mem name 2} (${top_mem mem 2})] [${top_mem name 3} (${top_mem mem 3})]${font}${voffset -2}${font Sawasdee Bold:size=10}${alignr 5}${time %a, %d %b %Y %H.%M}${image ~/Pictures/bk_semi_trans_sq.png -s 1024x18 -p 0,0}${if_match ${battery_percent BAT1} <= 14}${image ~/Pictures/Batteries/battery_1.png -s 16x16 -p 845,1}${else}${if_match ${battery_percent BAT1} <= 27}${image ~/Pictures/Batteries/battery_2.png -s 16x16 -p 845,1}${else}${if_match ${battery_percent BAT1} <= 41}${image ~/Pictures/Batteries/battery_3.png -s 16x16 -p 845,1}${else}${if_match ${battery_percent BAT1} <= 54}${image ~/Pictures/Batteries/battery_4.png -s 16x16 -p 845,1}${else}${if_match ${battery_percent BAT1} <= 68}${image ~/Pictures/Batteries/battery_5.png -s 16x16 -p 845,1}${else}${if_match ${battery_percent BAT1} <= 82}${image ~/Pictures/Batteries/battery_6.png -s 16x16 -p 845,1}${else}${if_match ${battery_percent BAT1} < 95}${image ~/Pictures/Batteries/battery_7.png -s 16x16 -p 845,1}${else}${image ~/Pictures/Batteries/battery_full.png -s 16x16 -p 845,1}${endif}${endif}${endif}${endif}${endif}${endif}${endif}
Special thanks go to *MrStylo for his superb battery icons, and to =mrcool256 for his devastatingly beautiful wallpaper image.
Feature Feature: Built-in Lua Bindings for Cairo
As you may have read in the Conky 1.7.2 feature tour, one of the most exciting new features is the ability to draw directly to Conky's window, using Cairo and/or imlib2. As a demonstration, our own Brenden wrote a little Lua script to use Cairo to draw top information as a pie chart. I modified the script slightly to make it fit with my current desktop...et voila!
To reproduce the look above, I've packaged my .conkyrc, Brenden's original cairo-pie.lua and the cairo-pie.lua I modified, over on my gnome-look.org profile.
There are other examples of Lua scripts for Conky over at norsetto.890m.com and further samples of Cairo scripts at cairographics.org.
Enjoy!
Conky 1.7.2 Released!
As of Monday, Conky 1.7.2 has been officially released!
You can get the files for this release in the usual spot, and there's a feature tour over on the Wiki.
Just a small taster of the new features:
- Built in Lua bindings for Cairo and Imlib2, which allows you to draw directly to Conky's window using Cairo and/or Imlib2.
- Added own_window_type panel.
- $weather: download, parse and display METAR data.
- $desktop, $desktop_number and $desktop_name: current desktop number and name, total number of available desktops.
Have a go and let us know what you think!
Welcome to the new blog!
Welcome to the brand new Official Conky Blog. Stay tuned for the latest development updates, features, and sneak peeks!
For the time being, please use the links on this page to find all the Conky info you desire.





