summaryrefslogtreecommitdiff
path: root/src/safe_x11/safex11.c
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-22 02:58:41 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-22 02:58:41 -0300
commit5da38341bc54f24c8cad41f1b63405d8cc955fe7 (patch)
treedebe4dda2dd02cc23ed64b54df768a0f584938d2 /src/safe_x11/safex11.c
parenta21473f60c6cfad6335db3b0b45cdff23f8b3a89 (diff)
downloaddotwm-5da38341bc54f24c8cad41f1b63405d8cc955fe7.tar.gz
next_xevent don't block anymore!
Now the next_xevent (from the safex11) will not block forever. So we can listen the socket without doing some thread stuff.
Diffstat (limited to 'src/safe_x11/safex11.c')
-rw-r--r--src/safe_x11/safex11.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/safe_x11/safex11.c b/src/safe_x11/safex11.c
new file mode 100644
index 0000000..e4f87d8
--- /dev/null
+++ b/src/safe_x11/safex11.c
@@ -0,0 +1,32 @@
+#include "safex11.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xutil.h>
+
+int select_next_event(Display *display, int x11_fd, XEvent *retval)
+{
+ fd_set in_fds;
+ struct timeval tv;
+ XEvent ev;
+ /* check if there're some events on the queue first of all. */
+ if(XPending(display) > 0)
+ goto EVENT_QUEUED;
+
+ FD_ZERO(&in_fds);
+ FD_SET(x11_fd, &in_fds);
+
+ /* one second */
+ tv.tv_usec = 0;
+ tv.tv_sec = 1;
+
+ /* Wait for X Event or a Timer */
+ if(select(x11_fd+1, &in_fds, 0, 0, &tv))
+ goto EVENT_QUEUED;
+
+ return 0;
+
+EVENT_QUEUED:
+ XNextEvent(display, &ev);
+ *retval = ev;
+ return 1;
+}