XMonad on Ubuntu

The biggest reason that I wanted to switch to Linux was tiling window managers. OS X is particularly bad at window management. I am constantly dragging this window here, changing the size from a single corner, rearranging my windows, and cursing. All of these actions are tedious, repetitive, slow, and theoretically scriptable. By default tiling window managers never overlap windows, and they provide good keyboard management for window arrangement. Alas they are only really available on X11.

There are many tiling window managers. Off the top of my head there is ratpoison, sawfish, awesome, xwem – written in elisp, stumpwm – written in Common Lisp, and xmonad – written in haskell. I really want to use stumpwm to get a chance to play with common lisp a bit more, but xmonad seems to be a lot more popular. So for now I am using xmonad.

installing xmonad was a simple “sudo apt-get install xmonad”, making it available as a window manager from the gnome-login was more complicated. X11 has a concept of display managers, from what I can tell display managers control your intial login to an x11 system. The standard x11 display manager is xdm, this runs your ~/.xinitrc and ~/.xsession . Most of the information about installing and customizing xmonad recommends editting these files. However under Ubuntu 9.10 gdm (Gnome Display Manager) doesn’t run your ~/.xinitrc . This is very frustrating. gdm does however have a concept of switchable sessions, when you see the login screen for ubuntu, after selecting the user, at the bottom of the screen there will be three drop downs (DRAWING A BLANK), (DRAWING A BLANK) and Session. By default under Session there is Gnome, Gnome-failsafe, and xterm. I ran some apt-get install command (DRAWING A BLANK) that added an option for xmonad to this list, and sure enough upon selecting it, xmonad started on login.

Starting xmonad in this way lets you play with it, but I of course wanted to customize my xmonad preferences. Piecing together from the xmonad faq and some blog posts I came up with this setup, it feels hackish, but it’s a start.

This setup starts nm-applet – the network monitor control thing, this make my laptop automatically connect to my wifi. It also starts emacs, firefox, and rxvt. Then it runs some xmodmap commands to map the key to the right of the right ctrl-key to mod5, my xmonad configuration uses mod5 as it’s hot-key. I will explain my experiences with x11 key mapping in my next post.

There is a directory /usr/share/xsessions/ which contains files that describe the session dropdown box for gdm. In this directory I made a file for xmonad2.desktop


[Desktop Entry]
Comment=Leightweight tiling window manager

The exec line is the important one, it tells gdm to run xmonad.start. xmonad.start is what I am using instead of a ~/.xinitrc , this is the part that feels very hacky



xrdb -merge .Xresources

#trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --width 15 --height 12 --transparent true --tint 0x000000 &



#if [ -x /usr/bin/gnome-power-manager ] ; then
#   sleep 1
#   gnome-power-manager

if [ -x /usr/bin/nm-applet ] ; then
   nm-applet --sm-disable &

#kmix --keepvisibility
emacs &
xterm &
firefox &

#most basic xmodmap stuff
xmodmap -e 'remove Lock = Caps_Lock'
xmodmap -e 'keysym Caps_Lock = Control_L'
xmodmap -e 'add Control = Control_L'
xmodmap -e 'keycode 166 = Hyper_R'
xmodmap -e 'add mod5 = Hyper_R'

#feh --bg-scale /mnt/archivio/foto/2008-2009-dublino/2009-04-10-stefano/hapenny-desktop.jpg &
#exec ~/.xmonadrc
exec xmonad

The last file that I have editted is my xmonad.hs file. This is a haskell file that sets preferences for xmonad. For now all it really does is tell xmonad to use mod5 for it’s hyper-key


import XMonad

main = xmonad defaultConfig
         { modMask = mod5Mask
         , terminal = "urxvt"

And with that I have a minimally usable xmonad setup. Xmonad’s default hot-key is mod1 which is mapped to alt/meta , an unusable meta key makes emacs useless, thus the change. Many people use the windows key, but I need that for super in emacs, I plan to use the document key for hyper in emacs, thus mod5 for xmonad.

All in all I am enjoying xmonad. I’m not completely familiar with it yet, but it seems incredibly powerful and fast.

My biggest gripe with the X11 graphical environment is the lack of sane keyboard shortcuts. OS X got this very right. CTRL-Q generally quits an app, Apple-Q always quit apps. The biggest thing I miss about OS X though is the input modifiers for text areas. In OS X, the default bindings for almost every text input box are very similar to emacs bindings. Try it. C-w, C-a, C-e, C-p, C-n, C-k all work as expected, if I had put in the time I could have made the meta bindings work too. I know of no equivalent for linux and I miss it. The upside though is, I only really use emacs and firefox, a media player, sometimes a terminal, a chat program, and an irc client. That is a small number of programs to customize, and if I get my act together, I could do chat and irc in emacs too.

7 Responses to “XMonad on Ubuntu”

  1. Anonymous says:

    If you want to trivially use XMonad with your gnome desktop in ubuntu you can just edit .gnomerc :

    export WINDOW_MANAGER=${HOME}/bin/xmonad

  2. oberhamsi says:

    the comment above has bad advice. this will have strange results regarding gnome-session-settings, etc. do it the – not much harder – right way for maximum xmonad pleasure

  3. Joey says:

    gdm does not run ~/.xinitrc, but it will run ~/.xsession. I simply symlink the two files to not have to worry about how X was started.

    (If you start xmonad this way, you will want to start gnome-settings-daemon and gnome-panel manually from your ~/.xsession.)

  4. Martin says:

    Thanks to you I finally managed to get the Xmonad setup that I have on Debian Squeeze on Ubuntu 10.04 too!
    Please note: If you use a custom xmonad.start that lives in your home folder you have to specify the full path in the /usr/share/xsession/xmonad2.desktop. (Obvious, right — but I forgot it ;)
    Also: If you want gnome-panel and gnome-settings-daemon, put them BEFORE the xmonad line in your xmonad.start. BTW: it seems that on Ubuntu 10.04 neither .xinitrc nor .xsession are read by gdm.
    – Cheers, Martin

  5. Gerald Sears says:

    I have xmonad installed from repos and it came up in my gdm automatically, no changes needed, just needed to select it in the drop down menu.

    Still working on customizing it, though, getting a status bar and background are the two major things for me. Then I’ll try to get some nice effects and a little subtle eye-candy going and work on fitting the keystrokes to my tastes. Also need to figure out how to work with my second head(monitor), I don’t think it will be that hard, just haven’t had time to play around with it enough to figure it.

  6. In ubuntu 10.04 $HOME/.xession is only run if the argument passed to /etc/gdm/Xsession is “xcustom” (it is “xmonad” when you’re using xmonad).

  7. Aaron says:

    Great post.

    I have one suggestion to the startup scheme. Instead of putting all your startup configuration in /usr/local/bin/xmonad.start, change it to just start the same named file in your home directory, e.g.

    $ cat /usr/local/bin/xmonad.start

    exec ~/.xmonad/xmonad.start

    Then put everything you had in that file into the one in your home dir.

    This way all accounts on the same machine can have their own xmonad setups.