diff --git a/awesome.c b/awesome.c index 2c4caa82..db4221f1 100644 --- a/awesome.c +++ b/awesome.c @@ -637,6 +637,8 @@ main(int argc, char **argv) query = xcb_get_extension_data(globalconf.connection, &xcb_shape_id); globalconf.have_shape = query->present; + event_init(); + /* Allocate the key symbols */ globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); diff --git a/event.c b/event.c index b08ce2f8..f7cdb0af 100644 --- a/event.c +++ b/event.c @@ -976,49 +976,34 @@ void event_handle(xcb_generic_event_t *event) #undef EVENT } - static uint8_t randr_screen_change_notify = 0; - static uint8_t randr_output_change_notify = 0; - static uint8_t shape_notify = 0; - static uint8_t xkb_notify = 0; +#define EXTENSION_EVENT(base, offset, callback) \ + if (globalconf.event_base_ ## base != 0 \ + && response_type == globalconf.event_base_ ## base + (offset)) \ + callback((void *) event) + EXTENSION_EVENT(randr, XCB_RANDR_SCREEN_CHANGE_NOTIFY, event_handle_randr_screen_change_notify); + EXTENSION_EVENT(randr, XCB_RANDR_NOTIFY, event_handle_randr_output_change_notify); + EXTENSION_EVENT(shape, XCB_SHAPE_NOTIFY, event_handle_shape_notify); + EXTENSION_EVENT(xkb, 0, event_handle_xkb_notify); +#undef EXTENSION_EVENT +} - if(randr_screen_change_notify == 0 || randr_output_change_notify == 0) - { - /* check for randr extension */ - const xcb_query_extension_reply_t *randr_query; - randr_query = xcb_get_extension_data(globalconf.connection, &xcb_randr_id); - if(randr_query->present) { - xcb_randr_select_input(globalconf.connection, globalconf.screen->root, XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE); - randr_screen_change_notify = randr_query->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY; - randr_output_change_notify = randr_query->first_event + XCB_RANDR_NOTIFY; - } +void event_init(void) +{ + const xcb_query_extension_reply_t *reply; + + reply = xcb_get_extension_data(globalconf.connection, &xcb_randr_id); + if (reply && reply->present) { + xcb_randr_select_input(globalconf.connection, globalconf.screen->root, XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE); + globalconf.event_base_randr = reply->first_event; } - if(shape_notify == 0) - { - /* check for shape extension */ - const xcb_query_extension_reply_t *shape_query; - shape_query = xcb_get_extension_data(globalconf.connection, &xcb_shape_id); - if(shape_query->present) - shape_notify = shape_query->first_event + XCB_SHAPE_NOTIFY; - } + reply = xcb_get_extension_data(globalconf.connection, &xcb_shape_id); + if (reply && reply->present) + globalconf.event_base_shape = reply->first_event; - if(xkb_notify == 0) - { - /* check for xkb extension */ - const xcb_query_extension_reply_t *xkb_query; - xkb_query = xcb_get_extension_data(globalconf.connection, &xcb_xkb_id); - if(xkb_query->present) - xkb_notify = xkb_query->first_event; - } - - if (response_type == randr_screen_change_notify) - event_handle_randr_screen_change_notify((void *) event); - if (response_type == randr_output_change_notify) - event_handle_randr_output_change_notify((void *) event); - if (response_type == shape_notify) - event_handle_shape_notify((void *) event); - if (response_type == xkb_notify) - event_handle_xkb_notify((void *) event); + reply = xcb_get_extension_data(globalconf.connection, &xcb_xkb_id); + if (reply && reply->present) + globalconf.event_base_xkb = reply->first_event; } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/event.h b/event.h index f47add4b..1d471aa3 100644 --- a/event.h +++ b/event.h @@ -50,6 +50,7 @@ awesome_refresh(void) return xcb_flush(globalconf.connection); } +void event_init(void); void event_handle(xcb_generic_event_t *); void event_drawable_under_mouse(lua_State *, int); diff --git a/globalconf.h b/globalconf.h index be4a6535..dc407596 100644 --- a/globalconf.h +++ b/globalconf.h @@ -82,8 +82,6 @@ typedef struct screen_array_t screens; /** The primary screen, access through screen_get_primary() */ screen_t *primary_screen; - /** Do we have RandR 1.3 or newer? */ - bool have_randr_13; /** Root window key bindings */ key_array_t keys; /** Root window mouse bindings */ @@ -92,10 +90,15 @@ typedef struct xcb_atom_t selection_atom; /** Window owning the WM_Sn selection */ xcb_window_t selection_owner_window; + /** Do we have RandR 1.3 or newer? */ + bool have_randr_13; /** Check for XTest extension */ bool have_xtest; /** Check for SHAPE extension */ bool have_shape; + uint8_t event_base_shape; + uint8_t event_base_xkb; + uint8_t event_base_randr; /** Clients list */ client_array_t clients; /** Embedded windows */