This website is now static html, I have no time to write anything and Wordpress has more security holes than a Swiss cheese, and so the migthy wget -m replaced the ugly php. For sure there will be problems with this new version, but that is life.

My configuration of xmonad window manager with xmobar and trayer


I’ll write here my configuration of xmonad in order to find it easily in the future. xmonad is a dynamically tiling X11 window manager that is written and configured in Haskell (http://xmonad.org/). I find xmonad really useful on systems with small screens and on laptops to avoid using the touchpad.

Software

  1. xmonad (0.8) – the window manager
  2. xmobar (0.9) – a status bar also in haskell
  3. trayer (1.0) – small app for a systray
  4. feh (1.3.4) -to set the background image
  5. gdm, kmix, network-manager, …

How to install stuff

You’ll find more or less all the software needed on the repositories of the distribution of your choice (if you use ubuntu, like me, this should install the window manager apt-get install xmonad libghc6-xmonad-contrib-dev libghc6-xmonad-dev dwm-tools).

Configuration

Following the config files of the various softwares:

xmonad~/.xmonad/xmonad.hs

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

myManageHook = composeAll
    [ className =? "Gimp"      --> doFloat
    , className =? "Vncviewer" --> doFloat
    ]

main = do
    xmproc <- spawnPipe "xmobar"
    xmonad $ defaultConfig
        { manageHook = manageDocks <+> myManageHook -- make sure to include myManageHook definition from above
                        <+> 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
        } `additionalKeys`
        [ ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
        , ((0, xK_Print), spawn "scrot")
        ]

xmobar~/.xmobarrc

Config { font = "-misc-fixed-*-*-*-*-13-*-*-*-*-*-*-*"
       , bgColor = "black"
       , fgColor = "grey"
       , position = TopW L 85
       , commands = [ Run Network "wlan0" ["-L","0","-H","32","--normal","green","--high","red"] 10
                    , Run Cpu ["-L","15","-H","50","--normal","green","--high","red"] 10
                    , Run Memory ["-t","Mem: %"] 10
                    , Run Swap [] 10
                    , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10
                    , Run StdinReader
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%StdinReader% }{ %cpu% | %memory% * %swap% | %wlan0% | %date%"
       }

gdm/usr/share/xsessions/xmonad.desktop

[Desktop Entry]
Encoding=UTF-8
Name=XMonad
Comment=Leightweight tiling window manager
Exec=xmonad.start
Icon=xmonad.png
Type=XSession

xmonad.start is a custom script.

xmonad.start/usr/local/bin/xmonad.start

#!/bin/bash

xrdb -merge .Xresources

trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --width 15 --height 12 --transparent true --tint 0x000000 &

gnome-screensaver

gnome-settings-daemon

if [ -x /usr/bin/gnome-power-manager ] ; then
   sleep 1
   gnome-power-manager
fi

if [ -x /usr/bin/nm-applet ] ; then
   nm-applet --sm-disable &
fi

kmix --keepvisibility

#feh --bg-scale /mnt/archivio/foto/2008-2009-dublino/2009-04-10-stefano/hapenny-desktop.jpg &

exec xmonad

Notes:

  • using gnome-settings-daemon (i.e. for multimedia keys) the use of feh for setting the background image is unnecessary.

Screenshots

A screenshot of the desktop without applications (only xmonad and trayer), the background image is the Ha’Penny Bridge, Dublin, by Steve:

now with some apps:

16 Responses to “My configuration of xmonad window manager with xmobar and trayer”

  1. Michele Beltrame

    Hey man!

    I think you don’t live (or used to live) far from where I do, in Maniago. ;)

    Anyhow, I’m fairly new to xmonad and what I basically need is a GTK notification area in order to get rid of the xfce4 panel for the SkyPe notification icon – I don’t really need the icon, a string will do. Do you know of a lightweight software I could use with xmonad which provides that?

    Thanksss,
    Michele.

  2. Michele Beltrame

    Ah, reading better I now see you use “trayer” for that!

    I’ll try this config tomorrow.

    Thanks,
    Michele.

  3. Arjuna Del Toso

    @Michele
    You’re right, I (used to) live in Travesio (and in Maniago I attended the liceo) =).
    Yes, the “trayer” is quite nice and just does the job.

    (Your website http://www.cattlegrind.info/ seems down, is this a temporary problem or maybe a typo in the url?)

    mandi mandi,
    arjuna

  4. Michele Beltrame

    Er ops, it’s really:

    http://www.cattlegrid.info/

    Mistyped it. ;) For now I posted about an xmonad+xfce integration which I like enough… but I’m really looking into going more minimal, and minimal, and….

    Cheers,
    Michele.

  5. matt

    It didn’t work for me sadly on arch linux 64. All I got was a weird green background and none of the xmonad key bindings worked. I had to launch a shell to kill xmonad.

  6. Arjuna Del Toso

    @matt
    strange, maybe try to read the docs on how to use xmonad http://xmonad.org/tour.html (remember that in my config the Mod key is the Windows button on keyboard)
    can be also a copy&paste problem, to be sure the config file is correct try ghci ~/.xmonad/xmonad.hs
    you should see something like

    $ ghci ~/.xmonad/xmonad.hs
        GHCi, version 6.8.2: http://www.haskell.org/ghc/  :?  for help
        Loading package base ... linking ... done.
        Ok, modules loaded: Main.
    
        Prelude Main> :t main
        main :: IO ()
    
  7. matt

    Yeah I think there was an issue with xmonad.hs not compiling. I had to strip everything out and am now trying stuff little by little. Maybe it has something to do with the fact that I’m using ghc 6.10?

    Now I’m wrestling with how to use trayer. I think I have it docked on the bottom, but I have no idea what it’s doing for me.

  8. Tb

    Hello man,
    Many thanks for the config files.
    They were very helpfull.
    However, I have a problem.
    Despite I use the config files almost identical to yours, there is nowhere an indication of the workspaces.
    ([1] [2] …) have dissapeared compleatly, and I have no idea why.
    As I see from your screenshot I should see something like that.
    Any idea?

  9. Tb

    Hallo again,
    After a little while I noticed that I was missing StdinReader.
    Very important.

    Molto grazie

  10. Shannon -jj Behrens

    Thanks for the post. It helped me get up and running quickly which is exactly what I was looking for. You wrote it on my birthday, so I’m going to call it a birthday present ;)

    After reading your instructions, I decided to integrate xmonad more fully into my normal Ubuntu environment. Hence, I wrote my own instructions here: http://jjinux.blogspot.com/2009/11/linux-my-xmonad-setup.html. I referenced your instructions in my blog post.

    Thanks again!

  11. Maj

    Trayer doesn’t seem to exist in Karmic repositories.

    You can get it here:

    http://archive.ubuntu.com/ubuntu/pool/universe/t/trayer/trayer_1.0-2_amd64.deb

    For Ubuntu users, when you click on the link it should open in gdebi.

  12. Maj

    (For 64 bit, there are packages for other arches in http://archive.ubuntu.com/ubuntu/pool/universe/t/trayer/ )

  13. Rada

    Thanks for writing this up. It’s great to have a How To on creating a setup in between “full on gnome with xmonad instead of metacity” and “totally minimal just xmonad”. If people get xsession-errors about xmonad not providing window manager, or it otherwise doesn’t automatically start on login… likely the applications/xmonad.desktop file is missing. Can use:

    $ cat /usr/share/applications/xmonad.desktop
    [Desktop Entry]
    Type=Application
    Encoding=UTF-8
    Name=Xmonad
    Exec=xmonad
    NoDisplay=true
    X-GNOME-WMName=Xmonad
    X-GNOME-Autostart-Phase=WindowManager
    X-GNOME-Provides=windowmanager
    X-GNOME-Autostart-Notify=false

  14. Xmonad on Karmic Koala : expatiari expatria

    [...] configuration above is a mix and match from these four pages and my own [...]

  15. Oli M

    Thanks for posting this! I’m running Ubuntu 10.4 LL & am just getting started with xmonad. This was a big help.

    Just to let you know, I had trouble with your .xmobarrc and your xmonad.start, but I figured it out with some tinkering.

    For .xmobarrc, I just modified the .xmobarrc-example in my docs. Perhaps I’m using a different version of xmobar? (0.9.2)
    For xmonad.start I had to append an & to gnome-power-manager and the nm-applet lines.

    Not completely sure why I had to do those things, but everything works find now.

  16. jeff stern

    hi, arjuna,

    thank you for this excellent post. it was so helpful. i never
    would have gotten off the ground without someone like you giving me
    the kick-start.

    i am following you along, 2.5 years later, on an ubuntu 64bit v11.10 machine.

    some notes:

    - in my .xmobarrc, i would get an error and it wouldn’t start until i added the lowerOnStart config like so:

    , position = TopW L 85
    , lowerOnStart = False

    - i changed my /usr/local/bin/xmonad.start setup a little bit. i
    removed a lot of stuff and it took me all day to figure out what was
    optional (basically, everything) and what i really needed. like
    Oli M, i had to put an ampersand (&) after nm-applet (and almost all
    processes being started up). and since i could not find a
    “gnome-power-manager” for ubuntu 11.10, i just left that out. here
    it is:

    ========================================================================
    #!/bin/bash

    # /usr/local/bin/xmonad.start

    # all commands are optional except the last (for executing xmonad).

    # notice most commands are put into background (&) so as not to lock up
    # xmonad startup

    # merge any X-windowc settings. (i commented out because I do not have
    # this file currently)
    # xrdb -merge .Xresources

    # non-gnome system tray (lighter)
    trayer –edge top –align right –SetDockType true –SetPartialStrut true –expand true –width 15 –height 12 –transparent true –tint 0×000000 &

    # syndaemon – a program that monitors keyboard activity and disables the
    # touchpad when the keyboard is being used.
    # ubuntu package: syndaemon
    syndaemon -d -t

    # i just changed the background to a solid grey
    xsetroot -solid “#636161″ # Darker gray.

    # network manager applet – because i am mobile and like the wifi
    # and network status controls
    nm-applet –sm-disable &

    # my dropbox daemon
    ~/.dropbox-dist/dropbox start -i &

    # printer applet (usually invisible) when i print
    sh -c “sleep 31 && system-config-printer-applet > /dev/null 2> /dev/null” &

    # notify when ubuntu package updates are available
    update-notifier –startup-delay=60 &

    # start xmonad
    # REQUIRED
    exec xmonad
    ========================================================================

    - i didn’t want the windows key to be my “Mod” key. so for others coming to this page, i did this by
    removing the following line in ~/.xmonad/xmonad.hs:
    , modMask = mod4Mask — Rebind Mod to the Windows key
    and, after testing it with ghci as you mentioned earlier,
    $ ghci ~/.xmonad/xmonad.hs
    i recompiled:
    $ xmonad –recompile
    and started a new session (exited with mod-shift-q and signed back in)

    - of course, to get trayer and xmobar for ubuntu, one only has to add
    them to the list of packages. i did not add feh, and also dwm -tools
    (for the dmenu when one hits mod-P in xmonad environment) is no
    longer dwm-tools, but suckless-tools. so the command would be:

    $ sudo apt-get install xmonad libghc6-xmonad-contrib-dev libghc6-xmonad-dev suckless-tools trayer xmonad

    QUESTIONS:

    - what do you do for gnome-power-manager in ubuntu 11.10?

    - in a gnome-based window manager, it is easy to reconfigure the power
    button to be a “sleep” or “hibernate” button, instead. how can this
    be done in xmonad without bringing in all the heavy baggage of
    gnome?

    thanks again, arjuna.
    jeff



Leave a Reply