Convert XQueryTree to XCB

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2018-10-03 15:06:16 +02:00 committed by Yuxuan Shui
parent 6c6156932f
commit 54807342f4
1 changed files with 22 additions and 18 deletions

View File

@ -827,27 +827,24 @@ long determine_evmask(session_t *ps, Window wid, win_evmode_t mode) {
win *find_toplevel2(session_t *ps, Window wid) { win *find_toplevel2(session_t *ps, Window wid) {
// TODO this should probably be an "update tree", then find_toplevel. // TODO this should probably be an "update tree", then find_toplevel.
// current approach is a bit more "racy" // current approach is a bit more "racy"
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
win *w = NULL; win *w = NULL;
// We traverse through its ancestors to find out the frame // We traverse through its ancestors to find out the frame
while (wid && wid != ps->root && !(w = find_win(ps, wid))) { while (wid && wid != ps->root && !(w = find_win(ps, wid))) {
Window troot; xcb_query_tree_reply_t *reply;
Window parent;
Window *tchildren;
unsigned tnchildren;
// XQueryTree probably fails if you run compton when X is somehow // xcb_query_tree probably fails if you run compton when X is somehow
// initializing (like add it in .xinitrc). In this case // initializing (like add it in .xinitrc). In this case
// just leave it alone. // just leave it alone.
if (!XQueryTree(ps->dpy, wid, &troot, &parent, &tchildren, reply = xcb_query_tree_reply(c, xcb_query_tree(c, wid), NULL);
&tnchildren)) { if (reply == NULL) {
parent = 0;
break; break;
} }
cxfree(tchildren); wid = reply->parent;
wid = parent; free(reply);
} }
return w; return w;
@ -5413,18 +5410,25 @@ session_init(session_t *ps_old, int argc, char **argv) {
xcb_grab_server(c); xcb_grab_server(c);
{ {
Window root_return, parent_return; xcb_window_t *children;
Window *children; int nchildren;
unsigned int nchildren;
XQueryTree(ps->dpy, ps->root, &root_return, xcb_query_tree_reply_t *reply = xcb_query_tree_reply(c,
&parent_return, &children, &nchildren); xcb_query_tree(c, ps->root), NULL);
for (unsigned i = 0; i < nchildren; i++) { if (reply) {
add_win(ps, children[i], i ? children[i-1] : None); children = xcb_query_tree_children(reply);
nchildren = xcb_query_tree_children_length(reply);
} else {
children = NULL;
nchildren = 0;
} }
cxfree(children); for (int i = 0; i < nchildren; i++) {
add_win(ps, children[i], i ? children[i-1] : XCB_NONE);
}
free(reply);
} }
if (ps->o.track_focus) { if (ps->o.track_focus) {