title: How to put an instance of XMobar on each screen in XMonad?
body: <p>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 <code>xmonad.hs</code> have a instance of XMobar per screen.</p>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/5607326/finding-the-number-of-x11-screens-from-haskell">this question and answer</a>, but I've not really got my head around monad transformers and how to make use of a value of type <code>X [Rectangle]</code>.</p>
  
  <p>Right now, I have, roughly, this:</p>
  
  <pre><code>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 &lt;- spawnPipe "/usr/bin/xmobar /home/liam/.xmobarrc"
      xmonad $ desktopConfig
          { layoutHook = avoidStruts $ layoutHook defaultConfig,
            manageHook = manageHook defaultConfig &lt;+&gt; manageDocks,
            logHook = dynamicLogWithPP xmobarPP
              { ppOutput = hPutStrLn xmproc
              }
          }
  </code></pre>
  
  <p>Naively, I'd like to put <code>rects &lt;- xdisplays</code> at the start of my do block, then spawn xmobar instances appropriately, but obviously this doesn't work because the type is <code>X [Rectangle]</code> not <code>IO [Rectangle]</code>. I wondered if I need to use <a href="https://hackage.haskell.org/package/xmonad-0.13/docs/XMonad-Core.html#v:runX" rel="nofollow noreferrer">runX</a> somehow?</p>