about summary refs log tree commit diff stats
path: root/dwm.c
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2011-11-06 20:31:29 +0100
committerConnor Lane Smith <cls@lubutu.com>2011-11-06 20:31:29 +0100
commit80a9da555e81a69ab2e2e8fa9b779fa087d6863c (patch)
tree160e330c0afcdf92a978866de58f36750c6abe89 /dwm.c
parentd21026f0a169841a70187b806cab8abd30e552ed (diff)
downloaddwm-80a9da555e81a69ab2e2e8fa9b779fa087d6863c.tar.gz
calculate window/monitor intersection
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/dwm.c b/dwm.c
index 4c6af64..fd6f04d 100644
--- a/dwm.c
+++ b/dwm.c
@@ -43,7 +43,8 @@
 /* macros */
 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
-#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
+#define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
+                               * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
 #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
 #define LENGTH(X)               (sizeof X / sizeof X[0])
 #define MAX(A, B)               ((A) > (B) ? (A) : (B))
@@ -203,8 +204,8 @@ static void movemouse(const Arg *arg);
 static Client *nexttiled(Client *c);
 static void pop(Client *);
 static void propertynotify(XEvent *e);
-static Monitor *ptrtomon(int x, int y);
 static void quit(const Arg *arg);
+static Monitor *recttomon(int x, int y, int w, int h);
 static void resize(Client *c, int x, int y, int w, int h, Bool interact);
 static void resizeclient(Client *c, int x, int y, int w, int h);
 static void resizemouse(const Arg *arg);
@@ -1248,7 +1249,7 @@ movemouse(const Arg *arg) {
 		}
 	} while(ev.type != ButtonRelease);
 	XUngrabPointer(dpy, CurrentTime);
-	if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
+	if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
 		sendmon(c, m);
 		selmon = m;
 		focus(NULL);
@@ -1305,21 +1306,24 @@ propertynotify(XEvent *e) {
 	}
 }
 
-Monitor *
-ptrtomon(int x, int y) {
-	Monitor *m;
-
-	for(m = mons; m; m = m->next)
-		if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
-			return m;
-	return selmon;
-}
-
 void
 quit(const Arg *arg) {
 	running = False;
 }
 
+Monitor *
+recttomon(int x, int y, int w, int h) {
+	Monitor *m, *r = selmon;
+	int a, area = 0;
+
+	for(m = mons; m; m = m->next)
+		if((a = INTERSECT(x, y, w, h, m)) > area) {
+			area = a;
+			r = m;
+		}
+	return r;
+}
+
 void
 resize(Client *c, int x, int y, int w, int h, Bool interact) {
 	if(applysizehints(c, &x, &y, &w, &h, interact))
@@ -1383,7 +1387,7 @@ resizemouse(const Arg *arg) {
 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
 	XUngrabPointer(dpy, CurrentTime);
 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
-	if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
+	if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
 		sendmon(c, m);
 		selmon = m;
 		focus(NULL);
@@ -2051,7 +2055,7 @@ wintomon(Window w) {
 	Monitor *m;
 
 	if(w == root && getrootptr(&x, &y))
-		return ptrtomon(x, y);
+		return recttomon(x, y, 1, 1);
 	for(m = mons; m; m = m->next)
 		if(w == m->barwin)
 			return m;
dbong/suckless/dwm/commit/config.def.h?h=6.2&id=b1a28ae1dab34a159e7cf17a82ecda0635e72f97'>b1a28ae ^
c3feffa ^
5497268 ^
1724f7f ^
2d4faae ^
12ea925 ^

a6d23fb ^
3794c62 ^

f196b71 ^
349d768 ^
0fe2e78 ^
5cd65f8 ^



0fe2e78 ^
512541b ^
1edf6a7 ^




d662f98 ^
a8e0772 ^
349d768 ^
1edf6a7 ^

5cd65f8 ^


b1a28ae ^

5cd65f8 ^

5cd65f8 ^


12ea925 ^



5cd65f8 ^
a8e0772 ^

a9e145f ^



5cd65f8 ^









b515765 ^
5cd65f8 ^

c3feffa ^
5cd65f8 ^

12ea925 ^

5cd65f8 ^
1edf6a7 ^
5cd65f8 ^


829b6b5 ^


b86c818 ^
5cd65f8 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105