Merge branch 'randr-stuff'

This commit is contained in:
Uli Schlachter 2016-04-10 11:46:06 +02:00
commit cf9e45e5d9
4 changed files with 50 additions and 57 deletions

View File

@ -637,6 +637,8 @@ main(int argc, char **argv)
query = xcb_get_extension_data(globalconf.connection, &xcb_shape_id); query = xcb_get_extension_data(globalconf.connection, &xcb_shape_id);
globalconf.have_shape = query->present; globalconf.have_shape = query->present;
event_init();
/* Allocate the key symbols */ /* Allocate the key symbols */
globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection); globalconf.keysyms = xcb_key_symbols_alloc(globalconf.connection);

97
event.c
View File

@ -397,13 +397,19 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev)
static void static void
event_handle_configurenotify(xcb_configure_notify_event_t *ev) event_handle_configurenotify(xcb_configure_notify_event_t *ev)
{ {
const xcb_screen_t *screen = globalconf.screen; xcb_screen_t *screen = globalconf.screen;
if(ev->window == screen->root if(ev->window == screen->root
&& (ev->width != screen->width_in_pixels && (ev->width != screen->width_in_pixels
|| ev->height != screen->height_in_pixels)) || ev->height != screen->height_in_pixels))
/* it's not that we panic, but restart */ /* it's not that we panic, but restart */
awesome_restart(); awesome_restart();
/* Copy what XRRUpdateConfiguration() would do: Update the configuration */
if(ev->window == screen->root) {
screen->width_in_pixels = ev->width;
screen->height_in_pixels = ev->height;
}
} }
/** The destroy notify event handler. /** The destroy notify event handler.
@ -765,22 +771,18 @@ event_handle_unmapnotify(xcb_unmap_notify_event_t *ev)
static void static void
event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t *ev) event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t *ev)
{ {
/* Code of XRRUpdateConfiguration Xlib function ported to XCB /* Ignore events for other roots (do we get them at all?) */
* (only the code relevant to RRScreenChangeNotify) as the latter if (ev->root != globalconf.screen->root)
* doesn't provide this kind of function */ return;
if(ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270))
xcb_randr_set_screen_size(globalconf.connection, ev->root, ev->height, ev->width,
ev->mheight, ev->mwidth);
else
xcb_randr_set_screen_size(globalconf.connection, ev->root, ev->width, ev->height,
ev->mwidth, ev->mheight);
/* XRRUpdateConfiguration also executes the following instruction /* Do (part of) what XRRUpdateConfiguration() would do (update our state) */
* but it's not useful because SubpixelOrder is not used at all at if (ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270)) {
* the moment globalconf.screen->width_in_pixels = ev->height;
* globalconf.screen->height_in_pixels = ev->width;
* XRenderSetSubpixelOrder(dpy, snum, scevent->subpixel_order); } else {
*/ globalconf.screen->width_in_pixels = ev->width;
globalconf.screen->height_in_pixels = ev->height;
}
awesome_restart(); awesome_restart();
} }
@ -976,49 +978,34 @@ void event_handle(xcb_generic_event_t *event)
#undef EVENT #undef EVENT
} }
static uint8_t randr_screen_change_notify = 0; #define EXTENSION_EVENT(base, offset, callback) \
static uint8_t randr_output_change_notify = 0; if (globalconf.event_base_ ## base != 0 \
static uint8_t shape_notify = 0; && response_type == globalconf.event_base_ ## base + (offset)) \
static uint8_t xkb_notify = 0; 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) void event_init(void)
{ {
/* check for randr extension */ const xcb_query_extension_reply_t *reply;
const xcb_query_extension_reply_t *randr_query;
randr_query = xcb_get_extension_data(globalconf.connection, &xcb_randr_id); reply = xcb_get_extension_data(globalconf.connection, &xcb_randr_id);
if(randr_query->present) { if (reply && reply->present) {
xcb_randr_select_input(globalconf.connection, globalconf.screen->root, XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE); 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; globalconf.event_base_randr = reply->first_event;
randr_output_change_notify = randr_query->first_event + XCB_RANDR_NOTIFY;
}
} }
if(shape_notify == 0) reply = xcb_get_extension_data(globalconf.connection, &xcb_shape_id);
{ if (reply && reply->present)
/* check for shape extension */ globalconf.event_base_shape = reply->first_event;
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;
}
if(xkb_notify == 0) reply = xcb_get_extension_data(globalconf.connection, &xcb_xkb_id);
{ if (reply && reply->present)
/* check for xkb extension */ globalconf.event_base_xkb = reply->first_event;
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);
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -50,6 +50,7 @@ awesome_refresh(void)
return xcb_flush(globalconf.connection); return xcb_flush(globalconf.connection);
} }
void event_init(void);
void event_handle(xcb_generic_event_t *); void event_handle(xcb_generic_event_t *);
void event_drawable_under_mouse(lua_State *, int); void event_drawable_under_mouse(lua_State *, int);

View File

@ -82,8 +82,6 @@ typedef struct
screen_array_t screens; screen_array_t screens;
/** The primary screen, access through screen_get_primary() */ /** The primary screen, access through screen_get_primary() */
screen_t *primary_screen; screen_t *primary_screen;
/** Do we have RandR 1.3 or newer? */
bool have_randr_13;
/** Root window key bindings */ /** Root window key bindings */
key_array_t keys; key_array_t keys;
/** Root window mouse bindings */ /** Root window mouse bindings */
@ -92,10 +90,15 @@ typedef struct
xcb_atom_t selection_atom; xcb_atom_t selection_atom;
/** Window owning the WM_Sn selection */ /** Window owning the WM_Sn selection */
xcb_window_t selection_owner_window; xcb_window_t selection_owner_window;
/** Do we have RandR 1.3 or newer? */
bool have_randr_13;
/** Check for XTest extension */ /** Check for XTest extension */
bool have_xtest; bool have_xtest;
/** Check for SHAPE extension */ /** Check for SHAPE extension */
bool have_shape; bool have_shape;
uint8_t event_base_shape;
uint8_t event_base_xkb;
uint8_t event_base_randr;
/** Clients list */ /** Clients list */
client_array_t clients; client_array_t clients;
/** Embedded windows */ /** Embedded windows */