static Window find_sub_sub_window(Window top, int* x, int* y) { Window base; Window* children; Window foo; Window target = 0; int rel_x, rel_y, new_x = 1, new_y = 1; int targetsize = 1000000; unsigned int nc, width, height, border, depth; base = top; if (!base) return base; ; if (!XQueryTree(dpy, base, &foo, &foo, &children, &nc) || children == NULL) return base; /* no more windows here */ ; log_debug("found subwindows %d\n", nc); /* check if we hit a sub window and find the smallest one */ for (; nc > 0; nc--) { if (XGetGeometry(dpy, children[nc - 1], &foo, &rel_x, &rel_y, &width, &height, &border, &depth)) { if ((rel_x <= *x) && (*x <= (int) (rel_x + width)) && (rel_y <= *y) && (*y <= (int) (rel_y + height))) { log_debug("found a subwindow 0x%x +%d +%d %d x %d\n", children[nc - 1], rel_x, rel_y, width, height); if ((int) (width * height) < targetsize) { target = children[nc - 1]; targetsize = width * height; new_x = *x - rel_x; new_y = *y - rel_y; /*bull's eye ... */ target = find_sub_sub_window(target, &new_x, &new_y); } } } } ; if (children != NULL) XFree(children); if (target) { *x = new_x; *y = new_y; return target; } else { return base; } }
Window find_sub_window(Window top,char *name,int *x, int *y) { Window base; Window *children,foo,target=0; unsigned int nc, rel_x,rel_y,width,height,border,depth, new_x=1,new_y=1, targetsize=1000000; base=find_window(top, name); if (!base) {return base;}; if(!XQueryTree(dpy,base,&foo,&foo,&children,&nc) || children==NULL) { return(base); /* no more windows here */ }; debugprintf("found subwindows %d\n",nc); /* check if we hit a sub window and find the smallest one */ for(;nc>0;nc--) { if(XGetGeometry(dpy, children[nc-1], &foo, &rel_x, &rel_y, &width, &height, &border, &depth)){ if ((rel_x<=*x)&&(*x<=rel_x+width)&&(rel_y<=*y)&&(*y<=rel_y+height)){ debugprintf("found a subwindow %x +%d +%d %d x %d \n",children[nc-1], rel_x,rel_y,width,height); if ((width*height)<targetsize){ target=children[nc-1]; targetsize=width*height; new_x=*x-rel_x; new_y=*y-rel_y; /*bull's eye ...*/ target=find_sub_sub_window(target,&new_x,&new_y); } } } }; if(children!=NULL) XFree(children); if (target){ *x=new_x; *y=new_y; return target; }else return base; }