summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar.hs
diff options
context:
space:
mode:
authorJochen Keil <jochen.keil@gmail.com>2012-08-09 10:12:39 +0200
committerJochen Keil <jochen.keil@gmail.com>2012-08-09 10:46:18 +0200
commitfa4b999c73067cb55e316b94fe62aebb147cea98 (patch)
tree1a8ce7da66ca387c2c8dba61f540a362140104db /src/Xmobar.hs
parent536273a9d980cf3e71d8d05813e18b3ebcaf9233 (diff)
downloadxmobar-fa4b999c73067cb55e316b94fe62aebb147cea98.tar.gz
xmobar-fa4b999c73067cb55e316b94fe62aebb147cea98.tar.bz2
Create signal handler in main and pass it down to the start* functions
This is necessary for setting up the signal callback (trigger) from the Plugin interface. As another benefit it is now possible to implement the lowerOnStart config option properly by simply sending a Hide signal in startLoop.
Diffstat (limited to 'src/Xmobar.hs')
-rw-r--r--src/Xmobar.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Xmobar.hs b/src/Xmobar.hs
index 6c2965c..1b58352 100644
--- a/src/Xmobar.hs
+++ b/src/Xmobar.hs
@@ -71,10 +71,10 @@ runX :: XConf -> X () -> IO ()
runX xc f = runReaderT f xc
-- | Starts the main event loop and threads
-startLoop :: XConf -> [[(Maybe ThreadId, TVar String)]] -> IO ()
-startLoop xcfg@(XConf _ _ w _ _) vs = do
+startLoop :: XConf -> MVar SignalType -> [[(Maybe ThreadId, TVar String)]] -> IO ()
+startLoop xcfg@(XConf _ _ w _ conf) sig vs = do
tv <- atomically $ newTVar []
- sig <- setupSignalHandler
+ when (lowerOnStart conf) $ putMVar sig Hide
_ <- forkIO (checker tv [] vs sig `catch`
\(SomeException _) -> void (putStrLn "Thread checker failed"))
#ifdef THREADED_RUNTIME
@@ -156,19 +156,21 @@ eventLoop tv xc@(XConf d _ w fs cfg) signal = do
o ->
return (ocfg {position = OnScreen 1 o})
-
-- $command
-- | Runs a command as an independent thread and returns its thread id
-- and the TVar the command will be writing to.
-startCommand :: (Runnable,String,String) -> IO (Maybe ThreadId, TVar String)
-startCommand (com,s,ss)
+startCommand :: MVar SignalType
+ -> (Runnable,String,String)
+ -> IO (Maybe ThreadId, TVar String)
+startCommand sig (com,s,ss)
| alias com == "" = do var <- atomically $ newTVar is
atomically $ writeTVar var (s ++ ss)
return (Nothing,var)
| otherwise = do var <- atomically $ newTVar is
let cb str = atomically $ writeTVar var (s ++ str ++ ss)
h <- forkIO $ start com cb
+ _ <- forkIO $ trigger com ( maybe (return ()) (putMVar sig) )
return (Just h,var)
where is = s ++ "Updating..." ++ ss