about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--dwm.c122
1 files changed, 79 insertions, 43 deletions
diff --git a/dwm.c b/dwm.c
index 096895c..9779654 100644
--- a/dwm.c
+++ b/dwm.c
@@ -166,7 +166,7 @@ static void detach(Client *c);
 static void detachstack(Client *c);
 static void die(const char *errstr, ...);
 static void drawbar(Monitor *m);
-static void drawbars();
+static void drawbars(void);
 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
 static void enternotify(XEvent *e);
@@ -176,6 +176,9 @@ static void focusin(XEvent *e);
 static void focusstack(const Arg *arg);
 static Client *getclient(Window w);
 static unsigned long getcolor(const char *colstr);
+static Monitor *getmonitor(Window w);
+static Monitor *getmonitorxy(int x, int y);
+static Bool getrootpointer(int *x, int *y);
 static long getstate(Window w);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void grabbuttons(Client *c, Bool focused);
@@ -197,6 +200,7 @@ static void resizemouse(const Arg *arg);
 static void restack(Monitor *m);
 static void run(void);
 static void scan(void);
+static void sendmon(Client *c, Monitor *m);
 static void setclientstate(Client *c, long state);
 static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
@@ -397,15 +401,11 @@ buttonpress(XEvent *e) {
 
 	click = ClkRootWin;
 	/* focus monitor if necessary */
-	for(m = mons; m; m = m->next)
-		if(ev->window == m->barwin) {
-			if(m != selmon) {
-				unfocus(selmon->stack);
-				selmon = m;
-				focus(NULL);
-			}
-			break;
-		}
+	if((m = getmonitor(ev->window)) && m != selmon) {
+		unfocus(selmon->sel);
+		selmon = m;
+		focus(NULL);
+	}
 	if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
 		i = 0;
 		x = selmon->btx;
@@ -683,7 +683,7 @@ drawbar(Monitor *m) {
 }
 
 void
-drawbars() {
+drawbars(void) {
 	Monitor *m;
 
 	for(m = mons; m; m = m->next)
@@ -742,10 +742,15 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
 void
 enternotify(XEvent *e) {
 	Client *c;
+	Monitor *m;
 	XCrossingEvent *ev = &e->xcrossing;
 
 	if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
 		return;
+	if((m = getmonitor(ev->window)) && m != selmon) {
+		unfocus(selmon->sel);
+		selmon = m;
+	}
 	if((c = getclient(ev->window)))
 		focus(c);
 	else
@@ -757,12 +762,8 @@ expose(XEvent *e) {
 	Monitor *m;
 	XExposeEvent *ev = &e->xexpose;
 
-	if(ev->count == 0)
-		for(m = mons; m; m = m->next)
-			if(ev->window == m->barwin) {
-				drawbar(m);
-				break;
-			}
+	if(ev->count == 0 && (m = getmonitor(ev->window)))
+		drawbar(m);
 }
 
 void
@@ -809,7 +810,6 @@ focusmon(const Arg *arg) {
 			unfocus(selmon->sel);
 			selmon = m;
 			focus(NULL);
-			drawbars();
 			break;
 		}
 }
@@ -863,6 +863,40 @@ getcolor(const char *colstr) {
 	return color.pixel;
 }
 
+Monitor *
+getmonitor(Window w) {
+	int x, y;
+	Client *c;
+	Monitor *m;
+
+	if(w == root && getrootpointer(&x, &y))
+		return getmonitorxy(x, y);
+	for(m = mons; m; m = m->next)
+		if(w == m->barwin)
+			return m;
+	if((c = getclient(w)))
+		return c->mon;
+	return NULL;
+}
+
+Monitor *
+getmonitorxy(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 NULL;
+}
+
+Bool
+getrootpointer(int *x, int *y) {
+	int di;
+	unsigned int dui;
+	Window dummy;
+	return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
+}
+
 long
 getstate(Window w) {
 	int format, status;
@@ -1124,10 +1158,9 @@ monocle(Monitor *m) {
 
 void
 movemouse(const Arg *arg) {
-	int x, y, ocx, ocy, di, nx, ny;
-	unsigned int dui;
+	int x, y, ocx, ocy, nx, ny;
 	Client *c;
-	Window dummy;
+	Monitor *m;
 	XEvent ev;
 
 	if(!(c = selmon->sel))
@@ -1138,7 +1171,8 @@ movemouse(const Arg *arg) {
 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
 		return;
-	XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
+	if(!getrootpointer(&x, &y))
+		return;
 	do {
 		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
 		switch (ev.type) {
@@ -1171,6 +1205,8 @@ movemouse(const Arg *arg) {
 	}
 	while(ev.type != ButtonRelease);
 	XUngrabPointer(dpy, CurrentTime);
+	if((m = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
+		sendmon(c, m);
 }
 
 Client *
@@ -1239,6 +1275,7 @@ resizemouse(const Arg *arg) {
 	int ocx, ocy;
 	int nw, nh;
 	Client *c;
+	Monitor *m;
 	XEvent ev;
 
 	if(!(c = selmon->sel))
@@ -1277,6 +1314,8 @@ 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 = getmonitorxy(c->x + c->w / 2, c->y + c->h / 2)) != selmon)
+		sendmon(c, m);
 }
 
 void
@@ -1342,6 +1381,20 @@ scan(void) {
 }
 
 void
+sendmon(Client *c, Monitor *m) {
+	if(c->mon == m)
+		return;
+	detach(c);
+	detachstack(c);
+	c->mon = m;
+	c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
+	attach(c);
+	attachstack(c);
+	focus(NULL);
+	arrange();
+}
+
+void
 setclientstate(Client *c, long state) {
 	long data[] = {state, None};
 
@@ -1497,14 +1550,7 @@ tagmon(const Arg *arg) {
 		return;
 	for(i = 0, m = mons; m; m = m->next, i++)
 		if(i == arg->ui) {
-			detach(c);
-			detachstack(c);
-			c->mon = m;
-			c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
-			attach(c);
-			attachstack(c);
-			focus(NULL);
-			arrange();
+			sendmon(c, m);
 			break;
 		}
 }
@@ -1676,11 +1722,9 @@ updatebarpos(Monitor *m) {
 
 void
 updategeom(void) {
-	int i, di, n = 1, x, y;
-	unsigned int dui;
+	int i, n = 1;
 	Client *c;
 	Monitor *newmons = NULL, *m, *tm;
-	Window dummy;
 
 #ifdef XINULATOR
 	n = 2;
@@ -1763,17 +1807,9 @@ updategeom(void) {
 		}
 
 	/* select focused monitor */
-	selmon = newmons;
-	if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) 
-		for(m = newmons; m; m = m->next)
-			if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh)) {
-				selmon = m;
-				break;
-			}
-
-	/* final assignment of new monitors */
 	cleanupmons();
 	mons = newmons;
+	selmon = getmonitor(root);
 }
 
 void
@@ -1848,7 +1884,7 @@ updatetitle(Client *c) {
 }
 
 void
-updatestatus() {
+updatestatus(void) {
 	if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
 		strcpy(stext, "dwm-"VERSION);
 	drawbar(selmon);
;id=cff951c65086950eeef5723b65dc06cbe7cdfa19'>^
727449d ^
6a9300e ^
6e22ccf ^

6a9300e ^
adaa28a ^
24d91e3 ^



b6ad663 ^
24d91e3 ^

a635743 ^
6b34535 ^


adaa28a ^
b6ad663 ^
f18ed61 ^
adaa28a ^
1076f2b
f841501 ^
d180ba4 ^
f841501 ^







1076f2b
d180ba4 ^
f841501 ^








22399a3 ^
f841501 ^





























d180ba4 ^



















6b25d06 ^
b5159df ^








a5cb80b ^
b5159df ^



b5159df ^



6651dd7 ^
a24a670 ^
b5159df ^
e256afe ^
b5159df ^
e256afe ^

b5159df ^

6b34535 ^
6651dd7 ^
ca65478 ^
f9e7a33 ^
b5159df ^

f9e7a33 ^
b5159df ^
cdbc84b ^
b5159df ^


b5159df ^
d180ba4 ^






6651dd7 ^
74cbbe5 ^
b5159df ^

cdbc84b ^
6651dd7 ^
b55bd70 ^
b5159df ^


37e062b ^
d2dd58e ^
b5159df ^

cf58091 ^
2aef8b9 ^
b5159df ^
6651dd7 ^

b5159df ^

2e834e9 ^
a686c9c ^

6651dd7 ^
87836d7 ^
b5159df ^

adaa28a ^




ca65478 ^
adaa28a ^



bf35794 ^

3399650 ^
2c477cf ^
727449d ^
1076f2b

2aef8b9 ^

ce450c5 ^

2aef8b9 ^




37e062b ^
2aef8b9 ^









37e062b ^
2aef8b9 ^
8f5f7a5 ^

2aef8b9 ^

6651dd7 ^
bf35794 ^
b597fa4 ^
dba2306 ^

ca65478 ^
dba2306 ^
dc5d967 ^




1d7674b ^

dba2306 ^

dc5d967 ^
b597fa4 ^
4641aa2 ^

1076f2b
ca65478 ^
61a1910 ^
b5159df ^
dc5d967 ^
e9c49dd ^
1076f2b
32563ab ^
59e65d1 ^
4970ef9 ^

d42c3ba ^
6bc4556 ^
86d1224 ^
e571de8 ^
1076f2b

dba2306 ^

86d1224 ^
1076f2b
f60c597 ^
dba2306 ^

1076f2b
b6ad663 ^
f60c597 ^
dba2306 ^
2ffdc19 ^
b5159df ^
c0705ee ^
dba2306 ^
1076f2b
4e2c5b5 ^
0680c76 ^
727449d ^
e3fd306 ^
0e5c819 ^
95e8d12 ^

e571de8 ^
478f6f9 ^


61a1910 ^
478f6f9 ^

61a1910 ^
478f6f9 ^
61a1910 ^
35e96b8 ^
478f6f9 ^


35e96b8 ^
478f6f9 ^


2210ea7 ^
fd995da ^
61a1910 ^

0e5c819 ^
478f6f9 ^
0e5c819 ^
b3b58c0 ^




439e15d ^
1076f2b

1076f2b

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350