09.07.2009 01:03

Vicious widgets for awesome WM

Desktop Screenshot I've been using awesome for over a year now, and version 3 for the last 7 months. I had a lot of widgets in my awesome2 setup and porting them to Lua was very important to me. From a few different approaches I choose Wicked. It's a big module for awesome that provides a few default widget types and allows registering custom functions to create new widgets easily. Wicked is great because it takes care of everything for you; registering widgets with awesome, setting timers, unregistering... It's also the only module (for now) that allows easy access to suspend and resume functions, so you can easily suspend your widgets when running on battery. Speaking of which, another killer feature is widget caching, you can have multiple widgets that use the same function and it gets executed only once. Good example is the volume widget, I have a textbox and a progressbar both showing the volume level.

I've been using Wicked for the past 7 months, and I wrote a lot of custom widget functions for it. My rc.lua was growing huge, close to the 1000 LOC mark. It bothered me for some time and my first take on it was to remove all the widget types I don't use from Wicked, and integrate my own widgets with it. That worked for a while, but then another problem arose. Often when bored or feeling creative I wanted to write a new widget, a good example is the wireless information widget. I would need it only when I'm outside or traveling, in the mean time it would just sit there in memory. When my local Wicked copy started growing past the 1000 LOC mark it was time for another solution.

Widgets need to be modular, you plug-in widgets that you need and ignore the rest. The Obvious project provides exactly that, a modular widget library. However it didn't sit well with me (in its current state), their design is that a widget module should not only crunch data, but set up everything. From output formatting to registering button bindings and timers.

What I had in mind for a widget module is that it should be a small, 10 lines, module with a worker function that crunches some data and spits out numbers/results. How that data will be formatted, should it be red or blue I want to define somewhere else, in the rc.lua most likely. If you need a new widget or maybe you are just motivated or feeling creative... you write a quick function that does the work, that's all you need to focus on. When you need it, you plug it in.

Pondering on it for a while I decided to do it my self, otherwise I would never be satisfied. Since I was already familiar with Wicked, and it has suspend/resume/caching... I split it and modularized the code. The new widget library I called Vicious, it has some of the old Wicked widget types, a few of them rewritten, and a good number of new widgets. Small summary of changes so far:

* Original code modularized
* Widgets ported from Wicked:
  - CPU, MEM, FS, NET, Date, Uptime, MPD
* Widgets written for Vicious:
  - Thermal, Battery, Mbox, OrgMode, Volume, Entropy, Disk I/O,
    System Load, Wireless, Pacman
* MEM widget rewritten, uses pattern matching
  - Swap widget merged with MEM widget type
* MPD widget rewritten, a bit more versatile
* NET widget rewritten, uses pattern matching
* CPU widget rewritten, uses pattern matching
* FS widget rewritten, uses pattern matching
  - Also fixed padding in the process
* Removed deprecated helper functions
I guess at least one user will share my views on widgets, and could be interested in the code. Since my rc.lua is by far the most requested file on this web server there will be a few more people interested in Vicious. For that reason I decided to share it.


Written by anrxc | Permalink | Filed under desktop, code