mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
Merge pull request #553 from TheMC47/postpone-pipe
X.H.StatusBar.statusBarPipe: spawn in the startupHook
This commit is contained in:
commit
dac3acc5dd
@ -57,8 +57,10 @@ module XMonad.Hooks.StatusBar (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Exception (SomeException, try)
|
import Control.Exception (SomeException, try)
|
||||||
|
import Data.IORef (newIORef, readIORef, writeIORef)
|
||||||
import qualified Codec.Binary.UTF8.String as UTF8 (encode)
|
import qualified Codec.Binary.UTF8.String as UTF8 (encode)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
import System.IO (hClose)
|
||||||
import System.Posix.Signals (sigTERM, signalProcessGroup)
|
import System.Posix.Signals (sigTERM, signalProcessGroup)
|
||||||
import System.Posix.Types (ProcessID)
|
import System.Posix.Types (ProcessID)
|
||||||
|
|
||||||
@ -311,9 +313,19 @@ statusBarPropTo prop cmd pp = def
|
|||||||
statusBarPipe :: String -- ^ The command line to launch the status bar
|
statusBarPipe :: String -- ^ The command line to launch the status bar
|
||||||
-> X PP -- ^ The pretty printing options
|
-> X PP -- ^ The pretty printing options
|
||||||
-> IO StatusBarConfig
|
-> IO StatusBarConfig
|
||||||
statusBarPipe cmd xpp = do
|
statusBarPipe cmd xpp = do
|
||||||
h <- spawnPipe cmd
|
hRef <- newIORef Nothing
|
||||||
return $ def { sbLogHook = xpp >>= \pp -> dynamicLogWithPP pp { ppOutput = hPutStrLn h } }
|
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
|
-- $multiple
|
||||||
|
Loading…
x
Reference in New Issue
Block a user