about summary refs log tree commit diff
path: root/dmenu.c
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2008-07-16 18:38:53 +0100
committerAnselm R Garbe <garbeam@gmail.com>2008-07-16 18:38:53 +0100
commit4d8a646958fa2e0c8fe9d8da3dd26357e8bb4317 (patch)
tree5263258edb252d83e2da8dfcddbd1ed2e2283ac5 /dmenu.c
parentreverted uint/ulong introduction (diff)
downloaddmenu-4d8a646958fa2e0c8fe9d8da3dd26357e8bb4317.tar.gz
dmenu-4d8a646958fa2e0c8fe9d8da3dd26357e8bb4317.tar.bz2
dmenu-4d8a646958fa2e0c8fe9d8da3dd26357e8bb4317.zip
got rid of compile time xidx, grabbing the mouse pointer instead, falling back to screen 0 if no pointer available
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/dmenu.c b/dmenu.c
index 33b1a89..e487333 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -16,7 +16,8 @@
 #endif
 
 /* macros */
-#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
+#define CLEANMASK(mask)         (mask & ~(numlockmask | LockMask))
+#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
 
 /* enums */
 enum { ColFG, ColBG, ColLast };
@@ -585,7 +586,7 @@ run(void) {
 
 void
 setup(Bool topbar) {
-	int i, j, x, y;
+	int i, j, n, x, y;
 	XModifierKeymap *modmap;
 	XSetWindowAttributes wa;
 #if XINERAMA
@@ -618,10 +619,20 @@ setup(Bool topbar) {
 	mh = dc.font.height + 2;
 #if XINERAMA
 	if(XineramaIsActive(dpy)) {
-		info = XineramaQueryScreens(dpy, &i);
-		x = info[xidx].x_org;
-		y = topbar ? info[xidx].y_org : info[xidx].y_org + info[xidx].height - mh;
-		mw = info[xidx].width;
+		i = 0;
+		info = XineramaQueryScreens(dpy, &n);
+		if(n > 1) {
+			int di;
+			unsigned int dui;
+			Window dummy;
+			if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui))
+				for(i = 0; i < n; i++)
+					if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
+						break;
+		}
+		x = info[i].x_org;
+		y = topbar ? info[i].y_org : info[i].y_org + info[i].height - mh;
+		mw = info[i].width;
 		XFree(info);
 	}
 	else