diff options
author | Jochen Keil <jochen.keil@gmail.com> | 2012-08-22 20:52:52 +0200 |
---|---|---|
committer | Jochen Keil <jochen.keil@gmail.com> | 2012-08-22 21:27:18 +0200 |
commit | fefeae79de28446d46dc21e193aa34fcd4fe9002 (patch) | |
tree | 97250603df41b6a6cf66a8c0b0e0cd483dd55c89 /src/Xmobar.hs | |
parent | 68f9f51cd7e20190e1ef2fd95beaf7c852f11c81 (diff) | |
download | xmobar-fefeae79de28446d46dc21e193aa34fcd4fe9002.tar.gz xmobar-fefeae79de28446d46dc21e193aa34fcd4fe9002.tar.bz2 |
Make it possible to delay Hide, Reveal and Toggle signals
Previously Hide, Reveal and Toggle were immediate actions. This is the
same behaviour as if called now with 0 as parameter.
If the parameter is a positive non zero value it is taken as a delay for
the requested action.
After the delay (implemented using threadDelay) a new signal is sent
with zero with no timeout being effective immediately. This is necessary
to evaluate the persistency flag after the delay because it might have
changed in the meantime.
Effectively this means that it is possible to cancel the delayed
operation by calling TogglePersistent.
Diffstat (limited to 'src/Xmobar.hs')
-rw-r--r-- | src/Xmobar.hs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 79234d2..f531cb4 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -146,9 +146,9 @@ eventLoop tv xc@(XConf d _ w fs cfg) signal = do ncfg <- updateConfigPosition cfg reposWindow ncfg - Hide -> hide - Reveal -> reveal - Toggle -> toggle + Hide t -> hide (t*100*1000) + Reveal t -> reveal (t*100*1000) + Toggle t -> toggle (t*100*1000) TogglePersistent -> eventLoop tv xc { config = cfg { persistent = not $ persistent cfg } } signal @@ -156,16 +156,27 @@ eventLoop tv xc@(XConf d _ w fs cfg) signal = do where isPersistent = not $ persistent cfg - hide = when isPersistent (hideWindow d w) >> eventLoop tv xc signal + hide t | t == 0 = do + when isPersistent $ hideWindow d w + eventLoop tv xc signal + | otherwise = do + void $ forkIO + $ threadDelay t >> atomically (putTMVar signal $ Hide 0) + eventLoop tv xc signal - reveal = if isPersistent - then do + reveal t | t == 0 = + if isPersistent + then do r' <- repositionWin d w fs cfg showWindow d w eventLoop tv (XConf d r' w fs cfg) signal else eventLoop tv xc signal + | otherwise = do + void $ forkIO + $ threadDelay t >> atomically (putTMVar signal $ Reveal 0) + eventLoop tv xc signal - toggle = isMapped d w >>= \b -> if b then hide else reveal + toggle t = isMapped d w >>= \b -> if b then hide t else reveal t reposWindow rcfg = do r' <- repositionWin d w fs rcfg |