Run Xmonad on Snow Leopard

2010/12/16

This is a little how-to install and execute xmonad under X11.app on Snow Leopard.

First thing to do (if you haven't yet) is installing the Haskell platform. I use Homebrew as my packet manager of choice:

brew install haskell-platform

Next we are going to install xmonad from Cabal:

cabal update
cabal install xmonad

Now that everything is installed correctly we need to tweak our X11.app settings in order to run nicely with xmonad.

First open your .bash_profile and append the followings as nicely described here:

# Xmonad stuff
export PATH=/Users/gbrindisi/.cabal/bin:$PATH
export USERWM=`which xmonad`

Next we need an .xinitrc in our $HOME, and we can copy from the stock one:

cp /usr/X11/lib/X11/xinit/xinitrc ~/.xinitrc

Some editing is needed because this .xinitrc executes the quartz-wm by default and xmonad will throw you an error if you'll try to start it on top of another windows manager.

So open it and locate this if statement and comment/remove everything:

if [ -d /usr/X11/lib/X11/xinit/xinitrc.d ] ; then
    for f in /usr/X11/lib/X11/xinit/xinitrc.d/*.sh ; do
    [ -x "$f" ] && . "$f"
    done
    unset f
fi

The above statement simply executes every *.sh in the X11's xinitrc.d directory. One of those is the quartz-wm that you don't want to run but if you need the others feel free to execute them anyway – I haven't looked at them in-depth.

I've also removed the following lines:

twm &
xclock -geometry 50x50-1+1 &
xterm -geometry 80x50+494+51 &
xterm -geometry 80x20+494-0 &
exec xterm -geometry 80x66+0+0 -name login

Then you need to append a couple of commands:

source ~/.bash_profile
exec $USERWM

Now everything should be setted up correctly.

The next and final step we need to face is to remap our X11 key bindings because since Command is the default xmonad's meta key it will happily interfere with other OSX applications.

Create a new .Xmodmap and write:

clear Mod1
clear Mod2
keycode 63 = Mode_switch
keycode 66 = Meta_L
add Mod1 = Meta_L
add Mod2 = Mode_switch

And we are set.
(Note: 63 is the left Option key and 66 is the left Command key)

Now run X11.app and enjoy xmonad.

Follow me: @gbrindisi