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);
// Call XSelectInput() before reading properties so that no property
// Set window event mask before reading properties so that no property
// 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
if (ps->shape_exists) {
@ -2527,14 +2528,15 @@ opts_init_track_focus(session_t *ps) {
if (ps->o.track_focus)
return;
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
ps->o.track_focus = true;
if (!ps->o.use_ewmh_active_win) {
// Start listening to FocusChange events
for (win *w = ps->list; w; w = w->next)
if (IsViewable == w->a.map_state)
XSelectInput(ps->dpy, w->id,
determine_evmask(ps, w->id, WIN_EVMODE_FRAME));
xcb_change_window_attributes(c, w->id, XCB_CW_EVENT_MASK,
(const uint32_t[]) { determine_evmask(ps, w->id, WIN_EVMODE_FRAME) });
}
// Recheck focus
@ -2750,11 +2752,13 @@ ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t *ev) {
if (ev->parent == ps->root) {
add_win(ps, ev->window, 0);
} else {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
destroy_win(ps, ev->window);
// Reset event mask in case something wrong happens
XSelectInput(ps->dpy, ev->window,
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN));
xcb_change_window_attributes(c, ev->window, XCB_CW_EVENT_MASK,
(const uint32_t[]) { determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) });
// Check if the window is an undetected 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
else {
XSelectInput(ps->dpy, ev->window,
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN)
| PropertyChangeMask);
xcb_change_window_attributes(c, ev->window, XCB_CW_EVENT_MASK, (const uint32_t[]) {
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) | PropertyChangeMask });
}
}
}
@ -2833,6 +2836,7 @@ update_ewmh_active_win(session_t *ps) {
inline static void
ev_property_notify(session_t *ps, xcb_property_notify_event_t *ev) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
#ifdef DEBUG_EVENTS
{
// 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
if (!find_toplevel(ps, ev->window)) {
// Reset event mask anyway
XSelectInput(ps->dpy, ev->window,
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN));
xcb_change_window_attributes(c, ev->window, XCB_CW_EVENT_MASK, (const uint32_t[]) {
determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) });
win *w_top = find_toplevel2(ps, ev->window);
// Initialize client_win as early as possible
@ -4548,7 +4552,8 @@ init_overlay(session_t *ps) {
}
// 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
// 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
// root geometry changes
XSelectInput(ps->dpy, ps->root,
SubstructureNotifyMask
| ExposureMask
| StructureNotifyMask
| PropertyChangeMask);
xcb_change_window_attributes(c, ps->root, XCB_CW_EVENT_MASK, (const uint32_t[]) {
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
| XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_STRUCTURE_NOTIFY
| XCB_EVENT_MASK_PROPERTY_CHANGE });
XFlush(ps->dpy);
ps->root_width = DisplayWidth(ps->dpy, ps->scr);
@ -5468,7 +5473,8 @@ session_destroy(session_t *ps) {
redir_stop(ps);
// 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
// Kill DBus connection

View File

@ -312,12 +312,12 @@ win_ev_stop(session_t *ps, win *w) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
// Will get BadWindow if the window is destroyed
set_ignore_next(ps);
XSelectInput(ps->dpy, w->id, 0);
set_ignore_cookie(ps,
xcb_change_window_attributes(c, w->id, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 }));
if (w->client_win) {
set_ignore_next(ps);
XSelectInput(ps->dpy, w->client_win, 0);
set_ignore_cookie(ps,
xcb_change_window_attributes(c, w->client_win, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 }));
}
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)
return;
XSelectInput(ps->dpy, client,
determine_evmask(ps, client, WIN_EVMODE_CLIENT));
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
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
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
*/
void win_unmark_client(session_t *ps, win *w) {
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
Window client = w->client_win;
w->client_win = None;
// Recheck event mask
XSelectInput(ps->dpy, client,
determine_evmask(ps, client, WIN_EVMODE_UNKNOWN));
xcb_change_window_attributes(c, client, XCB_CW_EVENT_MASK,
(const uint32_t[]) { determine_evmask(ps, client, WIN_EVMODE_UNKNOWN) });
}
/**