Posted by Craige McWhirter on
Last edited

Over the years I've found window managers and desktop environments increasingly getting in my way. It was for this reason I ditched GNOME for Enlightenment 0.17 and again why I recently ditched Enlightenment 0.19 for Xmonad.

I'd tried Xmonad back in 2013 because Haskell but walked away after a fairly half-hearted look. I gave it a much more serious look this time and I'm happy to say that it's here to stay.

Xmonad is light, fast and behaves exactly how I expect it to.

Here's how I went about settling into Xmonad on Debian Jessie:

An Overview of My Xmonad Environment

The current environment I've settled on with Xmonad looks like this:

TL;DR

For the impatient, follow these steps below and you should be on your way:

$ sudo apt-get install xmonad libghc-xmonad-contrib-dev libghc-xmonad-dev suckless-tools trayer xscreensaver scrot
$ wget myconfig and install it here
$ wget this xinitrc to here
$ wget -O /tmp/open-sans.zip http://www.fontsquirrel.com/fonts/download/open-sans
$ mkdir -p ~/.fonts/OpenSans
$ unzip -d ~/.fonts/OpenSans /tmp/open-sans.zip
$ fc-cache -fv

Select "Default Session" when logging in via GDM, LightDM etc. Enjoy.

Get the Gear

For those of us that are a little more Zen about learning, let's install the packages:

$ sudo apt-get install xmonad libghc-xmonad-contrib-dev libghc-xmonad-dev suckless-tools trayer xscreensaver scrot
Optional Font Installation:

The configuration I provide for xmobar uses the Open Sans font. You can change this to any font that you desire. However if you wish to use Open Sans, here is how you go about getting and installing it:

  1. Download the font:
$ mkdir ~/.fonts/OpenSans
$ wget -O /tmp/open-sans.zip http://www.fontsquirrel.com/fonts/download/open-sans
  1. Unzip the font:
$ cd ~/.fonts/OpenSans
$ unzip /tmp/open-sans.zip
  1. Rebuild the font cache information files:
$ fc-cache -fv

This will provide you with the all the tools that make up my Xmonad environment.

Configure Your Xsession

The very minimum that you'll need to do is edit / create ~/.xsession to have at least this line:

/usr/bin/xmonad

You can get more creative than this if you like, I recommend reading Getting started with xmonad and How can I use xmonad with a display manager?.

Configure Xmonad

Xmonad, unsurprisingly uses Haskell as it's configuration language. Here is the ~/.xmonad/xmonad.hs I used at the time of writing:

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO

main = do
        -- Spawn the xmobar status bar
        xmproc <- spawnPipe "/usr/bin/xmobar ~/.xmobarrc"
        xmonad $ defaultConfig
                -- Set your preferred mouse focus behaviour
                { focusFollowsMouse = False
                -- Set your default terminal
                , terminal = "terminology"
                -- Configure some default interactions between Xmonad and xmobar
                , manageHook = manageDocks <+> manageHook defaultConfig
                , layoutHook = avoidStruts $ layoutHook defaultConfig
                , logHook = dynamicLogWithPP $ xmobarPP
                        { ppOutput = hPutStrLn xmproc
                        , ppTitle = xmobarColor "green" "" . shorten 50
                        }
                , modMask = mod4Mask -- Rebind Mod to the Windows key
                -- Configure some additional keys
                } `additionalKeys`
                        -- Lock the screen with Windows+Shift+z
                        [ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock")
                        -- Capture the current window with control+PrintScreen
                        , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
                        -- Capture the current desktop with PrintScreen
                        , ((0, xK_Print), spawn "scrot")
                        -- Turn off the display port with Windows+d - Useful for undocking my laptop
                        , ((mod4Mask, xK_d), spawn "/usr/bin/xrandr --output DP1 --off")
                        -- Turn on the display port and set it as the primary display with Windows+Shift+d - tailor to your screen
                        , ((mod4Mask .|. shiftMask, xK_d), spawn "/usr/bin/xrandr --output DP1 --primary ; /usr/bin/xrandr --output LVDS1 --mode 1280x800; /usr/bin/xrandr --output DP1 --mode 2560x1440; /usr/bin/xrandr --output DP1 --left-of LVDS1")
                        -- Volume control keys, if needed. Yours may be different.
                        , ((0 , 0x1008FF11), spawn "amixer set Master 2%-")
                        , ((0 , 0x1008FF13), spawn "amixer set Master 2%+")
                        , ((0 , 0x1008FF12), spawn "amixer set Master toggle")
                ]

Configure xmobar

Xmobar uses ~/.xmobarrc as it's configuration file. I am using the Open Sans font. If you did not download and install that in the earlier steps, you may want to change the font = line to a font that you do have installed.

Here is my .xmobarrc file:

Config { font = "xft:Open Sans:size=10:antialias=true"
        , bgColor = "black"
        , fgColor = "grey"
        , position = TopW L 90
        , lowerOnStart = True
        , commands = [ Run Cpu ["-L","3","-H","70","--normal","green","--high","red", "-t", "CPU <total>"] 10
                , Run CpuFreq ["-t", "<cpu0>GHz <cpu1>GHz"] 10
                , Run Memory ["-t", "MEM <usedratio>%"] 10
                , Run Date "%a %b %_d %H:%M" "date" 10
                , Run Battery ["-t","BAT <left>", "-h", "green", "60", "-l", "red", "10"] 10
                , Run StdinReader
                , Run Weather "YSSY" ["-t"," <tempC>C","-L","10","-H","35","--normal","green","--high","red","--low","lightblue"] 36000
                , Run DynNetwork [] 10
                ]
        , sepChar = "%"
        , alignSep = "}{"
        , template = "%StdinReader% }{ %cpu% %cpufreq% | %memory% | %dynnetwork% | %battery% %YSSY% <fc=#ee9a00>%date%</fc>"
        }

I'd recommend looking up your nearest weather station here and replacing YSSY with that station's code. Unless you live in Sydney, Australia, in which case, you're set.

Configure Trayer

I use trayer as my system tray and I place it to the right of the screen in the gap left by my xmobar configuration:

trayer --edge top --align right --SetDockType true --SetPartialStrut true \
 --expand true --width 10  --transparent true --alpha 0 --tint 0x000000 --height 19 &

I currently run this manually but it could easily be launched automatically elsewhere.

Login & Get Comfortable

There's a useful list of default key bindings and handy cheatsheet which you'll need to familiarise yourself with.

I've found xmonad to be fast and unobtrusive with default behaviour that continually surprises me by doing exactly what I expected.

Very happy convert here.