X11 x11 = X11.INSTANCE;
X11.WindowByReference rootp = new X11.WindowByReference();
X11.WindowByReference parentp = new X11.WindowByReference();
PointerByReference childrenp = new PointerByReference();
IntByReference countp = new IntByReference();
x11.XQueryTree(dpy, win, rootp, parentp, childrenp, countp);
Pointer p = childrenp.getValue();
int[] ids = p.getIntArray(0, countp.getValue());
for (int i=0;i < ids.length;i++) {
// TODO: more verification of correct window?
X11.Window child = new X11.Window(ids[i]);