input focus: calculate areas of intersection
dd29c5d4
1 file(s) · +22 −12
| 13 | 13 | #endif |
|
| 14 | 14 | #include "draw.h" |
|
| 15 | 15 | ||
| 16 | - | #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) |
|
| 17 | - | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
|
| 18 | - | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
|
| 16 | + | #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ |
|
| 17 | + | * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) |
|
| 18 | + | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
|
| 19 | + | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
|
| 19 | 20 | ||
| 20 | 21 | typedef struct Item Item; |
|
| 21 | 22 | struct Item { |
|
| 513 | 514 | mh = (lines + 1) * bh; |
|
| 514 | 515 | #ifdef XINERAMA |
|
| 515 | 516 | if((info = XineramaQueryScreens(dc->dpy, &n))) { |
|
| 516 | - | int i, di; |
|
| 517 | + | int a, j, di, i = 0, area = 0; |
|
| 517 | 518 | unsigned int du; |
|
| 518 | - | Window w, dw; |
|
| 519 | + | Window w, pw, dw, *dws; |
|
| 519 | 520 | XWindowAttributes wa; |
|
| 520 | 521 | ||
| 521 | 522 | XGetInputFocus(dc->dpy, &w, &di); |
|
| 522 | - | if(w != root && w != PointerRoot && w != None && XGetWindowAttributes(dc->dpy, w, &wa)) |
|
| 523 | - | XTranslateCoordinates(dc->dpy, w, root, wa.x, wa.y, &x, &y, &dw); |
|
| 524 | - | else |
|
| 525 | - | XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); |
|
| 526 | - | for(i = 0; i < n-1; i++) |
|
| 527 | - | if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) |
|
| 528 | - | break; |
|
| 523 | + | if(w != root && w != PointerRoot && w != None) { |
|
| 524 | + | do { |
|
| 525 | + | if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws) |
|
| 526 | + | XFree(dws); |
|
| 527 | + | } while(w != root && w != pw); |
|
| 528 | + | if(XGetWindowAttributes(dc->dpy, pw, &wa)) |
|
| 529 | + | for(j = 0; j < n; j++) |
|
| 530 | + | if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { |
|
| 531 | + | area = a; |
|
| 532 | + | i = j; |
|
| 533 | + | } |
|
| 534 | + | } |
|
| 535 | + | if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) |
|
| 536 | + | for(i = 0; i < n; i++) |
|
| 537 | + | if(INTERSECT(x, y, 1, 1, info[i])) |
|
| 538 | + | break; |
|
| 529 | 539 | x = info[i].x_org; |
|
| 530 | 540 | y = info[i].y_org + (topbar ? 0 : info[i].height - mh); |
|
| 531 | 541 | mw = info[i].width; |
|