Mar 28 2008

Interesting aspects of Xmonad

Published by Dougal at 6:48 pm under Computing

Xmonad isn’t really a window manager in the proper sense of the word, in the same way that libogg (the reference Ogg media library) isn’t really a music player. It’s actually an elaborately constructed set of tools for the construction of window managers.

If you want to write a window manager which arranges windows in a clock-shaped pattern on screen, you would do it like this:

module Main where
 
import XMonad
import XMonad.Layout.Circle
 
main = xmonad defaultConfig { layoutHook = Circle }

In short, you import the main window-manipulation tools, then an optional layout, and tie them together in your own program. Xmonad works as a vast library — and what seems like a configuration file at first is in fact the main program. (Configuring the WM is getting people to write Haskell without their knowledge.)

Just as interesting is the problem this raises for on-the-fly configuration. If the program you’re running doesn’t read configuration from a text file to operate, how do you reload when the “configuration” changes?

The problem is made slightly easier by the X windowing system, which doesn’t require a window manager to be operating at all times — only when something changes. So if the window manager “drops the reins” this is no real problem, as long as the horses are not charging towards a ravine. When something else grabs the reins (the same window manager or a different one) the applications are none the wiser.

To restart Xmonad the system recompiles the configuration-file-cum-program and then passes the complete state of the world to this new version. It’s quite weird because when you first run xmonad you just invoke xmonad. But then if you restart and look at all the running processes it seems Xmonad has about three lines of strange configuration. It’s a neat trick. ;-)

One Response to “Interesting aspects of Xmonad”

  1. Sebastián Benítezon 24 Oct 2008 at 11:56 am

    It IS a window manager.

Trackback URI | Comments RSS

Leave a Reply