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

28Sep/0912

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:
"Air" Clock Screenshot

"Rings" Screenshot

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:

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!

Filed under: Hints & Tips 12 Comments
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 3 Comments
7Sep/091

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...

5. Conky Documentation

Conky Documentation

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

Ubuntu ForumsThe 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

Conky WikiThe 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

Lifehacker PoolIt'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.

1. Conky Hardcore!

Conky HardcoreHands 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?

Filed under: Hints & Tips 1 Comment
   

Essential Links

Categories

Archive Posts