Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I think this should be really easy for someone who's good at Haskell but I just couldn't figure it out as I'm bad at it. Basically I want to search through the list of windows in the current workspace, find one matching some condition and apply some action to it; if not found then create this window. I had a skeleton code like this

import qualified XMonad.StackSet as W
import XMonad.Actions.WindowGo

findWindow condition actionIfFound actionIfNotFound = 
    ifWindow (condition <&&> member W.current) windowFound actionIfNotFound
        where windowFound = ask >>= w -> do actionIfFound w
share|improve this question

1 Answer 1

Old post, but for anyone still wanting an answer:

Basically, with XMonad.StackSet.index, you can get the list of the windows in the current workspace like this:

    windows <- gets (W.index . windowset)
    -- something...

So findWindow can be implemented like this:

import qualified XMonad.StackSet as W
import Data.List (find)

findWindow :: (Window -> Bool) -> (Window -> X()) -> X() -> X()
findWindow condition actionIfFound actionIfNotFound = do
    windows <- gets (W.index . windowset)
    let found = find condition windows  -- found has type Maybe Window
    case found of
        Nothing -> actionIfNotFound
        Just w -> actionIfFound w

PS: The last three lines could be shortened into maybe actionIfNotFound actionIfFound found

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.