-/*
- * Takes an xcb_generic_event_t and calls the appropriate handler, based on the
- * event type.
- *
- */
-void handle_event(int type, xcb_generic_event_t *event) {
- /* XXX: remove the NULL and conn parameters as soon as this version of libxcb is required */
-
- if (randr_base > -1 &&
- type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
- handle_screen_change(NULL, conn, event);
- return;
- }
-
- switch (type) {
- case XCB_KEY_PRESS:
- handle_key_press(NULL, conn, (xcb_key_press_event_t*)event);
- break;
-
- case XCB_BUTTON_PRESS:
- handle_button_press(NULL, conn, (xcb_button_press_event_t*)event);
- break;
-
- case XCB_MAP_REQUEST:
- handle_map_request(NULL, conn, (xcb_map_request_event_t*)event);
- break;
-
- case XCB_UNMAP_NOTIFY:
- handle_unmap_notify_event(NULL, conn, (xcb_unmap_notify_event_t*)event);
- break;
-
- case XCB_DESTROY_NOTIFY:
- handle_destroy_notify_event(NULL, conn, (xcb_destroy_notify_event_t*)event);
- break;
-
- case XCB_EXPOSE:
- handle_expose_event(NULL, conn, (xcb_expose_event_t*)event);
- break;
-
- case XCB_MOTION_NOTIFY:
- handle_motion_notify(NULL, conn, (xcb_motion_notify_event_t*)event);
- break;
-
- /* Enter window = user moved his mouse over the window */
- case XCB_ENTER_NOTIFY:
- handle_enter_notify(NULL, conn, (xcb_enter_notify_event_t*)event);
- break;
-
- /* Client message are sent to the root window. The only interesting
- * client message for us is _NET_WM_STATE, we honour
- * _NET_WM_STATE_FULLSCREEN */
- case XCB_CLIENT_MESSAGE:
- handle_client_message(NULL, conn, (xcb_client_message_event_t*)event);
- break;
-
- /* Configure request = window tried to change size on its own */
- case XCB_CONFIGURE_REQUEST:
- handle_configure_request(NULL, conn, (xcb_configure_request_event_t*)event);
- break;
-
- /* Mapping notify = keyboard mapping changed (Xmodmap), re-grab bindings */
- case XCB_MAPPING_NOTIFY:
- handle_mapping_notify(NULL, conn, (xcb_mapping_notify_event_t*)event);
- break;
-
- case XCB_FOCUS_IN:
- handle_focus_in(NULL, conn, (xcb_focus_in_event_t*)event);
- break;
-
- case XCB_PROPERTY_NOTIFY:
- DLOG("Property notify\n");
- xcb_property_notify_event_t *e = (xcb_property_notify_event_t*)event;
- property_notify(e->state, e->window, e->atom);
- break;
-
- default:
- DLOG("Unhandled event of type %d\n", type);
- break;
- }
-}
-
-typedef int (*cb_property_handler_t)(void *data, xcb_connection_t *c, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *property);
-
-struct property_handler_t {
- xcb_atom_t atom;
- uint32_t long_len;
- cb_property_handler_t cb;
-};
-
-static struct property_handler_t property_handlers[] = {
- { 0, 128, handle_windowname_change },
- { 0, UINT_MAX, handle_hints },
- { 0, 128, handle_windowname_change_legacy },
- { 0, UINT_MAX, handle_normal_hints },
- { 0, UINT_MAX, handle_clientleader_change },
- { 0, UINT_MAX, handle_transient_for }
-};
-#define NUM_HANDLERS (sizeof(property_handlers) / sizeof(struct property_handler_t))
-
-/*
- * Sets the appropriate atoms for the property handlers after the atoms were
- * received from X11
- *
- */
-void property_handlers_init() {
- property_handlers[0].atom = A__NET_WM_NAME;
- property_handlers[1].atom = A_WM_HINTS;
- property_handlers[2].atom = A_WM_NAME;
- property_handlers[3].atom = A_WM_NORMAL_HINTS;
- property_handlers[4].atom = A_WM_CLIENT_LEADER;
- property_handlers[5].atom = A_WM_TRANSIENT_FOR;
-}
-
-static int property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom) {
- struct property_handler_t *handler = NULL;
- xcb_get_property_reply_t *propr = NULL;
- int ret;
-
- for (int c = 0; c < sizeof(property_handlers) / sizeof(struct property_handler_t); c++) {
- if (property_handlers[c].atom != atom)
- continue;
-
- handler = &property_handlers[c];
- break;
- }
-
- if (handler == NULL) {
- DLOG("Unhandled property notify for atom %d (0x%08x)\n", atom, atom);
- return 0;
- }
-
- if (state != XCB_PROPERTY_DELETE) {
- xcb_get_property_cookie_t cookie = xcb_get_property(conn, 0, window, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, handler->long_len);
- propr = xcb_get_property_reply(conn, cookie, 0);
- }
-
- ret = handler->cb(NULL, conn, state, window, atom, propr);
- FREE(propr);
- return ret;
-}