Squidly
Squidly

Reputation: 2717

XMobar is dying due to a problem in my Xmonad config, related to IO

This is a follow up to this question.
In pursuit of trying to find how many physical monitors I had, I came up with

screenCount :: X Int
screenCount = withDisplay (io.fmap length.getScreenInfo)


makeXMobars :: X [Handle] -- loads two xmobars per screen, one top & one bottom
makeXMobars = screenCount >>= (io.mapM spawnPipe.commandHandles )
  where
    commandHandles n = map ((\x -> "xmobar -x " ++ x).unwords) $ commandNames n
    commandNames n = sequence [map show [0..n], map (\x -> "~/.xmobarrc" ++ x) ["Top", "Bottom"]]



myLogHook :: X ()
myLogHook  = do
  handles <- makeXMobars
  dynamicLogWithPP $ defaultPP                                                                   
    {
      ppOutput  = \x -> mapM_ (`hPutStrLn` x) handles
    } 

myLogHook just drops in to the xmonad $ DefaultConfig. However, when I load XMonad the PipeReader for the top XMobars (on both screens) just shows updating for a little while, and then disappears, and refuses to come back when I reload. The bottom ones are perfectly happy.

Previously, I simply used for my ppOutput:

 ppOutput = \x -> hPutStrLn xmobarTopScreen0 x >> hPutStrLn xmobarTopScreen1 x

which worked perfectly fine.

I assume I've made some error with my understanding of IO, rather than the code itself being bad per se, but I'm really not sure.

Upvotes: 2

Views: 1135

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 152707

I suspect that you want to use map show [0 .. n-1] rather than map show [0 .. n]. I also suggest that you spawn the xmobar instances in main rather than in logHook, since the latter will spawn brand new copies of xmobar every time you do any xmonad action (like changing focus). As for screenCount, may I suggest countScreens from the IndependentScreens module?

Upvotes: 4

Related Questions