I'm running XMonad on a laptop that I sometimes, but not always, have an additional monitor attached. I'd like to detect the number of screens in my xmonad.hs
have a instance of XMobar per screen.
I've seen this question and answer, but I've not really got my head around monad transformers and how to make use of a value of type X [Rectangle]
.
Right now, I have, roughly, this:
import XMonad
import XMonad.Config.Desktop
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Core (X ,withDisplay ,io)
import Graphics.X11.Xinerama (getScreenInfo)
import Graphics.X11.Xlib.Types (Rectangle)
import System.IO
xdisplays :: X [Rectangle]
xdisplays = withDisplay $ io . getScreenInfo
main = do
xmproc <- spawnPipe "/usr/bin/xmobar /home/liam/.xmobarrc"
xmonad $ desktopConfig
{ layoutHook = avoidStruts $ layoutHook defaultConfig,
manageHook = manageHook defaultConfig <+> manageDocks,
logHook = dynamicLogWithPP xmobarPP
{ ppOutput = hPutStrLn xmproc
}
}
Naively, I'd like to put rects <- xdisplays
at the start of my do block, then spawn xmobar instances appropriately, but obviously this doesn't work because the type is X [Rectangle]
not IO [Rectangle]
. I wondered if I need to use runX somehow?
Use the startupHook
to run an X
action on every invocation of xmonad. For example,
main = xmonad $ desktopConfig
{ startupHook = do
rects <- xdisplays
{- spawn xmobar -}
}
You might also like countScreens
if all you actually care about is how many screens there are and spawnOnce
so that you don't get an extra copy of xmobar on each restart of xmonad.