aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Util/Timer.hs
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@unibz.it>2008-01-14 22:11:14 +0100
committerAndrea Rossato <andrea.rossato@unibz.it>2008-01-14 22:11:14 +0100
commit5c199b8eec76fdc4bb697cf8f0be263cac6ebed7 (patch)
treec2759d1f45a026c0e4bf99d2ff3bffb340ede36e /XMonad/Util/Timer.hs
parent672132c833ff5511c3f3b31cb9b4a9e1adcacaf8 (diff)
downloadXMonadContrib-5c199b8eec76fdc4bb697cf8f0be263cac6ebed7.tar.gz
XMonadContrib-5c199b8eec76fdc4bb697cf8f0be263cac6ebed7.tar.xz
XMonadContrib-5c199b8eec76fdc4bb697cf8f0be263cac6ebed7.zip
Timer: some code cleanup
darcs-hash:20080114211114-32816-d08eb16da558f534ae7016d95f25ed559871541c.gz
Diffstat (limited to 'XMonad/Util/Timer.hs')
-rw-r--r--XMonad/Util/Timer.hs16
1 files changed, 7 insertions, 9 deletions
diff --git a/XMonad/Util/Timer.hs b/XMonad/Util/Timer.hs
index 8d5c2f7..8d21030 100644
--- a/XMonad/Util/Timer.hs
+++ b/XMonad/Util/Timer.hs
@@ -23,7 +23,6 @@ import XMonad
import Control.Applicative
import Control.Concurrent
import Data.Unique
-import System.Environment
-- $usage
-- This module can be used to setup a timer to handle deferred events.
@@ -35,18 +34,17 @@ type TimerId = Int
-- time (in seconds).
startTimer :: Rational -> X TimerId
startTimer s = io $ do
- dpy <- catch (getEnv "DISPLAY") (const $ return [])
- d <- openDisplay dpy
- rw <- rootWindow d $ defaultScreen d
u <- hashUnique <$> newUnique
doubleFork $ do
- threadDelay (fromEnum $ s * 1000000)
- a <- internAtom d "XMONAD_TIMER" False
- allocaXEvent $ \e -> do
+ d <- openDisplay ""
+ rw <- rootWindow d $ defaultScreen d
+ threadDelay (fromEnum $ s * 1000000)
+ a <- internAtom d "XMONAD_TIMER" False
+ allocaXEvent $ \e -> do
setEventType e clientMessage
setClientMessageEvent e rw a 32 (fromIntegral u) currentTime
sendEvent d rw False structureNotifyMask e
- sync d False
+ sync d False
return u
-- | Given a 'TimerId' and an 'Event', run an action when the 'Event'
@@ -55,7 +53,7 @@ handleTimer :: TimerId -> Event -> X (Maybe a) -> X (Maybe a)
handleTimer ti (ClientMessageEvent {ev_message_type = mt, ev_data = dt}) action = do
d <- asks display
a <- io $ internAtom d "XMONAD_TIMER" False
- if dt /= [] && fromIntegral (head dt) == ti && mt == a
+ if mt == a && dt /= [] && fromIntegral (head dt) == ti
then action
else return Nothing
handleTimer _ _ _ = return Nothing