#include <X11/Xlib.h>
#include <stdio.h>
int main() {
  Display *d = XOpenDisplay(NULL);
  if (!d) { fprintf(stderr, "no display\n"); return 1; }
  int s = DefaultScreen(d);
  printf("screen %dx%d\n", DisplayWidth(d, s), DisplayHeight(d, s));
  Window root = RootWindow(d, s);
  Window rr, parent, *children; unsigned int n;
  XQueryTree(d, root, &rr, &parent, &children, &n);
  printf("root has %u children\n", n);
  for (unsigned i = 0; i < n; i++) {
    XWindowAttributes a;
    XGetWindowAttributes(d, children[i], &a);
    char *name = NULL;
    XFetchName(d, children[i], &name);
    printf("  win 0x%lx %dx%d+%d+%d map=%d name=%s\n",
           children[i], a.width, a.height, a.x, a.y, a.map_state,
           name ? name : "(none)");
    if (name) XFree(name);
  }
  if (children) XFree(children);
  XCloseDisplay(d);
  return 0;
}
