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

I'd like to have a different layout depending on how many windows are visible. Something like: one? --> Full under four? --> Tall otherwise --> Grid 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? Thanks Jeff

On Mon, Aug 27, 2012 at 5:48 AM, Jeffrey David Johnson
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@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Mon, Aug 27, 2012 at 11:12 AM, Brandon Allbery
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.
Except I forgot to actually attach it... -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Thanks, I'll read through this and try to figure it out when I get a chance (maybe later today). In the meantime I get a compile error: jefdaj@acro:~/.xmonad$ ghc --make OnlyFor.hs [1 of 1] Compiling XMonad.Layout.OnlyFor ( OnlyFor.hs, OnlyFor.o ) OnlyFor.hs:60:64: `m' is applied to too many type arguments In the type signature for `onlyFor': onlyFor :: HowMany -> m -> l a -> ModifiedLayout (OnlyFor (m a)) l a If I comment out the type signature and load it in GHCI it guesses this: onlyFor :: HowMany -> m -> l a -> XMonad.Layout.LayoutModifier.ModifiedLayout (OnlyFor m) l a Does that look reasonable? m is One | Multiple, l is the LayoutModifier and a is the Layout right? Jeff On 08/27/2012 08:28 AM, Brandon Allbery wrote:
On Mon, Aug 27, 2012 at 11:12 AM, Brandon Allbery
mailto:allbery.b@gmail.com> wrote: 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.
Except I forgot to actually attach it...
-- brandon s allbery allbery.b@gmail.com mailto:allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Mon, Aug 27, 2012 at 1:36 PM, Jeffrey David Johnson
Thanks, I'll read through this and try to figure it out when I get a chance (maybe later today). In the meantime I get a compile error:
jefdaj@acro:~/.xmonad$ ghc --make OnlyFor.hs [1 of 1] Compiling XMonad.Layout.OnlyFor ( OnlyFor.hs, OnlyFor.o ) OnlyFor.hs:60:64: `m' is applied to too many type arguments
*sigh* sorry, thought that was already fixed in that copy of the source. (this is why I retracted original patches and am not releasing until I can get my working environment back going....) ghci should be correct.
onlyFor :: HowMany -> m -> l a -> XMonad.Layout.LayoutModifier.ModifiedLayout (OnlyFor m) l a
Does that look reasonable? m is One | Multiple, l is the LayoutModifier and a is the Layout right?
"m" is the layout modifier to be applied, "l a" is the layout modifier to apply it to, "a" is instantiated to Window in xmonad and to a dummy when running pure tests. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

OK that makes sense I think. I ran into another problem though when trying to integrate it into my xmonad.hs. I used: myLayoutHook = onlyFor Multiple (spacing 2) $ Tall 1 (3/100) (1/2) and got this big long error. Something about Read instances, but all the data declarations in OnlyFor.hs have deriving (Read, Show) on them so I'm not sure what's up with that. Jeff jefdaj@acro:~/.xmonad$ ghc --make OnlyFor.hs xmonad.hs -o xmonad-x86_64-linux [2 of 2] Compiling Main ( xmonad.hs, xmonad.o ) xmonad.hs:199:5: No instances for (Read (l0 a0 -> XMonad.Layout.LayoutModifier.ModifiedLayout Spacing l0 a0), XMonad.Layout.LayoutModifier.LayoutModifier (OnlyFor (l0 a0 -> XMonad.Layout.LayoutModifier.ModifiedLayout Spacing l0 a0)) GHC.Word.Word64) arising from a use of `xmonad' Possible fix: add instance declarations for (Read (l0 a0 -> XMonad.Layout.LayoutModifier.ModifiedLayout Spacing l0 a0), XMonad.Layout.LayoutModifier.LayoutModifier (OnlyFor (l0 a0 -> XMonad.Layout.LayoutModifier.ModifiedLayout Spacing l0 a0)) GHC.Word.Word64) In the expression: xmonad In a stmt of a 'do' block: xmonad $ defaultConfig {terminal = "lxterminal", borderWidth = 2, modMask = mod4Mask, keys = myKeys, workspaces = myWorkspaces, handleEventHook = myHandleEventHook, layoutHook = myLayoutHook, manageHook = myManageHook, logHook = myLogHook toolbarPipe, normalBorderColor = myNormalBorderColor, focusedBorderColor = myFocusedBorderColor} In the expression: do { spawn myBackgroundApps; toolbarPipe <- spawnPipe myToolbar; xmonad $ defaultConfig {terminal = "lxterminal", borderWidth = 2, modMask = mod4Mask, keys = myKeys, workspaces = myWorkspaces, handleEventHook = myHandleEventHook, layoutHook = myLayoutHook, manageHook = myManageHook, logHook = myLogHook toolbarPipe, normalBorderColor = myNormalBorderColor, focusedBorderColor = myFocusedBorderColor} } On 08/27/2012 11:01 AM, Brandon Allbery wrote:
On Mon, Aug 27, 2012 at 1:36 PM, Jeffrey David Johnson
mailto:jefdaj@gmail.com> wrote: Thanks, I'll read through this and try to figure it out when I get a chance (maybe later today). In the meantime I get a compile error:
jefdaj@acro:~/.xmonad$ mailto:jefdaj@acro:%7E/.xmonad$ ghc --make OnlyFor.hs [1 of 1] Compiling XMonad.Layout.OnlyFor ( OnlyFor.hs, OnlyFor.o ) OnlyFor.hs:60:64: `m' is applied to too many type arguments
*sigh* sorry, thought that was already fixed in that copy of the source. (this is why I retracted original patches and am not releasing until I can get my working environment back going....) ghci should be correct.
onlyFor :: HowMany -> m -> l a -> XMonad.Layout.LayoutModifier.ModifiedLayout (OnlyFor m) l a
Does that look reasonable? m is One | Multiple, l is the LayoutModifier and a is the Layout right?
"m" is the layout modifier to be applied, "l a" is the layout modifier to apply it to, "a" is instantiated to Window in xmonad and to a dummy when running pure tests.
-- brandon s allbery allbery.b@gmail.com mailto:allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (2)
-
Brandon Allbery
-
Jeffrey David Johnson