From 6c6156932f95c6e4b31cc8f1fed77f4d098f773f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 3 Oct 2018 14:59:27 +0200 Subject: [PATCH] Convert find_client_win() to XCB This function was the only caller of wid_get_children() which called XQueryTree(). Signed-off-by: Uli Schlachter --- src/compton.c | 22 ++++++++++++---------- src/compton.h | 26 ++------------------------ 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/compton.c b/src/compton.c index 96db232..75f437a 100644 --- a/src/compton.c +++ b/src/compton.c @@ -985,27 +985,29 @@ paint_root(session_t *ps, const region_t *reg_paint) { /** * Look for the client window of a particular window. */ -Window -find_client_win(session_t *ps, Window w) { +xcb_window_t +find_client_win(session_t *ps, xcb_window_t w) { if (wid_has_prop(ps, w, ps->atom_client)) { return w; } - Window *children; - unsigned int nchildren; - unsigned int i; - Window ret = 0; - - if (!wid_get_children(ps, w, &children, &nchildren)) { + xcb_connection_t *c = XGetXCBConnection(ps->dpy); + xcb_query_tree_reply_t *reply = xcb_query_tree_reply(c, + xcb_query_tree(c, w), NULL); + if (!reply) return 0; - } + + xcb_window_t *children = xcb_query_tree_children(reply); + int nchildren = xcb_query_tree_children_length(reply); + int i; + xcb_window_t ret = 0; for (i = 0; i < nchildren; ++i) { if ((ret = find_client_win(ps, children[i]))) break; } - cxfree(children); + free(reply); return ret; } diff --git a/src/compton.h b/src/compton.h index bae513d..5dea260 100644 --- a/src/compton.h +++ b/src/compton.h @@ -43,8 +43,8 @@ void add_damage(session_t *ps, const region_t *damage); long determine_evmask(session_t *ps, Window wid, win_evmode_t mode); -Window -find_client_win(session_t *ps, Window w); +xcb_window_t +find_client_win(session_t *ps, xcb_window_t w); win *find_toplevel2(session_t *ps, Window wid); @@ -326,28 +326,6 @@ win_ev_stop(session_t *ps, win *w) { } } -/** - * Get the children of a window. - * - * @param ps current session - * @param w window to check - * @param children [out] an array of child window IDs - * @param nchildren [out] number of children - * @return 1 if successful, 0 otherwise - */ -static inline bool -wid_get_children(session_t *ps, Window w, - Window **children, unsigned *nchildren) { - Window troot, tparent; - - if (!XQueryTree(ps->dpy, w, &troot, &tparent, children, nchildren)) { - *nchildren = 0; - return false; - } - - return true; -} - /** * Check whether a window has WM frames. */