xcb_query_tree(3)

๐Ÿ“ฆ
version 1.17.0 ยท 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

โœจ xcb_query_tree(3) โœจ

okay bestie, welcome to xcb_query_tree from section 3 of the manual โ€” yes the library-functions girly section ๐Ÿ’… this one lives in libxcb and it's literally the request that lets you peek at a window's family tree. iconic behavior honestly ๐Ÿ‘‘


๐ŸŒธ NAME ๐ŸŒธ

xcb_query_tree โ€” query the window tree ๐ŸŒณ


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#include <xcb/xproto.h>

๐Ÿ’– Request function

xcb_query_tree_cookie_t xcb_query_tree(xcb_connection_t *conn,
       xcb_window_t window);

๐Ÿ’– Reply datastructure

typedef struct xcb_query_tree_reply_t {
    uint8_t      response_type;
    uint8_t      pad0;
    uint16_t     sequence;
    uint32_t     length;
    xcb_window_t root;
    xcb_window_t parent;
    uint16_t     children_len;
    uint8_t      pad1[14];
} xcb_query_tree_reply_t;

๐Ÿ’– Reply function

xcb_query_tree_reply_t *xcb_query_tree_reply(xcb_connection_t *conn,
       xcb_query_tree_cookie_t cookie, xcb_generic_error_t **e);

๐Ÿ’– Reply accessors

xcb_window_t *xcb_query_tree_children(const xcb_query_tree_request_t
       *reply);

int xcb_query_tree_children_length(const xcb_query_tree_reply_t *reply);

xcb_generic_iterator_t xcb_query_tree_children_end(const
       xcb_query_tree_reply_t *reply);

๐ŸŒˆ REQUEST ARGUMENTS ๐ŸŒˆ

  • conn โ€” the XCB connection to X11, your little lifeline to the server fr fr ๐Ÿซถ
  • window โ€” the window you're interrogating. the one you wanna know everything about ๐Ÿ‘€

๐Ÿ’œ REPLY FIELDS ๐Ÿ’œ

  • response_type โ€” the type of this reply, which in this case is XCB_QUERY_TREE. this field is also chillin' inside the xcb_generic_reply_t, so you can use it to tell your replies apart from each other. vibe check for replies basically โœจ
  • sequence โ€” the sequence number of the last request the X11 server actually processed.
  • length โ€” the length of the reply, measured in words. and a word is 4 bytes, no cap ๐Ÿ“
  • root โ€” the root window of window. the ancestor of all ancestors ๐ŸŒณ
  • parent โ€” the parent window of window. yes she has a mom ๐Ÿ’…
  • children_len โ€” how many child windows there are. count 'em ๐Ÿงฎ

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so this request gets you three things for the window you specify: the root window ID, the parent window ID, and the list of children windows. and the children come back listed in bottom-to-top stacking order โ€” so the bottom-most one is first, going up from there. stacking order, not alphabetical, bestie, don't get it twisted ๐Ÿ’…


โญ RETURN VALUE โญ

it hands you back an xcb_query_tree_cookie_t ๐Ÿช (yes, cookie, we love a snack). any errors have to be dealt with when you call the reply function, xcb_query_tree_reply.

if you'd rather handle your errors inside the event loop instead, then use xcb_query_tree_unchecked. see xcb-requests(3) for the deets ๐Ÿ‘‘


๐Ÿ’€ ERRORS ๐Ÿ’€

this request does never generate any errors. not one. zero. she's unproblematic and we love that for her ๐Ÿ™ˆโœจ


๐Ÿ“ EXAMPLE ๐Ÿ“

here's the whole thing, verbatim, so you can copy it straight into your little project:

/*
 * Displays the root, parent and children of the specified window.
 *
 */
void my_example(xcb_connection_t *conn, xcb_window_t window) {
    xcb_query_tree_cookie_t cookie;
    xcb_query_tree_reply_t *reply;

    cookie = xcb_query_tree(conn, window);
    if ((reply = xcb_query_tree_reply(conn, cookie, NULL))) {
        printf("root = 0x%08x\n", reply->root);
        printf("parent = 0x%08x\n", reply->parent);

        xcb_window_t *children = xcb_query_tree_children(reply);
        for (int i = 0; i < xcb_query_tree_children_length(reply); i++)
            printf("child window = 0x%08x\n", children[i]);

        free(reply);
    }
}
bestie, don't forget the free(reply) at the end. the way that memory is not gonna free itself ๐Ÿ˜ญ

๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

xcb-requests(3), xcb-examples(3), xwininfo(1)


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Generated from xproto.xml. Contact xcb@lists.freedesktop.org for corrections and improvements.


kisses, that's the whole page ๐Ÿซถ this was brought to you by X Version 11 and libxcb 1.17.0 โ€” she's serving xcb_query_tree(3) realness and honestly? obsessed. go query that tree bestie ๐ŸŒณ๐Ÿ’–โœจ