event: tweak ev_reparent_notify

Instead of change window attributes back and forth, calculate the evmask
and set it just once. And also make sure the request is flushed.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-02-06 08:56:37 +00:00
parent 037be5cca2
commit baeafb3a3b
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
1 changed files with 5 additions and 7 deletions

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2019, Yuxuan Shui <yshuiv7@gmail.com>
#include <stdint.h>
#include <stdio.h>
#include <X11/Xlibint.h>
@ -350,19 +351,14 @@ static inline void ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t
}
// Reset event mask in case something wrong happens
xcb_change_window_attributes(
ps->c.c, ev->window, XCB_CW_EVENT_MASK,
(const uint32_t[]){determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN)});
uint32_t evmask = determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN);
if (!wid_has_prop(ps, ev->window, ps->atoms->aWM_STATE)) {
log_debug("Window %#010x doesn't have WM_STATE property, it is "
"probably not a client window. But we will listen for "
"property change in case it gains one.",
ev->window);
xcb_change_window_attributes(
ps->c.c, ev->window, XCB_CW_EVENT_MASK,
(const uint32_t[]){determine_evmask(ps, ev->window, WIN_EVMODE_UNKNOWN) |
XCB_EVENT_MASK_PROPERTY_CHANGE});
evmask |= XCB_EVENT_MASK_PROPERTY_CHANGE;
} else {
auto w_real_top = find_managed_window_or_parent(ps, ev->parent);
if (w_real_top && w_real_top->state != WSTATE_UNMAPPED &&
@ -386,6 +382,8 @@ static inline void ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t
}
}
}
XCB_AWAIT_VOID(xcb_change_window_attributes, ps->c.c, ev->window,
XCB_CW_EVENT_MASK, (const uint32_t[]){evmask});
}
}