Switch to libev for the event loop to build a base for IPC stuff. Please test!

This commit is contained in:
Michael Stapelberg 2009-06-01 20:59:40 +02:00
parent e689be983b
commit 553db28664
3 changed files with 47 additions and 3 deletions

View File

@ -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)

2
debian/control vendored
View 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/

View 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 dont 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 xcbs 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;