diff options
author | jao <jao@gnu.org> | 2018-11-25 01:40:25 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2018-11-25 01:40:25 +0000 |
commit | 071794d33443ff76d85be035394103fc8bf48e98 (patch) | |
tree | af709ba185ca14eefaf1dca66e678f529990ef38 /src/lib/Xmobar/Utils.hs | |
parent | 0b7b43ef83a2ab6fd894c20e028b9d69372c7266 (diff) | |
download | xmobar-071794d33443ff76d85be035394103fc8bf48e98.tar.gz xmobar-071794d33443ff76d85be035394103fc8bf48e98.tar.bz2 |
Wee refactoring
Diffstat (limited to 'src/lib/Xmobar/Utils.hs')
-rw-r--r-- | src/lib/Xmobar/Utils.hs | 20 |
1 files changed, 19 insertions, 1 deletions
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 |