From HaskellWiki
Jump to navigation Jump to search


This page pretends to be like the XMonad guided tour for new users, but applied to the XMonad Contrib. Mainly because I think it's very difficult for newcomers to discover what extra features XMonad provides. Haddock documentation is pretty useful when you are looking for, but when you're looking around to find or is if some feature is implemented already implemented,the way that the documentation is indexed (by alphabetical order) doesn't help much.

Showing XMonad state in statusbars

XMonad provides a contrib module that outputs the state changes of XMonad (worskpace change, which workspace is active if a workspace has windows or not, etc) into a external statusbar programs like xmobar or dzen.

This module is called XMonad.Hooks.DynamicLog it provides some drop-in loggers and some helper functions to make your own logger.

The more interesting one is DynamicLogWithPP that's a DynamicLog with a Pretty Printer. The DynamicLog contrib module ships with some PP ready to be used, for example one for xmobar, and one for dzen.

You can have your status fed into a xmobar by adding:

import XMonad.Hooks.DynamicLog
import XMonad.Util.Run -- for spawnPipe and hPutStrLn

main = do
       h <- spawnPipe "xmobar"
       xmonad $ defaultConfig {
       logHook = dynamicLogWithPP $ xmobarPP { ppOutput = hPutStrLn h }

To do feed the output to a dzen statusbar you have to add:

import XMonad.Hooks.DynamicLog
import XMonad.Util.Run -- for spawnPipe and hPutStrLn

main = do
       h <- spawnPipe "dzen OPTIONS"
       xmonad $ defaultConfig {
       logHook = dynamicLogWithPP $ dzenPP { ppOutput = hPutStrLn h }

xmobarPP and dzenPP are default PPs ready to be used with each application, but the real power of DynamicLogWithPP lies in that you can make your own PP, you can start by modifing and existing one or doing one by sractch, here's the PP type for reference.

Making space for the statusbar

As XMonad by default uses all screen space to display and arrange it's windows, we need to find a way to show the statusbar.

There is a little module called XMonad.Hooks.ManageDocks, that automatically makes room for panels (and statusbars).

The configuration nedded to run ManageDocks looks like this:

import XMonad
import XMonad.Hooks.ManageDocks
main = xmonad defaultConfig
              { manageHook = manageDocks <+> manageHook defaultConfig
              , layoutHook = avoidStruts  $  layoutHook defaultConfig

XXX: show a shot of the statusbar.

Removing unneded borders around windows

So, you've configured XMonad to draw a nice red border around focused windows, but you find that when you have only one window open the border is still there, and because is the only window in the screen we don't need a big red border to signal us that we've focused that windows.

That's where XMonad.Layout.NoBorders enters.

It provides two utilities, smartBorders and noBorders, the former removes the borders from windows if they are the only window in the workspace, the latter removes all borders from the windows in the Worskpace

smartBorders, and noBorders can be applied to an specific Layout or a group of Layouts, so if you want your Full layuot don't render borders you will have to add something like this to you configuration:

layoutHook = ... ||| noBorders Full ||| ...

To add smartBorders to all the Layouts (good idea) you'll have to add:

layoutHook = smartBorders $ (tiled ||| (Mirror tiled) ||| Full)

Having a floating terminal always at your fingertips

XMonad.Util.Scratchpad provides the ability to set a keybind to launch a preconfigured floating terminal that will hide when you press the keybind again. Preety handy, trust me. Its location and size is even configurable so you can make it more like yakuake if you really want to.

The documentation is very straightforward on how to configure it, you can see it in action here:

XXX: show a show of a cluttered workspace and a scratchpad floating

More options in layout selection


More powerful window management


Getting notifications on events

The programs running on your windows can try to catch your attention setting what's called the "Urgency Hint" basically it means "this window needs your attention".

XMonad has some features to act uppon a window setting its urgency hint, they are located in the XMonad.Hooks.UrgencyHook.

This module allows you to pop-up a custom dzen with a message, use different colours in your DynamicLog for workspaces with urgent windows on them and provides you a keybind to focus the urgent window.

To have dzen flash for a period of time add this to your config:

main = xmonad $ withUrgencyHook dzenUrgencyHook { args = ["-bg", "darkgreen", "-xs", "1"] }
              $ defaultConfig

You can provide the arguments you want to the dzen call, so it's very flexible.

If you don't want it flashing things but want to change your DynamicLog use this:

main = xmonad $ withUrgencyHook NoUrgencyHook
              $ defaultConfig

You'll have to config you ppUrgent in your PP to make the changes you wan't to show.

XXX: show a screenshot of every one in action

Configuring some programs to notify xmonad of urgency


If you set in your .Xresourses or .Xdefaults

URxvt.urgentOnBell: true

The terminal window will get the urgency hint when the running program inside makes a "bell", it's realy useful for Irssi notifications, mutt mail arrivings, etc.


You have to enable the beeping feature of Irssi for it to tell the terminal program to set the urgency hint on the window.

/set bell_beeps ON /set beep_msg_level MSGS NOTICES DCC DCCMSGS HILIGHT

If you use it inside a GNU Screen you should set it to have audible beeps.


Pidgin ships with a "Message Notification" plugin, you must activate it and configure it to set the window manager urgency hint.

Modifiying existing layouts

LayoutModifiers, tabbed, withIM

Launching programs in a better way