summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/X11
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xmobar/X11')
-rw-r--r--src/Xmobar/X11/Events.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Xmobar/X11/Events.hs b/src/Xmobar/X11/Events.hs
new file mode 100644
index 0000000..4334f6b
--- /dev/null
+++ b/src/Xmobar/X11/Events.hs
@@ -0,0 +1,36 @@
+------------------------------------------------------------------------------
+-- |
+-- Module: Xmobar.X11.Events
+-- Copyright: (c) 2018 Jose Antonio Ortega Ruiz
+-- License: BSD3-style (see LICENSE)
+--
+-- Maintainer: jao@gnu.org
+-- Stability: unstable
+-- Portability: portable
+-- Created: Sun Nov 25, 2018 23:24
+--
+--
+-- Utilities or event handling
+--
+------------------------------------------------------------------------------
+
+
+module Xmobar.X11.Events(nextEvent') where
+
+import Control.Concurrent
+import System.Posix.Types (Fd(..))
+
+import Graphics.X11.Xlib (
+ Display(..), XEventPtr, nextEvent, pending, connectionNumber)
+
+-- | 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