Make i3 compatible with the very latest xcb
This involves: • Compiling with xcb-util instead of xcb-{atom,aux} (they merged the libraries) • Not using xcb-{event,property} anymore (code removed upstream) • Not using the predefined WINDOW, CARDINEL, … atoms (removed upstream) • Using the new xcb_icccm_* data types/functions instead of just xcb_* (for example xcb_icccm_get_wm_hints instead of xcb_get_wm_hints) Also I refactored the atoms to use x-macros.
This commit is contained in:
176
src/handlers.c
176
src/handlers.c
@ -6,14 +6,19 @@
|
||||
*
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <xcb/xcb_atom.h>
|
||||
#include <xcb/randr.h>
|
||||
|
||||
#include <X11/XKBlib.h>
|
||||
|
||||
#include "all.h"
|
||||
|
||||
int randr_base = -1;
|
||||
|
||||
/* forward declaration for property_notify */
|
||||
static int property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom);
|
||||
|
||||
/* After mapping/unmapping windows, a notify event is generated. However, we don’t want it,
|
||||
since it’d trigger an infinite loop of switching between the different windows when
|
||||
changing workspaces */
|
||||
@ -59,6 +64,143 @@ static bool event_is_ignored(const int sequence) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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_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;
|
||||
}
|
||||
|
||||
/*
|
||||
* There was a key press. We compare this key code with our bindings table and pass
|
||||
* the bound action to parse_command().
|
||||
@ -627,10 +769,10 @@ int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *
|
||||
*/
|
||||
int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message_event_t *event) {
|
||||
LOG("ClientMessage for window 0x%08x\n", event->window);
|
||||
if (event->type == atoms[_NET_WM_STATE]) {
|
||||
if (event->format != 32 || event->data.data32[1] != atoms[_NET_WM_STATE_FULLSCREEN]) {
|
||||
if (event->type == A__NET_WM_STATE) {
|
||||
if (event->format != 32 || event->data.data32[1] != A__NET_WM_STATE_FULLSCREEN) {
|
||||
DLOG("atom in clientmessage is %d, fullscreen is %d\n",
|
||||
event->data.data32[1], atoms[_NET_WM_STATE_FULLSCREEN]);
|
||||
event->data.data32[1], A__NET_WM_STATE_FULLSCREEN);
|
||||
DLOG("not about fullscreen atom\n");
|
||||
return 0;
|
||||
}
|
||||
@ -693,17 +835,17 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
|
||||
|
||||
/* If the hints were already in this event, use them, if not, request them */
|
||||
if (reply != NULL)
|
||||
xcb_get_wm_size_hints_from_reply(&size_hints, reply);
|
||||
xcb_icccm_get_wm_size_hints_from_reply(&size_hints, reply);
|
||||
else
|
||||
xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, con->window->id), &size_hints, NULL);
|
||||
xcb_icccm_get_wm_normal_hints_reply(conn, xcb_icccm_get_wm_normal_hints_unchecked(conn, con->window->id), &size_hints, NULL);
|
||||
|
||||
if ((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) {
|
||||
if ((size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)) {
|
||||
// TODO: Minimum size is not yet implemented
|
||||
DLOG("Minimum size: %d (width) x %d (height)\n", size_hints.min_width, size_hints.min_height);
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
if ((size_hints.flags & XCB_SIZE_HINT_P_RESIZE_INC)) {
|
||||
if ((size_hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)) {
|
||||
if (size_hints.width_inc > 0 && size_hints.width_inc < 0xFFFF)
|
||||
if (con->width_increment != size_hints.width_inc) {
|
||||
con->width_increment = size_hints.width_inc;
|
||||
@ -724,10 +866,10 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
|
||||
/* base_width/height are the desired size of the window.
|
||||
We check if either the program-specified size or the program-specified
|
||||
min-size is available */
|
||||
if (size_hints.flags & XCB_SIZE_HINT_BASE_SIZE) {
|
||||
if (size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE) {
|
||||
base_width = size_hints.base_width;
|
||||
base_height = size_hints.base_height;
|
||||
} else if (size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE) {
|
||||
} else if (size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) {
|
||||
/* TODO: is this right? icccm says not */
|
||||
base_width = size_hints.min_width;
|
||||
base_height = size_hints.min_height;
|
||||
@ -742,7 +884,7 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
|
||||
}
|
||||
|
||||
/* If no aspect ratio was set or if it was invalid, we ignore the hints */
|
||||
if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
|
||||
if (!(size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT) ||
|
||||
(size_hints.min_aspect_num <= 0) ||
|
||||
(size_hints.min_aspect_den <= 0)) {
|
||||
goto render_and_return;
|
||||
@ -788,13 +930,13 @@ int handle_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t
|
||||
return 1;
|
||||
}
|
||||
|
||||
xcb_wm_hints_t hints;
|
||||
xcb_icccm_wm_hints_t hints;
|
||||
|
||||
if (reply != NULL) {
|
||||
if (!xcb_get_wm_hints_from_reply(&hints, reply))
|
||||
if (!xcb_icccm_get_wm_hints_from_reply(&hints, reply))
|
||||
return 1;
|
||||
} else {
|
||||
if (!xcb_get_wm_hints_reply(conn, xcb_get_wm_hints_unchecked(conn, con->window->id), &hints, NULL))
|
||||
if (!xcb_icccm_get_wm_hints_reply(conn, xcb_icccm_get_wm_hints_unchecked(conn, con->window->id), &hints, NULL))
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -804,7 +946,7 @@ int handle_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t
|
||||
}
|
||||
|
||||
/* Update the flag on the client directly */
|
||||
con->urgent = (xcb_wm_hints_get_urgency(&hints) != 0);
|
||||
con->urgent = (xcb_icccm_wm_hints_get_urgency(&hints) != 0);
|
||||
//CLIENT_LOG(con);
|
||||
LOG("Urgency flag changed to %d\n", con->urgent);
|
||||
|
||||
@ -841,7 +983,7 @@ int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_
|
||||
|
||||
if (prop == NULL) {
|
||||
prop = xcb_get_property_reply(conn, xcb_get_property_unchecked(conn,
|
||||
false, window, WM_TRANSIENT_FOR, WINDOW, 0, 32), NULL);
|
||||
false, window, A_WM_TRANSIENT_FOR, A_WINDOW, 0, 32), NULL);
|
||||
if (prop == NULL)
|
||||
return 1;
|
||||
}
|
||||
@ -872,7 +1014,7 @@ int handle_clientleader_change(void *data, xcb_connection_t *conn, uint8_t state
|
||||
|
||||
if (prop == NULL) {
|
||||
prop = xcb_get_property_reply(conn, xcb_get_property_unchecked(conn,
|
||||
false, window, WM_CLIENT_LEADER, WINDOW, 0, 32), NULL);
|
||||
false, window, A_WM_CLIENT_LEADER, A_WINDOW, 0, 32), NULL);
|
||||
if (prop == NULL)
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user