diff options
author | makefu <github@syntax-fehler.de> | 2015-10-25 18:17:14 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2015-10-25 18:17:14 +0100 |
commit | bb16a38df6ad33c7339d4875e948853927015045 (patch) | |
tree | 3cd41d5d52c8facf55e48e05c65b6bad887ae4c3 /tv/2configs/xserver/xmonad/Util/Shutdown.hs | |
parent | cca25c7b66c44e0ec826d466bd48f2463df03fe9 (diff) | |
parent | 4b22988392f940c705e7f3fddc39481635777895 (diff) |
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'tv/2configs/xserver/xmonad/Util/Shutdown.hs')
-rw-r--r-- | tv/2configs/xserver/xmonad/Util/Shutdown.hs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tv/2configs/xserver/xmonad/Util/Shutdown.hs b/tv/2configs/xserver/xmonad/Util/Shutdown.hs new file mode 100644 index 000000000..c5a3edb80 --- /dev/null +++ b/tv/2configs/xserver/xmonad/Util/Shutdown.hs @@ -0,0 +1,53 @@ +{-# LANGUAGE LambdaCase #-} +module Util.Shutdown + ( sendShutdownEvent + , handleShutdownEvent + , shutdown + ) + where + +import Control.Monad +import Data.Monoid +import Data.Maybe (catMaybes) +import qualified Data.Map as Map +import System.Environment (getEnv) +import System.Exit (exitSuccess) +import XMonad +import qualified XMonad.StackSet as W + +sendShutdownEvent :: IO () +sendShutdownEvent = do + dpy <- openDisplay "" + rw <- rootWindow dpy $ defaultScreen dpy + a <- internAtom dpy "XMONAD_SHUTDOWN" False + allocaXEvent $ \e -> do + setEventType e clientMessage + setClientMessageEvent e rw a 32 0 currentTime + sendEvent dpy rw False structureNotifyMask e + sync dpy False + +handleShutdownEvent :: Event -> X All +handleShutdownEvent = \case + ClientMessageEvent { ev_message_type = mt } -> do + c <- (mt ==) <$> getAtom "XMONAD_SHUTDOWN" + when c shutdown + return (All c) + _ -> + return (All True) + +shutdown :: X () +shutdown = do + broadcastMessage ReleaseResources + io . flush =<< asks display + let wsData = show . W.mapLayout show . windowset + maybeShow (t, Right (PersistentExtension ext)) = Just (t, show ext) + maybeShow (t, Left str) = Just (t, str) + maybeShow _ = Nothing + extState = + return . show . catMaybes . map maybeShow . Map.toList . extensibleState + s <- gets (\s -> (wsData s : extState s)) + _ <- io $ do + path <- getEnv "XMONAD_STATE" + writeFile path (concatMap (++"\n") s) + exitSuccess + return () |