I am trying to get an X Window at a specific location on the screen. When I asked people to execute this function, they said that you would just call XQueryTree recursively.
This is a piece of code that I think is somehow wrong. When I debug it, it works fine. The only problem is that the conclusion he gives seems a little strange. When I do XQueryTree in the root window, I get hundreds of children when I have only five or so open. In addition, it seems that there is a top-level window somewhere where it simply does not exist, and returns it as a result. Regardless of how I move my actual windows, XQueryTree seems to indicate that there is another window on top of my windows (not covering the whole screen.) When I look where it says that this window is in some then an arbitrary point on my desktop.
If this helps: The display is in XOpenDisplay (NULL), and the root window that I originally passed is XDefaultRootWindow (display). I am running gnome under debian with metacity.
point getwindowatloc(Display * display, Window root, jint x, jint y) { Window returnedroot; Window returnedparent; Window * children; unsigned int numchildren; XQueryTree(display,root,&returnedroot,&returnedparent,&children, &numchildren); XWindowAttributes w; int i; for(i=numchildren-1; i>=0; i--) { XGetWindowAttributes(display,children[i],&w); if(x>=wx && x<=w.x+w.width && y>=wy && y <= w.y+w.height) { point result={wx,wy}; XFree(children); return result; } else { point result=getwindowatloc(display,children[i],xw.x,yw.y); if(result.x!=INT_MAX) { result.x+=wx; result.y+=wy; XFree(children); return result; } } } if(children) { XFree(children); } return notfound; }
Thanks!
EDIT: for those looking for similar information: I ended up searching for xwininfo source. The key function is Find_Client in dsimple.c, which somehow ignores window managers to get the window that you are really looking for. If you want to look into the subwindows, this is the code I added to Select_Window in dsimple.c, which will look recursively inside the subwindows using XTranslateCoordinates.
Window child; do { XTranslateCoordinates(dpy,target_temp,target_win,x,y,&x,&y,&child); target_temp=target_win; target_win=child; } while(target_win); return target_temp;