]> git.sur5r.net Git - i3/i3lock/commitdiff
make event loop simpler (Thanks to Jamey Sharp)
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 20 Jul 2010 18:13:40 +0000 (20:13 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 20 Jul 2010 18:13:40 +0000 (20:13 +0200)
As explained in Jamey’s post on the XCB mailing list, the event
loop can/should be written in a more simple way than it was before
in xcb-event. See:
<AANLkTinhIM320wUjSeHkBTVk4ysBuiSZkvfs8pMLVykO@mail.gmail.com>
or
http://lists.freedesktop.org/archives/xcb/2010-July/006292.html

i3lock.c
xcb.c
xcb.h

index 0fa384c329ccf818de16be28068fe945e3a239cb..cb671d56838b3720f8036a8394b94236d9763bd6 100644 (file)
--- a/i3lock.c
+++ b/i3lock.c
@@ -324,7 +324,11 @@ int main(int argc, char *argv[]) {
         dpms_turn_off_screen(conn);
 
     while ((event = xcb_wait_for_event(conn))) {
-        int type = x_event_type(event);
+        if (event->response_type == 0)
+            errx(1, "XCB: Invalid event received");
+
+        /* Strip off the highest bit (set if the event is generated) */
+        int type = (event->response_type & 0x7F);
 
         if (type == XCB_EXPOSE) {
             handle_expose_event();
diff --git a/xcb.c b/xcb.c
index 2fdb841f13c7747aca274ea066fbff9983d6a69e..5627af1c09a7c0ae0f02e64abced53a8e3b32047 100644 (file)
--- a/xcb.c
+++ b/xcb.c
@@ -27,23 +27,6 @@ static uint32_t get_colorpixel(char *hex) {
     return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
 }       
 
-int x_event_type(xcb_generic_event_t *event) {
-    /* TODO: comment */
-    assert(event->response_type != 1);
-
-    if (event->response_type == 0) {
-        fprintf(stderr, "error\n");
-        exit(1);
-    }
-    int type = event->response_type;
-    assert(type < 256);
-    /* strip the highest bit (TODO: why?) */
-    type &= 0x7F;
-    assert(type >= 2);
-
-    return type;
-}
-
 xcb_visualtype_t *get_root_visual_type(xcb_screen_t *screen) {
     xcb_visualtype_t *visual_type = NULL;
     xcb_depth_iterator_t depth_iter;
diff --git a/xcb.h b/xcb.h
index 2790858f47ed1c9ac0df22bd3c019e393acdddbc..66590246ac0b1b5c8ce88a3ef79ae122234fe67e 100644 (file)
--- a/xcb.h
+++ b/xcb.h
@@ -3,7 +3,6 @@
 
 #include <xcb/xcb.h>
 
-int x_event_type(xcb_generic_event_t *event);
 xcb_visualtype_t *get_root_visual_type(xcb_screen_t *s);
 xcb_window_t open_fullscreen_window(xcb_connection_t *conn, xcb_screen_t *scr, char *color);
 void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen);