summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/X11/Events.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-11-25 23:43:41 +0000
committerjao <jao@gnu.org>2018-11-25 23:43:41 +0000
commit24c84e47177b6ebbe3df99db53220def6c0951ec (patch)
tree76ab584623118b7dde610c94639d44951cf83b6e /src/Xmobar/X11/Events.hs
parent54cf675f1299a74466950be240a708a762335d5d (diff)
downloadxmobar-24c84e47177b6ebbe3df99db53220def6c0951ec.tar.gz
xmobar-24c84e47177b6ebbe3df99db53220def6c0951ec.tar.bz2
Xmobar.System.Utils, Xmobar.X11.Events
Diffstat (limited to 'src/Xmobar/X11/Events.hs')
-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