Last active
April 10, 2023 14:48
-
-
Save IronOxidizer/017d538d1837e25b118a1009e00c959d to your computer and use it in GitHub Desktop.
xcb search window by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xcb_window_t search_window_by_name(xcb_connection_t *conn, xcb_window_t window, const char *search_string) { | |
// check name | |
xcb_get_property_reply_t *name_reply = xcb_get_property_reply(conn, xcb_get_property(conn, 0, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 0, 256), NULL); | |
if (name_reply) { | |
char *name = xcb_get_property_value(name_reply); | |
free(name_reply); | |
if (name && !strcmp(name, search_string)) return window; | |
} | |
// get window tree | |
xcb_query_tree_reply_t *tree_reply = xcb_query_tree_reply(conn, xcb_query_tree(conn, window), NULL); | |
if (!tree_reply) return 0; | |
// get children | |
xcb_window_t *children = xcb_query_tree_children(tree_reply); | |
int num_children = xcb_query_tree_children_length(tree_reply); | |
// recurse | |
for (int i = 0; i < num_children; ++i) { | |
xcb_window_t child = search_window_by_name(conn, children[i], search_string); | |
if (child != 0) { // child found | |
free(tree_reply); | |
return child; | |
} | |
} | |
// not found in children | |
free(tree_reply); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment