tv xmonad: wait for shutdown to complete

This commit is contained in:
tv 2018-11-28 17:03:15 +01:00
parent ef418b19a0
commit 2b9d361f7f
2 changed files with 25 additions and 3 deletions

View File

@ -101,7 +101,7 @@ in {
"\${XMONAD_DATA_DIR}" "\${XMONAD_DATA_DIR}"
]}"; ]}";
ExecStart = "${pkgs.xmonad-tv}/bin/xmonad-${currentSystem}"; ExecStart = "${pkgs.xmonad-tv}/bin/xmonad-${currentSystem}";
ExecStop = "${pkgs.xmonad-tv}/bin/xmonad-${currentSystem} --shutdown"; ExecStop = "${pkgs.xmonad-tv}/bin/xmonad-${currentSystem} --shutdown $MAINPID";
User = cfg.user.name; User = cfg.user.name;
WorkingDirectory = cfg.user.home; WorkingDirectory = cfg.user.home;
}; };

View File

@ -19,6 +19,11 @@ pkgs.writeHaskellPackage "xmonad-tv" {
module Main where module Main where
import System.IO.Error (isDoesNotExistError, tryIOError)
import System.Exit (exitFailure)
import Control.Monad (forever)
import Control.Concurrent (threadDelay)
import Control.Exception import Control.Exception
import Control.Monad.Extra (whenJustM) import Control.Monad.Extra (whenJustM)
import Graphics.X11.ExtraTypes.XF86 import Graphics.X11.ExtraTypes.XF86
@ -27,6 +32,8 @@ import XMonad
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
import System.Environment (getArgs, getEnv, getEnvironment, lookupEnv) import System.Environment (getArgs, getEnv, getEnvironment, lookupEnv)
import System.Posix.Process (executeFile) import System.Posix.Process (executeFile)
import System.Posix.Signals (nullSignal, signalProcess)
import System.Posix.Types (ProcessID)
import XMonad.Actions.DynamicWorkspaces ( addWorkspacePrompt, renameWorkspace import XMonad.Actions.DynamicWorkspaces ( addWorkspacePrompt, renameWorkspace
, removeEmptyWorkspace) , removeEmptyWorkspace)
import XMonad.Actions.GridSelect import XMonad.Actions.GridSelect
@ -57,8 +64,23 @@ myFont = "-schumacher-*-*-*-*-*-*-*-*-*-*-*-iso10646-*"
main :: IO () main :: IO ()
main = getArgs >>= \case main = getArgs >>= \case
["--shutdown"] -> sendShutdownEvent [] -> mainNoArgs
_ -> mainNoArgs ["--shutdown", pidArg] -> mainShutdown (read pidArg)
args -> hPutStrLn stderr ("bad arguments: " <> show args) >> exitFailure
mainShutdown :: ProcessID -> IO ()
mainShutdown pid = do
sendShutdownEvent
hPutStrLn stderr ("waiting for: " <> show pid)
result <- tryIOError (waitProcess pid)
if isSuccess result
then hPutStrLn stderr ("result: " <> show result <> " [AKA success^_^]")
else hPutStrLn stderr ("result: " <> show result)
where
isSuccess = either isDoesNotExistError (const False)
waitProcess :: ProcessID -> IO ()
waitProcess pid = forever (signalProcess nullSignal pid >> threadDelay 10000)
mainNoArgs :: IO () mainNoArgs :: IO ()
mainNoArgs = do mainNoArgs = do