November 11, 2007

Xmonad on Ubuntu - setting it up

My setup (and what seems to be the most common way to set it up) consists of modifying xmonad 'Config.hs' and configuring dzen, dmenu and the '.xsession' file.

Xmonad does not load settings dynamically from a configuration file. Instead, the settings are compiled into the binary. This means that changes in the settings require xmonad to be recompiled and reloaded. This is not as hard as it sounds, however.
Looking at the Config.hs, you will find it fairly simple and easy to understand. The first thing I did was changes the number of workspaces to 4 with names for them.

workspaces :: [WorkspaceId]
workspaces = ["terminal", "web", "work", "coding"]

The next setting you may want to change is the modMask which determines which will be the modifier key (Alt is the default) - I was content with the default.
The other import change to make is to create a gap for the dzen bar at the top - like this...

defaultGaps :: [(Int,Int,Int,Int)]
defaultGaps = [(18,0,0,0)] -- 15 for default dzen font

In the window rules, you might want to choose the applications that should always display in the floating mode (that is, not tiled). You can also choose here to open some applications only on a specific workspace, browsers in the 'web' workspace, editors in the 'coding' workspace and so on.
Next is the section for changing the keybindings though I will stick to the default keybindings for now.

Once the changes are done, you have to compile Xmonad again. If you want to experiment with some settings and will be doing this repeatedly, it is logical to put these lines as a shell script.


runhaskell Setup.lhs build
rm `which xmonad`
runhaskell Setup.lhs install --user

Now you just run and then press 'Alt-q' to restart xmonad on the fly. For examples of users config files see If Alt-q doesnt seem to work (didnt for me at first), it is because xmonad is not in your PATH. Add this to your .bashrc -

export PATH

dmenu provides a simple way to launch applications in xmonad. On pressing 'Alt-p' (the default keybinding), dmenu pops up. It allows you to type the name of the application to launch. As you type, the possible candidates are shown and you need not type the whole name if there is only one option left. I installed dmenu from the repository (sudo aptitude install dmenu), but while it worked perfectly in gutsy, the dmenu in Feisty was not showing the completions. I solved this by downloading the source ( and then compiling it.

dzen is a very versatile program used for notification and display of status messages. The best way to get is to compile from source. Once started, it fits into the 'gap' that we created in the xmonad display. Here is dzen in action -

Though this screenshot shows the latest release, you should consider checking out the development version.

svn checkout dzen

The development version makes it easier to pipe output selectively to the master and slave windows and also has better gadgets (gcpubar instead of cpubar).

And finally modify the xsession file to add programs you want at startup. My .xsession file currently looks like this

unclutter -idle 1 &
/home/raja/xmonad/genstatusmessage | dzen2 -ta l -fg '#ffffff' -bg '#808080' -x 0 -w 430 &
/home/raja/xmonad/cpubar | dzen2 -fg '#ffffff' -bg '#808080' -x 430 -w 300 &
/home/raja/xmonad/genemailmessage | dzen2 -ta l -l 3 -fg '#ffffff' -bg '#808080' -x 730 -w 350 &
gnome-settings-daemon &
gnome-power-manager &
rxvt -bg black -fg white &
firefox &

The first line starts unclutter (available in the Ubuntu repos) which hides the mouse cursor after the set idle time (1 sec). Watch out for problems with loss of keyboard focus that has been occasionally reported with unclutter.
The next three lines start 3 instances of dzen. The first dzen shows the output of my genstatusmessage script shown here

while true ; do
temp=`cat /proc/acpi/thermal_zone/THM0/temperature | awk '{print $2}'`
bt=`acpi -b | awk '{print $5,$6}'`
m=`date +"%H:%M %a %b %d"`
printf "%s | Temp: %s C | Batt: %s \n" "$tm" "$temp" "$bt"
sleep 30

The other script genemailmessage checks my gmail and gives the count of new messages as well as the headers of the new messages - but that is for another post!
Starting the gnome-power-manager allows suspend on closing the laptop lid.