+ Window w, pw, dw, *dws;
+ XWindowAttributes wa;
+
+ XGetInputFocus(dc->dpy, &w, &di);
+ if(w != root && w != PointerRoot && w != None) {
+ /* find top-level window containing current input focus */
+ do {
+ if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws)
+ XFree(dws);
+ } while(w != root && w != pw);
+ /* find xinerama screen with which the window intersects most */
+ if(XGetWindowAttributes(dc->dpy, pw, &wa))
+ for(j = 0; j < n; j++)
+ if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
+ area = a;
+ i = j;
+ }
+ }
+ /* no focused window is on screen, so use pointer location instead */
+ if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
+ for(i = 0; i < n; i++)
+ if(INTERSECT(x, y, 1, 1, info[i]))
+ break;