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 that the statusbar is always shown.

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)

To write

  • More options in layout selection: Perworkspace
  • More powerful window management: ManageHelpers
  • Getting notifications on events: UrgencyHook
  • A handy terminal for doing dirty work: ScratchPad
  • Modifiying existing layouts: LayoutModifiers, tabbed, withIM
  • Launching programs in a better way: ShellPrompt