#include #include #include #include #include #include static Display *display; static Status recurse(unsigned int level, Window window) { Window root, parent; unsigned int i; char *name = NULL; Window *children = NULL; unsigned int num_children = 0; XFetchName(display, window, &name); for (i = 0; i < level; i++) printf(" "); printf("[0x%x] %s\n", (unsigned int)window, name ? name : "(no name)"); if (name) XFree(name); if (!XQueryTree(display, window, &root, &parent, &children, &num_children)) return False; if (children) { for (i = 0; i < num_children; i++) { if (!recurse(level + 1, children[i])) return False; } XFree(children); } return True; } int main(int argc, char **argv) { int status = EXIT_FAILURE; display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Could not open default display\n"); goto out; } if (!recurse(0, DefaultRootWindow(display))) goto out_display; status = EXIT_SUCCESS; out_display: XCloseDisplay(display); out: return 0; }