From 54fb0c7ac045114255b3176031ec17908d049efd Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Mon, 25 Mar 2024 01:44:11 +0000 Subject: [PATCH] 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 --- src/event.c | 8 ++++---- src/picom.c | 24 ++---------------------- src/win.c | 15 +++++---------- 3 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/event.c b/src/event.c index f76d693c..16e32a8d 100644 --- a/src/event.c +++ b/src/event.c @@ -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); diff --git a/src/picom.c b/src/picom.c index ec26cfe9..ff2fa2cd 100644 --- a/src/picom.c +++ b/src/picom.c @@ -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)); diff --git a/src/win.c b/src/win.c index 09e6a764..ca3b5bcb 100644 --- a/src/win.c +++ b/src/win.c @@ -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; } }