Convert XSelectInput() to XCB

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Uli Schlachter 2018-10-03 14:34:24 +02:00 committed by Yuxuan Shui
parent 1b1b3456bc
commit 2da0ecdf66
3 changed files with 35 additions and 26 deletions

View File

@ -2019,9 +2019,10 @@ map_win(session_t *ps, Window id) {
cxinerama_win_upd_scr(ps, w); cxinerama_win_upd_scr(ps, w);
// Call XSelectInput() before reading properties so that no property // Set window event mask before reading properties so that no property
// changes are lost // changes are lost
XSelectInput(ps->dpy, id, determine_evmask(ps, id, WIN_EVMODE_FRAME)); xcb_change_window_attributes(c, id, XCB_CW_EVENT_MASK,
(const uint32_t[]) { determine_evmask(ps, id, WIN_EVMODE_FRAME) });
// Notify compton when the shape of a window changes // Notify compton when the shape of a window changes
if (ps->shape_exists) { if (ps->shape_exists) {
@ -2527,14 +2528,15 @@ opts_init_track_focus(session_t *ps) {
if (ps->o.track_focus) if (ps->o.track_focus)
return; return;
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
ps->o.track_focus = true; ps->o.track_focus = true;
if (!ps->o.use_ewmh_active_win) { if (!ps->o.use_ewmh_active_win) {
// Start listening to FocusChange events // Start listening to FocusChange events
for (win *w = ps->list; w; w = w->next) for (win *w = ps->list; w; w = w->next)
if (IsViewable == w->a.map_state) if (IsViewable == w->a.map_state)
XSelectInput(ps->dpy, w->id, xcb_change_window_attributes(c, w->id, XCB_CW_EVENT_MASK,
determine_evmask(ps, w->id, WIN_EVMODE_FRAME)); (const uint32_t[]) { determine_evmask(ps, w->id, WIN_EVMODE_FRAME) });
} }
// Recheck focus // Recheck focus
@ -2750,11 +2752,13 @@ ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t *ev) {
if (ev->parent == ps->root) { if (ev->parent == ps->root) {
add_win(ps, ev->window, 0); add_win(ps, ev->window, 0);
} else { } else {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
destroy_win(ps, ev->window); destroy_win(ps, ev->window);
// Reset event mask in case something wrong happens // Reset event mask in case something wrong happens
XSelectInput(ps->dpy, ev->window, xcb_change_window_attributes(c, ev->window, XCB_CW_EVENT_MASK,
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN)); (const uint32_t[]) { determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) });
// Check if the window is an undetected client window // Check if the window is an undetected client window
// Firstly, check if it's a known client window // Firstly, check if it's a known client window
@ -2773,9 +2777,8 @@ ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t *ev) {
} }
// Otherwise, watch for WM_STATE on it // Otherwise, watch for WM_STATE on it
else { else {
XSelectInput(ps->dpy, ev->window, xcb_change_window_attributes(c, ev->window, XCB_CW_EVENT_MASK, (const uint32_t[]) {
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) | PropertyChangeMask });
| PropertyChangeMask);
} }
} }
} }
@ -2833,6 +2836,7 @@ update_ewmh_active_win(session_t *ps) {
inline static void inline static void
ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) { ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
#ifdef DEBUG_EVENTS #ifdef DEBUG_EVENTS
{ {
// Print out changed atom // Print out changed atom
@ -2866,8 +2870,8 @@ ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) {
// Check whether it could be a client window // Check whether it could be a client window
if (!find_toplevel(ps, ev->window)) { if (!find_toplevel(ps, ev->window)) {
// Reset event mask anyway // Reset event mask anyway
XSelectInput(ps->dpy, ev->window, xcb_change_window_attributes(c, ev->window, XCB_CW_EVENT_MASK, (const uint32_t[]) {
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN)); determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) });
win *w_top = find_toplevel2(ps, ev->window); win *w_top = find_toplevel2(ps, ev->window);
// Initialize client_win as early as possible // Initialize client_win as early as possible
@ -4548,7 +4552,8 @@ init_overlay(session_t *ps) {
} }
// Listen to Expose events on the overlay // Listen to Expose events on the overlay
XSelectInput(ps->dpy, ps->overlay, ExposureMask); xcb_change_window_attributes(c, ps->overlay, XCB_CW_EVENT_MASK,
(const uint32_t[]) { XCB_EVENT_MASK_EXPOSURE });
// Retrieve DamageNotify on root window if we are painting on an // Retrieve DamageNotify on root window if we are painting on an
// overlay // overlay
@ -5104,11 +5109,11 @@ session_init(session_t *ps_old, int argc, char **argv) {
// Start listening to events on root earlier to catch all possible // Start listening to events on root earlier to catch all possible
// root geometry changes // root geometry changes
XSelectInput(ps->dpy, ps->root, xcb_change_window_attributes(c, ps->root, XCB_CW_EVENT_MASK, (const uint32_t[]) {
SubstructureNotifyMask XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
| ExposureMask | XCB_EVENT_MASK_EXPOSURE
| StructureNotifyMask | XCB_EVENT_MASK_STRUCTURE_NOTIFY
| PropertyChangeMask); | XCB_EVENT_MASK_PROPERTY_CHANGE });
XFlush(ps->dpy); XFlush(ps->dpy);
ps->root_width = DisplayWidth(ps->dpy, ps->scr); ps->root_width = DisplayWidth(ps->dpy, ps->scr);
@ -5468,7 +5473,8 @@ session_destroy(session_t *ps) {
redir_stop(ps); redir_stop(ps);
// Stop listening to events on root window // Stop listening to events on root window
XSelectInput(ps->dpy, ps->root, 0); xcb_change_window_attributes(c, ps->root, XCB_CW_EVENT_MASK,
(const uint32_t[]) { 0 });
#ifdef CONFIG_DBUS #ifdef CONFIG_DBUS
// Kill DBus connection // Kill DBus connection

View File

@ -312,12 +312,12 @@ win_ev_stop(session_t *ps, win *w) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy); xcb_connection_t *c = XGetXCBConnection(ps->dpy);
// Will get BadWindow if the window is destroyed // Will get BadWindow if the window is destroyed
set_ignore_next(ps); set_ignore_cookie(ps,
XSelectInput(ps->dpy, w->id, 0); xcb_change_window_attributes(c, w->id, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 }));
if (w->client_win) { if (w->client_win) {
set_ignore_next(ps); set_ignore_cookie(ps,
XSelectInput(ps->dpy, w->client_win, 0); xcb_change_window_attributes(c, w->client_win, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 }));
} }
if (ps->shape_exists) { if (ps->shape_exists) {

View File

@ -639,8 +639,9 @@ void win_mark_client(session_t *ps, win *w, Window client) {
if (IsViewable != w->a.map_state) if (IsViewable != w->a.map_state)
return; return;
XSelectInput(ps->dpy, client, xcb_connection_t *c = XGetXCBConnection(ps->dpy);
determine_evmask(ps, client, WIN_EVMODE_CLIENT)); xcb_change_window_attributes(c, client, XCB_CW_EVENT_MASK,
(const uint32_t[]) { determine_evmask(ps, client, WIN_EVMODE_CLIENT) });
// Make sure the XSelectInput() requests are sent // Make sure the XSelectInput() requests are sent
XFlush(ps->dpy); XFlush(ps->dpy);
@ -676,13 +677,15 @@ void win_mark_client(session_t *ps, win *w, Window client) {
* @param w struct _win of the parent window * @param w struct _win of the parent window
*/ */
void win_unmark_client(session_t *ps, win *w) { void win_unmark_client(session_t *ps, win *w) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
Window client = w->client_win; Window client = w->client_win;
w->client_win = None; w->client_win = None;
// Recheck event mask // Recheck event mask
XSelectInput(ps->dpy, client, xcb_change_window_attributes(c, client, XCB_CW_EVENT_MASK,
determine_evmask(ps, client, WIN_EVMODE_UNKNOWN)); (const uint32_t[]) { determine_evmask(ps, client, WIN_EVMODE_UNKNOWN) });
} }
/** /**