diff options
author | Michael Cardell Widerkrantz <mc@hack.org> | 2010-07-21 07:55:00 +0200 |
---|---|---|
committer | Michael Cardell Widerkrantz <mc@hack.org> | 2010-07-21 07:55:00 +0200 |
commit | 06964729c8774a01ed2308c29719ff51300b7446 (patch) | |
tree | 68031ab9729af6baa51d86f499c6410c3e68b5c9 | |
parent | 4fad7769e43c529030b4e755a1e8c9eb61f368b8 (diff) | |
download | mcwm-06964729c8774a01ed2308c29719ff51300b7446.zip |
Use xcb_poll_for_event() and block on select() instead of
xcb_wait_for_event() so we can react on signals right away instead of
waiting for the next event.
-rw-r--r-- | mcwm.c | 41 |
1 files changed, 38 insertions, 3 deletions
@@ -33,6 +33,7 @@ #include <sys/types.h> #include <sys/wait.h> +#include <sys/select.h> #include <xcb/xcb.h> #include <xcb/xcb_keysyms.h> @@ -2147,14 +2148,48 @@ void events(void) int mode = 0; /* Internal mode. */ int16_t mode_x; int16_t mode_y; + int fd; + fd_set in; + int found; + fd = xcb_get_file_descriptor(conn); + for (exitcode = 0; 0 == exitcode;) { - ev = xcb_wait_for_event(conn); + FD_ZERO(&in); + FD_SET(fd, &in); + + /* + * Check for events, again and again. When poll returns NULL, + * we block on select() until the event file descriptor gets + * readable again. + * + * We do it this way instead of xcb_wait_for_event() since + * select() will return if we we're interrupted by a signal. + * We like that. + */ + ev = xcb_poll_for_event(conn); if (NULL == ev) { - fprintf(stderr, "mcwm: Couldn't get event. Exiting...\n"); - exit(1); + found = select(fd + 1, &in, NULL, NULL, NULL); + if (-1 == found) + { + if (EINTR != errno) + { + fprintf(stderr, "mcwm: select failed."); + die(1); + } + else + { + /* We received a signal. Goto start of loop. */ + continue; + } + } + else + { + /* We found more events. Goto start of loop. */ + continue; + } } #ifdef DEBUG |