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.

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

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


#!/bin/bash
#recompile.sh

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


Now you just run recompile.sh and then press 'Alt-q' to restart xmonad on the fly. For examples of users config files see http://haskell.org/haskellwiki/Xmonad/Config_archive. 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 -


PATH=$PATH:/path/to/xmonad
export PATH


dmenu
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 (http://www.suckless.org/download/dmenu-3.4.tar.gz) and then compiling it.

dzen
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 http://dzen.googlecode.com/svn/trunk 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).

xsession
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 &
xmonad


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


#!/bin/bash
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
done


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.

4 comments:

Anonymous said...

What's the advantage of naming your workspaces?

Raja said...

If you are not planning to display the workspace names, you may not need it. But it is possible to display the current workspace in dzen (see the screenshot in http://reachbeyondgrasp.blogspot.com/2007/12/gmail-notify-for-dzen.html) and then it makes sense to have names. It also makes more sense to have names when you set up xmonad to open windows in certain workspaces (eg. firefox in 'web', text editors in 'coding' and so on).

nu.conteaza said...

what happens when you change your workspace... and open a new term, doesn't it overlap with the other window ?

Anonymous said...

The new term will be tiled atomatically. It's the magic of Xmonad.