core: let's not do ancestry lookups

Always assume WM frames are direct children of the root window, and
client windows are direct children of their respective frames. Also WM
frames must have a one-to-one relationship with client windows.

We already assume this in most places, but it's inconsistent. Let's make
this assumption official. If something breaks we can then figure out a
principled way of dealing with that. Instead of having things "happen to
work" which is the situation now.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-03-25 01:44:11 +00:00
parent 21777fce05
commit 54fb0c7ac0
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
3 changed files with 11 additions and 36 deletions

View File

@ -402,12 +402,12 @@ static inline void ev_reparent_notify(session_t *ps, xcb_reparent_notify_event_t
ev->window);
evmask |= XCB_EVENT_MASK_PROPERTY_CHANGE;
} else {
auto w_real_top = find_managed_window_or_parent(ps, ev->parent);
if (w_real_top) {
auto w = find_managed_win(ps, ev->parent);
if (w) {
log_debug("Mark window %#010x (%s) as having a stale "
"client",
w_real_top->base.id, w_real_top->name);
win_set_flags(w_real_top, WIN_FLAGS_CLIENT_STALE);
w->base.id, w->name);
win_set_flags(w, WIN_FLAGS_CLIENT_STALE);
ps->pending_updates = true;
} else {
log_debug("parent %#010x not found", ev->parent);

View File

@ -146,26 +146,6 @@ static inline int64_t get_time_ms(void) {
return (int64_t)tp.tv_sec * 1000 + (int64_t)tp.tv_nsec / 1000000;
}
/**
* Find matched window.
*
* XXX move to win.c
*/
static inline struct managed_win *find_win_all(session_t *ps, const xcb_window_t wid) {
if (!wid || PointerRoot == wid || wid == ps->c.screen_info->root || wid == ps->overlay) {
return NULL;
}
auto w = find_managed_win(ps, wid);
if (!w) {
w = find_toplevel(ps, wid);
}
if (!w) {
w = find_managed_window_or_parent(ps, wid);
}
return w;
}
enum vblank_callback_action check_render_finish(struct vblank_event *e attr_unused, void *ud) {
auto ps = (session_t *)ud;
if (!ps->backend_busy) {
@ -556,7 +536,7 @@ void update_ewmh_active_win(session_t *ps) {
// Search for the window
xcb_window_t wid = wid_get_prop_window(&ps->c, ps->c.screen_info->root,
ps->atoms->a_NET_ACTIVE_WINDOW);
auto w = find_win_all(ps, wid);
auto w = find_toplevel(ps, wid);
// Mark the window focused. No need to unfocus the previous one.
if (w) {
@ -589,7 +569,7 @@ static void recheck_focus(session_t *ps) {
free(reply);
}
auto w = find_win_all(ps, wid);
auto w = find_managed_window_or_parent(ps, wid);
log_trace("%#010" PRIx32 " (%#010lx \"%s\") focused.", wid,
(w ? w->base.id : XCB_NONE), (w ? w->name : NULL));

View File

@ -1507,24 +1507,19 @@ void win_unmark_client(session_t *ps, struct managed_win *w) {
*/
static xcb_window_t
find_client_win(struct x_connection *c, struct atom *atoms, xcb_window_t w) {
if (wid_has_prop(c->c, w, atoms->aWM_STATE)) {
return w;
}
xcb_query_tree_reply_t *reply =
xcb_query_tree_reply(c->c, xcb_query_tree(c->c, w), NULL);
if (!reply) {
return 0;
return XCB_NONE;
}
xcb_window_t *children = xcb_query_tree_children(reply);
int nchildren = xcb_query_tree_children_length(reply);
int i;
xcb_window_t ret = 0;
xcb_window_t ret = XCB_NONE;
for (i = 0; i < nchildren; ++i) {
ret = find_client_win(c, atoms, children[i]);
if (ret) {
for (int i = 0; i < nchildren; ++i) {
if (wid_has_prop(c->c, children[i], atoms->aWM_STATE)) {
ret = children[i];
break;
}
}