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
/usr/share/xsessions/xmonad2.desktop
[Desktop Entry] Encoding=UTF-8 Name=XMonad2 Comment=Leightweight tiling window manager Exec=xmonad.start Icon=xmonad.png Type=XSession
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
/usr/local/bin/xmonad.start
#!/bin/bash xrdb -merge .Xresources #trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --width 15 --height 12 --transparent true --tint 0x000000 & #gnome-screensaver #gnome-settings-daemon #if [ -x /usr/bin/gnome-power-manager ] ; then # sleep 1 # gnome-power-manager #fi if [ -x /usr/bin/nm-applet ] ; then nm-applet --sm-disable & fi #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
~/.xmonad/xmonad.hs
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.
If you want to trivially use XMonad with your gnome desktop in ubuntu you can just edit .gnomerc :
export WINDOW_MANAGER=${HOME}/bin/xmonad
Comment by Anonymous — January 17, 2010 @ 5:34 pm
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
Comment by oberhamsi — January 18, 2010 @ 2:50 am
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.)
Comment by Joey — January 18, 2010 @ 5:06 pm