]> git.sur5r.net Git - i3/i3/commitdiff
Switch to libev for the event loop to build a base for IPC stuff. Please test!
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 1 Jun 2009 18:59:40 +0000 (20:59 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 1 Jun 2009 18:59:40 +0000 (20:59 +0200)
Makefile
debian/control
src/mainx.c

index 9f82b1a9ffb5815d9ee6dd0756fa3985730d5b6f..a42099d47eb01a02f3ee7a250045696789488c55 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,7 @@ LDFLAGS += -lxcb-aux
 LDFLAGS += -lxcb-icccm
 LDFLAGS += -lxcb-xinerama
 LDFLAGS += -lX11
+LDFLAGS += -lev
 LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
 
 ifeq ($(UNAME),NetBSD)
index e0807987802586ece877b2780ff1be0bc7e659eb..63997e86177df478db087adebe2fa99a954f1874 100644 (file)
@@ -3,7 +3,7 @@ Section: utils
 Priority: optional
 Maintainer: Michael Stapelberg <michael@stapelberg.de>
 DM-Upload-Allowed: yes
-Build-Depends: debhelper (>= 5), libx11-dev, libxcb-aux0-dev (>= 0.3.3), libxcb-keysyms1-dev, libxcb-xinerama0-dev (>= 1.1), libxcb-event1-dev (>= 0.3.3), libxcb-property1-dev (>= 0.3.3), libxcb-atom1-dev (>= 0.3.3), libxcb-icccm1-dev (>= 0.3.3), asciidoc (>= 8.4.4-1), xmlto, docbook-xml, pkg-config
+Build-Depends: debhelper (>= 5), libx11-dev, libxcb-aux0-dev (>= 0.3.3), libxcb-keysyms1-dev, libxcb-xinerama0-dev (>= 1.1), libxcb-event1-dev (>= 0.3.3), libxcb-property1-dev (>= 0.3.3), libxcb-atom1-dev (>= 0.3.3), libxcb-icccm1-dev (>= 0.3.3), asciidoc (>= 8.4.4-1), xmlto, docbook-xml, pkg-config, libev-dev
 Standards-Version: 3.8.0
 Homepage: http://i3.zekjur.net/
 
index 79a21e144dac7f610d428eda345bb0eca069f050..5de87700076d3904fe744c1bc19ac780ecb7049b 100644 (file)
@@ -31,6 +31,8 @@
 #include <xcb/xcb_icccm.h>
 #include <xcb/xinerama.h>
 
+#include <ev.h>
+
 #include "config.h"
 #include "data.h"
 #include "debug.h"
@@ -69,6 +71,34 @@ xcb_atom_t atoms[NUM_ATOMS];
 
 int num_screens = 0;
 
+/*
+ * Callback for activity on the connection to the X server
+ *
+ */
+static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
+        xcb_generic_event_t *event;
+
+        /* When an event is available… */
+        while ((event = xcb_poll_for_event(evenths.c)) != NULL) {
+                /* …we handle all events in a row: */
+                do {
+                        xcb_event_handle(&evenths, event);
+                        xcb_aux_sync(evenths.c);
+                        free(event);
+                } while ((event = xcb_poll_for_event(evenths.c)));
+
+                /* Make sure all replies are handled/discarded */
+                xcb_aux_sync(evenths.c);
+
+                /* Afterwards, there may be new events available which would
+                 * not trigger the select() (libev) immediately, so we check
+                 * again (and don’t bail out of the loop). */
+        }
+
+        /* Make sure all replies are handled/discarded */
+        xcb_aux_sync(evenths.c);
+}
+
 int main(int argc, char *argv[], char *env[]) {
         int i, screens, opt;
         char *override_configpath = NULL;
@@ -307,8 +337,21 @@ int main(int argc, char *argv[], char *env[]) {
                 c_ws = &workspaces[screen->current_workspace];
         }
 
-        /* Enter xcb’s event handler */
-        xcb_event_wait_for_event_loop(&evenths);
+
+        /* Initialize event loop using libev */
+        struct ev_loop *loop = ev_default_loop(0);
+        if (loop == NULL)
+                die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
+
+        ev_io xcb_watcher;
+        ev_io_init(&xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
+
+        /* Call the handler to work all events which arrived before the libev-stuff was set up */
+        xcb_got_event(NULL, &xcb_watcher, 0);
+
+        /* Enter the libev eventloop */
+        ev_io_start(loop, &xcb_watcher);
+        ev_loop(loop, 0);
 
         /* not reached */
         return 0;