[xmonad] Can I switch layouts based on number of windows in a workspace?

Brandon Allbery allbery.b at gmail.com
Mon Aug 27 17:12:55 CEST 2012

On Mon, Aug 27, 2012 at 5:48 AM, Jeffrey David Johnson <jefdaj at gmail.com>wrote:

> I'd like to have a different layout depending on how many windows are
> visible. Something like:
> one?            --> Full
> under four? --> Tall
> otherwise    --> Grid

Hm, this would be a simple generalization of a module I've been working on
that already distinguishes between 1 and multiple windows.  But it's
waiting for me to get a test environment back up and running, which is
taking a while :(

I've attached the current version; it compiles but is not tested in
practice.  It should be clear enough how to extend it to support other
values than One and Multiple.

The problem with doing it in the ManageHook is that it can only see new
windows being added, not windows being removed.  You would have to listen
for UnmapWindow or DestroyWindow events in the handleEventHook to catch the
latter; or do it in the layout, which listens for all of them for you.

> I couldn't find an existing function, and didn't make much headway writing
> my own either. (I tried to use sendMessage $ JumpToLayout "Full" etc. in a
> managehook) Is there an obvious way to do this?

In general this is (liftX ({- general code goes here -}) >> idHook).  The
idHook is needed to switch the type back from Query () to Query (Endo
WindowSet); a ManageHook really wants to operate on workspaces, not run
random code, so we need to apply the dummy workspace update.  We may add a
(doX) function at some point since the idiom seems to come up a lot.

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/20120827/a9b41eb9/attachment.htm>

More information about the xmonad mailing list