June 15, 2013

Setting up xmobar on xmonad

Everybody who has encountered me while I’m using a computer has probably been shown my wonderful window manager, xmonad. I had been using it without xmobar, which is a neat info-bar, for a fairly significant reason: Whenever xmobar was run, it would hide behind other windows. Additionally, after I fixed that, I was annoyed that there was no easy-to-find configuration for the weather plugin. This blog post will talk about how these things were fixed.

Hiding Behind Other Windows

Ideally, my workspace would look something like this.
xmonad workspace screenshot. hello world c program on the left and command line with the previously mentioned program being compiled and ran on the right

(two notes about this picture: first, I might have to post another blog post about taking screenshots with xmonad. second, hopefully my ideal workspace will have me doing cooler programs than “Hello, World!”)

Unfortunately, before I got it working, when I ran xmobar it would come up, but the other windows would be drawn over xmobar, and I would only be able to see it when I did not have any windows open.

Solution: I came across this forum post, from which I was able to gather a few things:

1. I needed to change some of the settings in xmonad to deal with the fact that the windows were to be drawn such that xmobar would be seen;

2. the program launcher for dmenu might have to be changed.

Now, I had been using the sample xmonad config file which was found on their website. These settings are to be saved in ~/.xmonad/xmonad.hs, and compiled and run with MOD+P. After looking at some code posted in that forum, I replaced the line in the sample config (which I can imagine just starts xmonad),

main = xmonad defaults

with the following:

main = do
    xmonad defaults
        { manageHook = manageDocks <+> manageHook defaultConfig
        , layoutHook = avoidStruts  $  layoutHook defaultConfig
        }

which, when saved and compiled, worked! Hurray!

The Weather Plugin and its Cryptic Settings

In the sample config which I linked to earlier, it provides some default usage of a weather plugin for xmobar. I’ll post it here; this would be saved in the file ~/.xmobarrc, and if changed, you save it and restart xmobar:

Config { font = “-misc-fixed-----10-------“
       , bgColor = “black”
       , fgColor = “grey”
       , position = Top
       , lowerOnStart = True
       , commands = [ Run Weather “EGPF” [“-t”,”<station>: <tempC>C”,”-L”,”18”,”-H”,”25”,”—normal”,”green”,”—high”,”red”,”—low”,”lightblue”] 36000
                    , Run Network “eth0” [“-L”,”0”,”-H”,”32”,”—normal”,”green”,”—high”,”red”] 10
                    , Run Network “eth1” [“-L”,”0”,”-H”,”32”,”—normal”,”green”,”—high”,”red”] 10
                    , Run Cpu [“-L”,”3”,”-H”,”50”,”—normal”,”green”,”—high”,”red”] 10
                    , Run Memory [“-t”,”Mem: <usedratio>%”] 10
                    , Run Swap [] 10
                    , Run Com “uname” [“-s”,”-r”] “” 36000
                    , Run Date “%a %b %_d %Y %H:%M:%S” “date” 10
                    ]
       , sepChar = “%”
       , alignSep = “}{“
       , template = “%cpu% | %memory%  %swap% | %eth0% - %eth1% }{ <fc=#ee9a00>%date%</fc>| %EGPF% | %uname%”
       }

(here I’ve bolded the significant lines)

Turns out the “EGPF”, which you’ll see is in both of the bolded lines, is some kind of weather code, which the script ends up using to get the weather data. I put my google skills to use and figured out that these are a kind of weather code called ICAO. Furthermore, I was able to find a great list of cities and their weather codes. I was then able to find “Waterloo” by searching the file, and when I replaced “EGPF” with “KALO”, and saved the file and restarted xmobar, it worked!

Conclusion

So, my xmonad window manager got a little sweeter last night when I figured this stuff out. I know this isn’t a be all end all guide for how to make xmonad and xmobar work together, but hopefully if you’ve had either of these problems you can extrapolate and figure it out. There is still a lot more customization to do; I’ll post about them when appropriate. I might also make a short post about screenshots in xmonad.

/src/reigh