XMonad Configuration Notes

I made a disastrous attempt at upgrading my Ubuntu distribution today. It failed partway through, leaving things in a horrible broken state. I use XMonad as my windows manager, mostly because I hate having to move things around with a mouse. But today it especially paid off, because the half-upgraded operating system was so broken that I couldn't even log in to Unity: it just bounced me back to the log-in screen. XMonad still generally worked, so I was able to fiddle with things, while doing a lot of googling, and eventually I got everything cleaned up.

But during all this, some of my configurations got messed up, so they needed to be fixed. And I couldn't quite remember how the XMonad configuration worked, so I thought perhaps I should Write It Down, for next time.

~/.xmonad/xmonad.hs

This is the main configuration file for XMonad. It spawns XMobar (more on this later). It's also where you'd put any keybindings. For example, by default, the volume and mute keys on my laptop don't work under XMonad: they have to be specifically bound in xmonad.hs as follows

...
`additionalKeys`
[ ((0, 0x1008FF11), spawn "amixer set Master 2-")
, ((0, 0x1008FF13), spawn "amixer set Master 2+")
, ((0, 0x1008FF12), spawn "amixer -D pulse set Master toggle")
]

XMobar

I also run XMobar, to add a status bar to XMonad (which would otherwise just be an empty screen). As mentioned above, XMobar is started by xmonad.hs, but it is configured in ~/.xmobarrc:

Config { font = "-*-Fixed-Bold-R-Normal-*-13-*-*-*-*-*-*-*"
    , borderColor = "black"
    , border = TopB
    , bgColor = "black"
    , fgColor = "grey"
    , position = TopW L 100
    , lowerOnStart = True
    , commands = [ Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
                 , Run Memory ["-t","Mem: <usedratio>%"] 10
                 , Run Swap [] 10
                 , Run BatteryP ["BAT0"] ["-t", "<acstatus>"
                                         , "-L", "10", "-H", "80"
                                         , "-l", "red", "-h", "green"
                                         , "--", "-O", "Charging", "-o", "Battery: <left>%"
                                         ] 10
                 , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10
                 , Run StdinReader
                 ]
    , sepChar = "%"
    , alignSep = "}{"
    , template = "%StdinReader% | %cpu% | %memory% * %swap% | %battery%}{<fc=#ee9a00>%date%</fc> "
    }

The commands includes anything you want to monitor. The documentation lists all the possible options, under "System Monitor Plugins". Note that each of their descriptions starts with "Aliases to [something]": this is how you refer to that plugin in the template, where you set how you want everything to be laid-out. If you run a command but don't add it to the template, you won't see anything on your status bar, so remember to make any changes in both places.

Start-up Script

I also have a file called start-xmonad.sh in my home directory, which starts an icon tray (stalonetray) and sets the background image (using feh), along with other miscellaneous start-up stuff. It ends with exec xmonad. In order for this start-up script to be used when you log in, you need to edit /usr/share/xsessions/xmonad.desktop and replace whatever is in the Exec= line with the full path of the script you want to run. (Hence the exec xmonad at the end of my script: since you're replacing the default command, it won't start at all if you don't call it in your script.)

My upgrade apparently replaced all the xsessions stuff, so my script was no longer being used. And I didn't check this one right away, since everything is otherwise configured in my home directory, and my nice start-up script was there and worked fine when I called it. It just mysteriously wasn't running automatically...

social