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

Brandon Allbery allbery.b at gmail.com
Sun Feb 12 00:11:25 CET 2012


On Sat, Feb 11, 2012 at 17:46, Toby Cubitt <tsc25 at cantab.net> wrote:

> 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
> work.
>
> 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'
>

The problem here is that your function wants to execute in the X monad, but
is actually running in the Query monad because it's in a ManageHook.  The
fix is to wrap it in liftX:

    className =? "mutt" --> liftX (doShiftEmpty "email")

By the way, did you really mean className there?  mutt is terminal based;
className will therefore always be the terminal program you're using, and
will start with an uppercase letter.  Assuming you're using -name or
similar to set the instance name for the terminal to "mutt", you probably
want appName instead.

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/xmonad/attachments/20120211/69fb2c88/attachment.htm>


More information about the xmonad mailing list