summaryrefslogtreecommitdiffhomepage
path: root/src/lib/Xmobar/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Xmobar/Utils.hs')
-rw-r--r--src/lib/Xmobar/Utils.hs20
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