DEV Community

mafflerbach
mafflerbach

Posted on

Jumping from I3 to xmonad - Day 2 -> Setup xmobar

Setting up xmonad is already a story, but xmobar is a completely different.

I had in I3 a bar iBlocks bar with the following content.

i3-iblocks-status-bar.png

This is of cause something what I want back, at lease in a similar fashion.
Xmobar don't show your workspaces per default. The reason is, that xmobar and xmonad are two different programs, but xmobar get the information from xmonad as hook. Some how I had difficulties without the workspace display in my bar.
So I want my workspaces back and the overview of my time tracking.

As time tracker I'm using watson, it's an easy to use CLI time tracker.

To get the right output for xmobar I created a script:


#!/bin/bash

while :; do
    case "$1" in
        -s) 
            echo $(watson status) | sed -e "s/Project //g" -e "s/(.*)//g"
            ;;
        -l) 
            echo " $(watson log | head -n1)"
            ;;
        *)
            break
    esac
    shift
done

Enter fullscreen mode Exit fullscreen mode

    , Run Com "watson.sh" ["-l"] "watson" 60                                
    , Run Com "watson.sh" ["-s"] "watson2" 60 

Enter fullscreen mode Exit fullscreen mode

This delivered something like this:

No project started. / Friday 27 November 2020 (12h 04m 17s)

The workspace overview tells a different story.

This is from my xmonad settings:


-- needed imports
import XMonad.Hooks.DynamicLog (dynamicLogWithPP, wrap, xmobarPP, xmobarColor, PP(..))

main = do 
        -- i want to have two bars. with slightly different settings
        xmproc0 <- spawnPipe "xmobar -x 0 /home/maren/.config/xmobar/xmobarrc0 -A 200"
        xmproc1 <- spawnPipe "xmobar -x 1 /home/maren/.config/xmobar/xmobarrc1 -A 200"
        xmonad $ ewmh $ docks $ def {

      -- 
      -- [block of ohter definitions]
      --

      -- defining the hook for xmobar

        logHook = myLogHook <+> dynamicLogWithPP xmobarPP
                        { ppOutput = \x -> hPutStrLn xmproc0 x  >> hPutStrLn xmproc1 x
                        , ppCurrent = xmobarColor "FGCOLOR" "" . wrap "[" "]" -- Current workspace in xmobar
                        , ppVisible = xmobarColor "COLOR2" ""                -- Visible but not current workspace
                        , ppHidden = xmobarColor "COLOR3" "" . wrap "*" ""   -- Hidden workspaces in xmobar
                        , ppSep =  "<fc=FGCOLOR> <fn=2>|</fn> </fc>"          -- Separators in xmobar
                        , ppUrgent = xmobarColor "COLOR8" "" . wrap "!" "!"  -- Urgent workspace
                        , ppExtras  = [windowCount]                           -- # of windows current workspace
                        , ppOrder  = \(ws:l:t) -> [ws]
                        }
    } 
Enter fullscreen mode Exit fullscreen mode

And here is the template:

       , template = " <action=`xdotool key control+alt+g`><icon=haskell_20.xpm/> </action><fc=#cfddeb>  |</fc> %StdinReader% }{ <fc=#cfddeb><fn=2>|</fn> </fc><fc=#6F94CF> %cpu% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#6F94CF> %memory% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#6F94CF> %disku% </fc><fc=#cfddeb> <fn=2>|</fn></fc>  <fc=#B993B2> %enp0s31f6% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#cfddeb> <fn=2>|</fn></fc> <fc=#B993B2> %wlp3s0wi% </fc><fc=#cfddeb> <fn=2>|</fn></fc> <fc=#5C54AA> %date% </fc><fc=#cfddeb><fn=2>|</fn></fc> <fc=#5C54AA>%watson2% / %watson% | %battery% %trayerpad%</fc> "

Enter fullscreen mode Exit fullscreen mode

You can ignore the tags the are used to get colors in the bar. Everything which is between % are the variables for replacing the content.

The StdinReader variable provides the workspace display. And here is the result:

xmonad-bar.png

You can see the full configuration here - xmonad and here - picom

Top comments (0)