Merge pull request #553 from TheMC47/postpone-pipe

X.H.StatusBar.statusBarPipe: spawn in the startupHook
This commit is contained in:
Yecine Megdiche 2021-06-02 16:02:57 +02:00 committed by GitHub
commit dac3acc5dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,8 +57,10 @@ module XMonad.Hooks.StatusBar (
) where
import Control.Exception (SomeException, try)
import Data.IORef (newIORef, readIORef, writeIORef)
import qualified Codec.Binary.UTF8.String as UTF8 (encode)
import qualified Data.Map as M
import System.IO (hClose)
import System.Posix.Signals (sigTERM, signalProcessGroup)
import System.Posix.Types (ProcessID)
@ -311,9 +313,19 @@ statusBarPropTo prop cmd pp = def
statusBarPipe :: String -- ^ The command line to launch the status bar
-> X PP -- ^ The pretty printing options
-> IO StatusBarConfig
statusBarPipe cmd xpp = do
h <- spawnPipe cmd
return $ def { sbLogHook = xpp >>= \pp -> dynamicLogWithPP pp { ppOutput = hPutStrLn h } }
statusBarPipe cmd xpp = do
hRef <- newIORef Nothing
return $ def
{ sbStartupHook = io (writeIORef hRef . Just =<< spawnPipe cmd)
, sbLogHook = do
pp <- xpp
h' <- io (readIORef hRef)
whenJust h' $ \h -> dynamicLogWithPP pp { ppOutput = hPutStrLn h }
, sbCleanupHook = io
$ readIORef hRef
>>= (`whenJust` hClose)
>> writeIORef hRef Nothing
}
-- $multiple