summaryrefslogtreecommitdiffstats
path: root/XMonad/Stockholm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2022-04-06 15:30:43 +0200
committertv <tv@krebsco.de>2022-04-06 15:52:01 +0200
commit89bae8aad73db8fe9e11da7d515f0b236e7fea51 (patch)
tree5d2687195a4d41445888cbf4ef5def9c84afcf9b /XMonad/Stockholm
parent6421da4e02383bae762fabae97974091733a3386 (diff)
shutdown: add xmonad-0.17 compatibilityHEAD1.3.1master
Diffstat (limited to 'XMonad/Stockholm')
-rw-r--r--XMonad/Stockholm/Shutdown.hs39
1 files changed, 36 insertions, 3 deletions
diff --git a/XMonad/Stockholm/Shutdown.hs b/XMonad/Stockholm/Shutdown.hs
index 373214e..8c0a657 100644
--- a/XMonad/Stockholm/Shutdown.hs
+++ b/XMonad/Stockholm/Shutdown.hs
@@ -6,17 +6,50 @@ module XMonad.Stockholm.Shutdown
)
where
+import Control.Applicative ((<|>), empty)
import Control.Concurrent (threadDelay)
-import Control.Monad (forever, when)
+import Control.Monad (forever, guard, when)
import Data.Monoid (All(All))
+import System.Directory (XdgDirectory(XdgData), createDirectoryIfMissing, doesFileExist, getAppUserDataDirectory, getXdgDirectory)
import System.Exit (exitSuccess)
+import System.Environment (lookupEnv)
import System.FilePath ((</>))
import System.IO.Error (isDoesNotExistError, tryIOError)
import System.IO (hPutStrLn, stderr)
import System.Posix.Process (getProcessID)
import System.Posix.Signals (nullSignal, signalProcess)
import System.Posix.Types (ProcessID)
-import XMonad
+import XMonad hiding (getXMonadDataDir)
+
+
+-- XXX this is for compatibility with both xmonad<0.17 and xmonad>=0.17
+getXMonadDataDir :: IO String
+getXMonadDataDir = xmEnvDir <|> xmDir <|> xdgDir
+ where
+ -- | Check for xmonad's environment variables first
+ xmEnvDir :: IO String
+ xmEnvDir =
+ maybe empty pure =<< lookupEnv "XMONAD_DATA_DIR"
+
+ -- | Check whether the config file or a build script is in the
+ -- @~\/.xmonad@ directory
+ xmDir :: IO String
+ xmDir = do
+ d <- getAppUserDataDirectory "xmonad"
+ conf <- doesFileExist $ d </> "xmonad.hs"
+ build <- doesFileExist $ d </> "build"
+ pid <- doesFileExist $ d </> "xmonad.pid"
+
+ -- Place *everything* in ~/.xmonad if yes
+ guard $ conf || build || pid
+ pure d
+
+ -- | Use XDG directories as a fallback
+ xdgDir :: IO String
+ xdgDir = do
+ d <- getXdgDirectory XdgData "xmonad"
+ d <$ createDirectoryIfMissing True d
+
newShutdownEventHandler :: IO (Event -> X All)
newShutdownEventHandler = do
@@ -65,7 +98,7 @@ waitProcess pid = forever (signalProcess nullSignal pid >> threadDelay 10000)
-- PID file stuff
--
-getProcessIDFileName :: (Functor m, MonadIO m) => m FilePath
+getProcessIDFileName :: IO FilePath
getProcessIDFileName = (</> "xmonad.pid") <$> getXMonadDataDir
writeProcessIDToFile :: IO ()