XMobar clickable workspaces
After years of using xfce for daily work I’ve headed back to tiling territory.
Stumbled on a git bug report discussing clickable workspaces with xmobar, which lead me to the xmobar plugin: UnsafeStdinReader that would enable escape sequences in workspace to be accepted by xmobar.
Below is a working example for XMonad 0.13:
import XMonad
import XMonad.Config.Desktop
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 =? "rdesktop" --> doFloat
]
xmobarEscape = concatMap doubleLts
where doubleLts '<' = "<<"
doubleLts x = [x]
myWorkspaces :: [String]
myWorkspaces = clickable . (map xmobarEscape) $ ["1","2","3","4","5"]
where
clickable l = [ "<action=xdotool key alt+" ++ show (n) ++ ">" ++ ws ++ "</action>" |
(i,ws) <- zip [1..5] l,
let n = i ]
main = do
xmproc <- spawnPipe "xmobar /home/someuser/.xmobarrc"
xmonad $ desktopConfig
{ manageHook = manageDocks <+> myManageHook -- make sure to include myManageHook definition from above
<+> manageHook desktopConfig
, layoutHook = avoidStruts $ layoutHook desktopConfig
, workspaces = myWorkspaces
, logHook = dynamicLogWithPP xmobarPP
{ ppOutput = hPutStrLn xmproc
, ppCurrent = xmobarColor "yellow" "" . wrap "[" "]"
, ppHiddenNoWindows = xmobarColor "grey" ""
, ppTitle = xmobarColor "green" "" . shorten 40
, ppVisible = wrap "(" ")"
, ppUrgent = xmobarColor "red" "yellow"
}
, modMask = mod1Mask -- Rebind Mod to the Left Alt key globally
} `additionalKeys`
[ ((mod1Mask, xK_f), spawn "firefox")
, ((mod1Mask, xK_Return), spawn "urxvt")
]
And the .xmobarrc:
Config { font = "xft:Dina:pixelsize=13"
, bgColor = "black"
, fgColor = "grey"
, position = TopW L 100
, lowerOnStart = True
, commands = [ Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run Memory ["-t","Mem: <usedratio>%"] 10
, Run Swap [] 10
, Run Date "%a %b %_d %H:%M" "date" 10
, Run UnsafeStdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = "%UnsafeStdinReader% }{ %cpu% | %memory% * %swap% <fc=#ee9a00>%date%</fc>"
}