diff options
| author | Jochen Keil <jochen.keil@gmail.com> | 2012-08-09 10:12:39 +0200 | 
|---|---|---|
| committer | Jochen Keil <jochen.keil@gmail.com> | 2012-08-09 10:46:18 +0200 | 
| commit | fa4b999c73067cb55e316b94fe62aebb147cea98 (patch) | |
| tree | 1a8ce7da66ca387c2c8dba61f540a362140104db | |
| parent | 536273a9d980cf3e71d8d05813e18b3ebcaf9233 (diff) | |
| download | xmobar-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.
| -rw-r--r-- | src/Main.hs | 7 | ||||
| -rw-r--r-- | src/Window.hs | 1 | ||||
| -rw-r--r-- | src/Xmobar.hs | 14 | 
3 files changed, 13 insertions, 9 deletions
| diff --git a/src/Main.hs b/src/Main.hs index 4c3f351..c7045b5 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -36,6 +36,8 @@ import System.Environment  import System.Posix.Files  import Control.Monad (unless) +import Signal (setupSignalHandler, SignalType(..)) +  -- $main  -- | The main entry point @@ -55,9 +57,10 @@ main = do    conf  <- doOpts c o    fs    <- initFont d (font conf)    cls   <- mapM (parseTemplate conf) (splitTemplate conf) -  vars  <- mapM (mapM startCommand) cls +  sig   <- setupSignalHandler +  vars  <- mapM (mapM $ startCommand sig) cls    (r,w) <- createWin d fs conf -  startLoop (XConf d r w fs conf) vars +  startLoop (XConf d r w fs conf) sig vars  -- | Splits the template in its parts  splitTemplate :: Config -> [String] diff --git a/src/Window.hs b/src/Window.hs index 34ecbf4..4917f57 100644 --- a/src/Window.hs +++ b/src/Window.hs @@ -25,7 +25,6 @@ createWin d fs c = do        (r,o) = setPosition (position c) srs (fi ht)    win <- newWindow  d (defaultScreenOfDisplay d) rootw r o    setProperties r c d win srs -  when (lowerOnStart c) (lowerWindow d win)    mapWindow         d win    return (r,win) 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 | 
