Convert find_client_win() to XCB

This function was the only caller of wid_get_children() which called
XQueryTree().

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2018-10-03 14:59:27 +02:00 committed by Yuxuan Shui
parent b2bfbcdfb0
commit 6c6156932f
2 changed files with 14 additions and 34 deletions

View File

@ -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;
}

View File

@ -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.
*/