// Copyright 2020-2024 David Robillard // SPDX-License-Identifier: ISC #include "x11_util.h" #include #include #include bool suil_x11_is_valid_child(Display* const display, const Window parent, const Window child) { Window root = 0U; Window grandparent = 0U; Window* children = NULL; unsigned n_children = 0U; XQueryTree(display, parent, &root, &grandparent, &children, &n_children); for (unsigned i = 0U; i < n_children; ++i) { if (children[i] == child) { if (children) { XFree(children); } return true; } } if (children) { XFree(children); } return false; } Window suil_x11_get_parent(Display* display, Window child) { Window root = 0U; Window parent = 0U; Window* children = NULL; unsigned count = 0U; if (child) { if (XQueryTree(display, child, &root, &parent, &children, &count)) { if (children) { XFree(children); } } } return (parent == root) ? 0 : parent; }