Reset layout to default on last window close

Hello, I want workspace layout to reset to some default once last window is closed. Quick glance though Xmonad-related modules names didn't give me any hints on what hook (or some other facility) to use, so I'm seeking your advice, fellow Xmonaders: how can I accomplish that? -- Regards, Alexander Batischev 4096R/0C8BFD03 CE6C 4307 9348 58E3 FD94 A00F 3569 61A2 0C8B FD03

Quoting Alexander Batischev
I want workspace layout to reset to some default once last window is closed. Quick glance though Xmonad-related modules names didn't give me any hints on what hook (or some other facility) to use, so I'm seeking your advice, fellow Xmonaders: how can I accomplish that?
To do this correctly, you'd need xmonad to inform you when it gets window deletion events. The best way to do that is to write a layout (modifier). I don't think a modifier that runs a particular action when the last window disappears has been written yet, but it seems like it shouldn't be too hard to do it once you've learned the basics of how layout works in xmonad. Alternately, if you're willing to only close windows via xmonad (e.g. mod+shift+c), you could make a keybinding like this one: import qualified Data.Set as S ((modMask .|. shiftMask, xK_c), do almostEmpty <- gets ((1 ==) . S.size . mapped) kill when almostEmpty (sendMessage (JumpToLayout blargle)) ) Caveat lector: this code is completely untested, and it certainly won't behave properly if the application closes itself (e.g. from a ^W or ^Q accelerator, from File -> Exit, by clicking a tray icon that hides the window, by middle-clicking the last tab in chromium/Firefox, etc.). Documentation for using the JumpToLayout message, which you will probably need for either solution, is available at http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Layout-LayoutCombinators... Some documentation on extending xmonad (but, notably, missing the section on LayoutClass, which is what you would need for the real solution) is available at http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Doc-Developing.html Good luck! ~d

On Tue, Feb 28, 2012 at 10:44, Alexander Batischev
I want workspace layout to reset to some default once last window is closed. Quick glance though Xmonad-related modules names didn't give me any hints on what hook (or some other facility) to use, so I'm seeking your advice, fellow Xmonaders: how can I accomplish that?
Use XMonad.Layout.LayoutCombinators; you want its version of the (|||) operator so you can send the JumpToLayout message. Beyond that, you want to use a handleEventHook which matches DestroyWindowEvent and checks the contents of the current workspace; if only one window is present, send the JumpToLayout message. It should end up being something like this (untested):
import XMonad hiding (|||) import XMonad.Layout.LayoutCombinators import qualified XMonad.StackSet as W import Data.Monoid -- for All ... handleEventHook DestroyWindowEvent {} = n <- (length . index) `fmap` withWindowSet guard (n == 1) $ sendMessage $ JumpToLayout "name of initial layout here" return (All True)
-- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (3)
-
Alexander Batischev
-
Brandon Allbery
-
wagnerdm@seas.upenn.edu