From 071794d33443ff76d85be035394103fc8bf48e98 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 25 Nov 2018 01:40:25 +0000 Subject: Wee refactoring --- src/lib/Xmobar/Utils.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/lib/Xmobar/Utils.hs') diff --git a/src/lib/Xmobar/Utils.hs b/src/lib/Xmobar/Utils.hs index ce8c4ad..eeb03f6 100644 --- a/src/lib/Xmobar/Utils.hs +++ b/src/lib/Xmobar/Utils.hs @@ -17,15 +17,21 @@ ------------------------------------------------------------------------------ -module Xmobar.Utils (expandHome, changeLoop, safeHead, hGetLineSafe) where +module Xmobar.Utils (expandHome, changeLoop, safeHead, hGetLineSafe, nextEvent') +where import Control.Monad +import Control.Concurrent import Control.Concurrent.STM +import System.Posix.Types (Fd(..)) import System.Environment import System.FilePath import System.IO +import Graphics.X11.Xlib ( + Display(..), XEventPtr, nextEvent, pending, connectionNumber) + #if defined XFT || defined UTF8 import qualified System.IO as S (hGetLine) #endif @@ -55,3 +61,15 @@ changeLoop s f = atomically s >>= go safeHead :: [a] -> Maybe a safeHead [] = Nothing safeHead (x:_) = Just x + +-- | A version of nextEvent that does not block in foreign calls. +nextEvent' :: Display -> XEventPtr -> IO () +nextEvent' d p = do + pend <- pending d + if pend /= 0 + then nextEvent d p + else do + threadWaitRead (Fd fd) + nextEvent' d p + where + fd = connectionNumber d -- cgit v1.2.3