diff options
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -13,9 +13,10 @@ | |||
13 | #endif | 13 | #endif |
14 | #include "draw.h" | 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)) | 16 | #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ |
17 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | 17 | * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) |
18 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) | 18 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
19 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) | ||
19 | 20 | ||
20 | typedef struct Item Item; | 21 | typedef struct Item Item; |
21 | struct Item { | 22 | struct Item { |
@@ -513,19 +514,28 @@ setup(void) { | |||
513 | mh = (lines + 1) * bh; | 514 | mh = (lines + 1) * bh; |
514 | #ifdef XINERAMA | 515 | #ifdef XINERAMA |
515 | if((info = XineramaQueryScreens(dc->dpy, &n))) { | 516 | if((info = XineramaQueryScreens(dc->dpy, &n))) { |
516 | int i, di; | 517 | int a, j, di, i = 0, area = 0; |
517 | unsigned int du; | 518 | unsigned int du; |
518 | Window w, dw; | 519 | Window w, pw, dw, *dws; |
519 | XWindowAttributes wa; | 520 | XWindowAttributes wa; |
520 | 521 | ||
521 | XGetInputFocus(dc->dpy, &w, &di); | 522 | XGetInputFocus(dc->dpy, &w, &di); |
522 | if(w != root && w != PointerRoot && w != None && XGetWindowAttributes(dc->dpy, w, &wa)) | 523 | if(w != root && w != PointerRoot && w != None) { |
523 | XTranslateCoordinates(dc->dpy, w, root, wa.x, wa.y, &x, &y, &dw); | 524 | do { |
524 | else | 525 | if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws) |
525 | XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du); | 526 | XFree(dws); |
526 | for(i = 0; i < n-1; i++) | 527 | } while(w != root && w != pw); |
527 | if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) | 528 | if(XGetWindowAttributes(dc->dpy, pw, &wa)) |
528 | break; | 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 | x = info[i].x_org; | 539 | x = info[i].x_org; |
530 | y = info[i].y_org + (topbar ? 0 : info[i].height - mh); | 540 | y = info[i].y_org + (topbar ? 0 : info[i].height - mh); |
531 | mw = info[i].width; | 541 | mw = info[i].width; |