From: Michael Stapelberg Date: Tue, 20 Jul 2010 18:13:40 +0000 (+0200) Subject: make event loop simpler (Thanks to Jamey Sharp) X-Git-Tag: 2.0~11 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9d19a8bb53d7285ba352004e47e76474f20ab7c2;p=i3%2Fi3lock make event loop simpler (Thanks to Jamey Sharp) 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: or http://lists.freedesktop.org/archives/xcb/2010-July/006292.html --- diff --git a/i3lock.c b/i3lock.c index 0fa384c..cb671d5 100644 --- 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 2fdb841..5627af1 100644 --- 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 2790858..6659024 100644 --- a/xcb.h +++ b/xcb.h @@ -3,7 +3,6 @@ #include -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);