[xmonad] Xmobar Plugin Development

Fred Blasdel blasdelf at gmail.com
Mon Jul 14 13:08:45 EDT 2008


I wrote a xmobar plugin to display the time as inexact text:
 http://www.wabdo.com/fred/FuzzyClock.hs

It uses Data.Time, not the more widespread System.Time. It's not
parameter-ised because it would be a huge pain to make a xmobar plugin
take a function as an argument (seems like I'd have to take it as a
string and eval it), and you're going to have to modify/recompile
xmobar's source to add it anyway.

I was surprised at just how un-idiomatic I found xmobar's configuration to be:
  * Uses format strings instead of functions
  * Uses property lists for the arguments to monitors instead of
[(a,b)] or a data constructor
  * Commands aren't simple functions
  * 'Plugins' cannot be seperated from xmobar's source (and resulting binary)

Currently the only way to extend xmobar's functionality without
modifying/recompiling it is to use external processes. I think that
having to hack/rebuild xmobar is a huge barrier to experimentation --
I could only find one other person who had published out-of-tree
plugins (http://www.haskell.org/pipermail/xmonad/2008-April/005465.html).

I think it should be possible to implement things like FuzzyClock in
my configuration file without modifying xmobar at all! I should be
able to use functions in my configuration file to do anything a Plugin
can do now -- the output text should be composed of functions
producing 'IO String'. Basically I think xmobar should be more like
xmonad :)

Here's what a simple xmobar configuration file would look like in my
ideal world (though getting rid of the separate commands list may be
unrealistic because of threading+STM setup):

import Xmobar
import Xmobar.Monitors as Mon
main = do xmobar $ Config {
   font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
 , bgColor = "black"
 , fgColor = "grey"
 , position = Top
 , format = Format {
     , left   = myCpu ++ " | " ++ myMemory where
          myCpu = "Cpu: " ++ (run 10 $ Mon.cpu [(3,"green"),(50,"red")]) ++ "%"
          myMemory = "Mem: " ++ (run 10 Mon.memUsedRatio) ++ "%"
     , middle = color "#aaa" stdinReader
     , right  = color "aquamarine" $ run 10 myHaskellFunction
   }
}

 -- Fred Blasdel


More information about the xmonad mailing list