[xmonad] Managehook which only shifts window if workspace is empty

Toby Cubitt tsc25 at cantab.net
Sat Feb 11 23:46:33 CET 2012

I'm trying to write a Managehook that only shifts a window to workspace
if that workspace is empty. But I'm quickly realising I don't have a good
enough grasp of Xmonad types, and Haskell monads in general, to get it to

So far, the closest I think I've got is the following:

myManageHook = [ className =? "mutt" --> doShiftEmpty "email" ]
               where doShiftEmpty t = when (isEmpty t) (doShift t)
                     isEmpty t = do wsl <- gets $ W.workspaces . windowset
                                    let mws = find (\ws -> W.tag ws == t) wsl
                                    return $ maybe True (isNothing . W.stack) mws

which throws a type error:

  "Couldn't match expected type `Bool' with actual type `m0 Bool'
   In the return type of a call of `isEmpty'"

I think I vaguely understand the problem, namely that "when" expects a
Bool as its first argument, whereas the "return" in isEmpty returns a
Bool wrapped inside a monad. But removing the "return" just throws a more
confusing type error. Clearly, I'm way out of my depth here, and am doing
little better than cargo cult programming.

Can someone who understands these things properly explain where I'm going
wrong here?

More generally, is there a tutorial explaining the Xmonad types and data
structures, and how they go together to make up Xmoand? I've been working
through some basic Haskell tutorials, but there's still quite a step from
understanding a little Haskell, to understanding enough of how Xmonad
works to write a simple Managehook action.

Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25 at cantab.net
web:   www.dr-qubit.org

More information about the xmonad mailing list