[xmonad] Reset layout to default on last window close
wagnerdm at seas.upenn.edu
wagnerdm at seas.upenn.edu
Tue Feb 28 19:40:46 CET 2012
Quoting Alexander Batischev <eual.jp at gmail.com>:
> 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.html
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
More information about the xmonad
mailing list