[xmonad] Shutdown hook

Don Stewart dons at galois.com
Sat Feb 13 18:55:39 EST 2010


juhe_xmonad:
> Hello,
>
> There is a startupHook in XConfig. I'm missing shutdownHook however. Is  
> there any proper way to execute custom code when xmonad is about to exit?
>

xmonad exits by throwing an asynchronous exception from the inner loop
out to main. The runtime catches this an exits gracefully.

You can write your own shutdown hook by catching this exception in your 
config main, and running your hook, before rethrowing.

I bet someone's already done this, and wrapped it up nicely, otherwise,
look at Control.Exception in the Haskell base library for how to use the
catch/handle functions.

Pseudocode:

    import Control.Exception
    import XMonad

    main = handle xmonad shutdown
       where
        shutdown e = do
            ... my action ...
            throw e


More information about the xmonad mailing list