title: Start applications on specific workspace if not yet started there
body: <p>In short: when I switch to workspace <em>X</em>, I want some programs to autostart, but only if they're not already started.</p>
  
  <p>This is different from <a href="https://stackoverflow.com/q/13279791/3132718">XMonad startup on different workspaces</a> as I don't want to move windows to specific workspaces (like always moving xterm to workspace 2).<br>
  This doesn't work for me, either: <a href="https://stackoverflow.com/q/10976044/3132718">xmonad spawn on startup in different workspace</a>. I don't want all applications to start immediately as I log in, also this won't autostart e.g. xterm if I close it and switch to workspace 2 again.</p>
  
  <hr>
  
  <p>Enough about what doesn't work, here is what <em>does</em> work:<br>
  <sub>(almost)</sub></p>
  
  <p>In my workspace list I hold touples with the workspace name and a list programs to start when I switch there:</p>
  
  <pre><code>myWorkspaces = [ ("VIM", ["gvim"]), ("TERM",[myTerminal ++ " -e tmux"]) ]
  
  -- In my keybindings:
  [ ((mod4Mask, key), loadWorkspace workspace cmd)
    | (key, (workspace, cmd)) &lt;- zip [xK_1..] myWorkspaces
  ]
  </code></pre>
  
  <p>I defined a function to switch to a workspace and spawn the given programs:</p>
  
  <pre><code>loadWorkspace :: String -&gt; [String] -&gt; X()
  loadWorkspace workspace commands =
      do windows $ W.greedyView workspace
         mapM_ spawn filtered_commands
             where filtered_commands :: X [String]
                   filtered_commands = filterM isNotOpen commands
  
                   isNotOpen :: String -&gt; X Bool
                   isNotOpen command = return True
  </code></pre>
  
  <p>(For some reason <code>mapM_</code> requires the second argument to be a <em>String</em> instead of <em>[String]</em>. I want to map <code>spawn</code> over the strings in <em>filtered_commands</em>, any idea why this doesn't work?)</p>
  
  <p>The last missing piece is the <code>isNotOpen</code> function, which should search the <code>className</code>s of the windows in the current workspace and return whether <code>command</code> is already there.</p>
  
  <hr>
  
  <p>I find it extremely hard (compared to other languages and technologies) to search for the XMonad way to do things. For this case I could only find how to get the windows in the current WS - <a href="https://superuser.com/a/852152/481701">https://superuser.com/a/852152/481701</a>. Ok, I think, this gives me a Window object, I can query it for some attributes.</p>
  
  <p>But no. The Window is actually... alias for <code>Word64</code>!!! Ok, I think. Google <em>xmonad get window attributes</em>. Nothing. <em>xmonad get classname from window id</em>. Nothing. <em>xmonad window information</em>. And a dozen other ways to say something similar - no helpful results. All I get is the xmonad homepage, the FAQ, or "Xmonad configuration tips".<br>
  I tried these in <em>hayoo!</em>, too, and the closest I could get was "fromClassName - Colorize a window depending on it's className.". Haha.</p>
  
  <h1>So, how can I get a window's className (or any other attributes) outside of <em>ManageHook</em>?</h1>