[xmonad] Xmobar Plugin Development

Spencer Janssen spencerjanssen at gmail.com
Mon Jul 14 16:11:17 EDT 2008

First I'd like to point out the author of xmobar, Andrea Rossato, probably
doesn't follow this list anymore.  If you'd like to see action on these issues,
you should probably forward this message to him.

On Mon, Jul 14, 2008 at 10:08:45AM -0700, Fred Blasdel wrote:
> 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

Yes, both of these are rather ugly -- it seems to have a shell script flavor to
it, rather than a strongly typed combinator approach usually used in Haskell.

>   * Commands aren't simple functions
>   * 'Plugins' cannot be seperated from xmobar's source (and resulting binary)

Andrea has chosen to use Read/Show serialization for xmobar rather than Haskell
source ala xmonad.  The things you mention are the negative aspects of this
choice, but there are positive aspects -- not requiring GHC as a runtime
dependency is a major one.

> 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).

In fact, I've written xmobar plugins but have not distributed them because
there isn't really a convenient way to do it.

> 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):

I think this is possible via some clever Applicative tricks, though I'm still
pondering that.

> 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

Spencer Janssen

More information about the xmonad mailing list