Use Xmobar on several Monitors

2.3k Views Asked by At

This Question was answered several times but I do not understand the accepted answers. For example here How to spawn XMobar instance for each screen?. In the question the user refers to another question where the solution is hidden behind a comment. But the accepted answer in this thread still hides code behind a comment. Can someone post a xmonad.hs that solves the problem and can be compiled?

I also asked this question here https://www.reddit.com/r/xmonad/comments/lowbw1/same_xmobar_on_several_screens/ but got the answer that it is not possible. But as written above there seems to be a solution since there were accepted answers.

1

There are 1 best solutions below

0
On BEST ANSWER

If you using Xmonad as your window manager, you can spawn xmobar in your xmonad.hs this way, importing XMonad.Util.Run to run 'spawnPipe'

main = do
     -- Launching three instances of xmobar on their monitors.
     xmproc0 <- spawnPipe "xmobar -x 0 $HOME/.config/xmobar/xmobarrc0"
     xmproc1 <- spawnPipe "xmobar -x 1 $HOME/.config/xmobar/xmobarrc2"
     xmproc2 <- spawnPipe "xmobar -x 2 $HOME/.config/xmobar/xmobarrc1"

it can be the same xmobarrc if you want.

With this you can pass parameters from Xmonad, like your workspaces, layouts, etc, to xmobar, defining in your def config

xmonad $ def {
      keys = myKeys
    , otherHooks...
    , logHook = myLogHook <+> dynamicLogWithPP xmobarPP
                    { ppOutput = \x -> hPutStrLn xmproc0 x  >> hPutStrLn xmproc1 x  >> hPutStrLn xmproc2 x
    , ppFormats
    }
} 

for the ppFormats check XMonad.Hooks.DynamicLog

And, if you aren't using Xmonad, probably defining in your startup file like .xinitrc or the file you use adding

exec 'xmobar -x 0 /path/to/config' &
exec 'xmobar -x 1 /path/to/config' &
exec ...

would work fine, but this I can't tell you how to pass info of you windows to xmobar.

I found this code here, there you can find an amazingly long xmonad config to take notes and ideas, and also some xmobar configs.

Hope this was helpfull