------------------------------------------------------------------------------- |-- Module : XMonad.Util.Timer-- Copyright : (c) Andrea Rossato and David Roundy 2007-- License : BSD-style (see xmonad/LICENSE)---- Maintainer : andrea.rossato@unibz.it-- Stability : unstable-- Portability : unportable---- A module for setting up timers-----------------------------------------------------------------------------moduleXMonad.Util.Timer(-- * Usage-- $usagestartTimer,handleTimer,TimerId)whereimportXMonadimportControl.ApplicativeimportControl.ConcurrentimportData.UniqueimportSystem.Posix.Process(forkProcess)-- $usage-- This module can be used to setup a timer to handle deferred events.-- See 'XMonad.Layout.ShowWName' for an usage example.typeTimerId=Int-- | Start a timer, which will send a ClientMessageEvent after some-- time (in seconds).startTimer::Rational->XTimerIdstartTimers=io$dou<-hashUnique<$>newUniqueforkProcess$dod<-openDisplay""rw<-rootWindowd$defaultScreendthreadDelay(fromEnum$s*1000000)a<-internAtomd"XMONAD_TIMER"FalseallocaXEvent$\e->dosetEventTypeeclientMessagesetClientMessageEventerwa32(fromIntegralu)currentTimesendEventdrwFalsestructureNotifyMaskesyncdFalsereturnu-- | Given a 'TimerId' and an 'Event', run an action when the 'Event'-- has been sent by the timer specified by the 'TimerId'handleTimer::TimerId->Event->X(Maybea)->X(Maybea)handleTimerti(ClientMessageEvent{ev_message_type=mt,ev_data=dt})action=dod<-asksdisplaya<-io$internAtomd"XMONAD_TIMER"Falseifmt==a&&dt/=[]&&fromIntegral(headdt)==tithenactionelsereturnNothinghandleTimer___=returnNothing