about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2009-06-22 14:58:08 +0100
committerAnselm R Garbe <garbeam@gmail.com>2009-06-22 14:58:08 +0100
commit78f56672b5164f2d8f7ecabc3be0a9bbe0ae98bf (patch)
treee2c00fdef01cfe23c167b2366d472302ee9212b7
parentc2fff604a760d271c7e9311c2927954e87ac3a6e (diff)
downloaddwm-78f56672b5164f2d8f7ecabc3be0a9bbe0ae98bf.tar.gz
changes monitor structure to be a list
-rw-r--r--dwm.c302
1 files changed, 169 insertions, 133 deletions
diff --git a/dwm.c b/dwm.c
index 5610a37..afe8f18 100644
--- a/dwm.c
+++ b/dwm.c
@@ -44,7 +44,7 @@
 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
-#define ISVISIBLE(M, C)         ((M) == (&mon[C->mon]) && (C->tags & M->tagset[M->seltags]))
+#define ISVISIBLE(M, C)         ((M) == (C->m) && (C->tags & M->tagset[M->seltags]))
 #define LENGTH(X)               (sizeof X / sizeof X[0])
 #define MAX(A, B)               ((A) > (B) ? (A) : (B))
 #define MIN(A, B)               ((A) < (B) ? (A) : (B))
@@ -77,6 +77,7 @@ typedef struct {
 	const Arg arg;
 } Button;
 
+typedef struct Monitor Monitor;
 typedef struct Client Client;
 struct Client {
 	char name[256];
@@ -85,10 +86,10 @@ struct Client {
 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
 	int bw, oldbw;
 	unsigned int tags;
-	unsigned int mon;
 	Bool isfixed, isfloating, isurgent;
 	Client *next;
 	Client *snext;
+	Monitor *m;
 	Window win;
 };
 
@@ -115,7 +116,12 @@ typedef struct {
 } Key;
 
 typedef struct {
-	char symbol[4];
+	const char *symbol;
+	void (*arrange)(Monitor *);
+} Layout;
+
+struct Monitor {
+	int screen_number;
 	float mfact;
 	int by, btx;          /* bar geometry */
 	int wx, wy, ww, wh;   /* window area  */
@@ -125,12 +131,8 @@ typedef struct {
 	Bool showbar;
 	Bool topbar;
 	Window barwin;
-} Monitor;
-
-typedef struct {
-	const char *symbol;
-	void (*arrange)(Monitor *);
-} Layout;
+	Monitor *next;
+};
 
 typedef struct {
 	const char *class;
@@ -149,6 +151,7 @@ static void attachstack(Client *c);
 static void buttonpress(XEvent *e);
 static void checkotherwm(void);
 static void cleanup(void);
+static void cleanupmons(void);
 static void clearurgent(Client *c);
 static void configure(Client *c);
 static void configurenotify(XEvent *e);
@@ -206,6 +209,7 @@ static void toggleview(const Arg *arg);
 static void unmanage(Client *c);
 static void unmapnotify(XEvent *e);
 static void updategeom(void);
+static void updatebars(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
@@ -252,8 +256,7 @@ static Cursor cursor[CurLast];
 static Display *dpy;
 static DC dc;
 static Layout *lt[] = { NULL, NULL };
-static Monitor *mon = NULL, *selmon = NULL;
-static unsigned int nmons = 0;
+static Monitor *mons = NULL, *selmon = NULL;
 static Window root;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
@@ -285,7 +288,7 @@ applyrules(Client *c) {
 		if(ch.res_name)
 			XFree(ch.res_name);
 	}
-	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : mon[c->mon].tagset[mon[c->mon].seltags];
+	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->m->tagset[c->m->seltags];
 }
 
 Bool
@@ -355,13 +358,14 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h) {
 
 void
 arrange(void) {
-	unsigned int i;
+	Monitor *m;
+
 	showhide(stack);
 	focus(NULL);
-	for(i = 0; i < nmons; i++) {
-		if(lt[mon[i].sellt]->arrange)
-			lt[mon[i].sellt]->arrange(&mon[i]);
-		restack(&mon[i]);
+	for(m = mons; m; m = m->next) {
+		if(lt[m->sellt]->arrange)
+			lt[m->sellt]->arrange(m);
+		restack(m);
 	}
 }
 
@@ -429,7 +433,6 @@ checkotherwm(void) {
 
 void
 cleanup(void) {
-	unsigned int i;
 	Arg a = {.ui = ~0};
 	Layout foo = { "", NULL };
 
@@ -447,14 +450,25 @@ cleanup(void) {
 	XFreeCursor(dpy, cursor[CurNormal]);
 	XFreeCursor(dpy, cursor[CurResize]);
 	XFreeCursor(dpy, cursor[CurMove]);
-	for(i = 0; i < nmons; i++)
-		XDestroyWindow(dpy, mon[i].barwin);
-	free(mon);
+	cleanupmons();
 	XSync(dpy, False);
 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
 }
 
 void
+cleanupmons(void) {
+	Monitor *m;
+
+	while(mons) {
+		m = mons->next;
+		XUnmapWindow(dpy, mons->barwin);
+		XDestroyWindow(dpy, mons->barwin);
+		free(mons);
+		mons = m;
+	}
+}
+
+void
 clearurgent(Client *c) {
 	XWMHints *wmh;
 
@@ -486,7 +500,7 @@ configure(Client *c) {
 
 void
 configurenotify(XEvent *e) {
-	unsigned int i;
+	Monitor *m;
 	XConfigureEvent *ev = &e->xconfigure;
 
 	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
@@ -496,8 +510,9 @@ configurenotify(XEvent *e) {
 		if(dc.drawable != 0)
 			XFreePixmap(dpy, dc.drawable);
 		dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
-		for(i = 0; i < nmons; i++)
-			XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh);
+		updatebars();
+		for(m = mons; m; m = m->next)
+			XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
 		arrange();
 	}
 }
@@ -526,7 +541,7 @@ configurerequest(XEvent *e) {
 				c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
 			if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
 				configure(c);
-			if(ISVISIBLE((&mon[c->mon]), c))
+			if(ISVISIBLE((c->m), c))
 				XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
 		}
 		else
@@ -588,7 +603,7 @@ drawbar(Monitor *m) {
 	Client *c;
 
 	for(c = clients; c; c = c->next) {
-		if(m == &mon[c->mon]) {
+		if(m == c->m) {
 			occ |= c->tags;
 			if(c->isurgent)
 				urg |= c->tags;
@@ -598,9 +613,11 @@ drawbar(Monitor *m) {
 	dc.x = 0;
 #ifdef XINERAMA
 	{
+		/*
 		dc.w = TEXTW(m->symbol);
-		drawtext(m->symbol, selmon == m ? dc.sel : dc.norm, False);
+		drawtext(NULL, selmon == m ? dc.sel : dc.norm, False);
 		dc.x += dc.w;
+		*/
 	}
 #endif /* XINERAMA */
 	m->btx = dc.x;
@@ -648,10 +665,10 @@ drawbar(Monitor *m) {
 
 void
 drawbars() {
-	unsigned int i;
+	Monitor *m;
 
-	for(i = 0; i < nmons; i++)
-		drawbar(&mon[i]);
+	for(m = mons; m; m = m->next)
+		drawbar(m);
 }
 
 void
@@ -718,20 +735,20 @@ enternotify(XEvent *e) {
 
 void
 expose(XEvent *e) {
-	unsigned int i;
+	Monitor *m;
 	XExposeEvent *ev = &e->xexpose;
 
 	if(ev->count == 0)
-		for(i = 0; i < nmons; i++)
-			if(ev->window == mon[i].barwin) {
-				drawbar(&mon[i]);
+		for(m = mons; m; m = m->next)
+			if(ev->window == m->barwin) {
+				drawbar(m);
 				break;
 			}
 }
 
 void
 focus(Client *c) {
-	if(!c || !ISVISIBLE((&mon[c->mon]), c))
+	if(!c || !ISVISIBLE((c->m), c))
 		for(c = stack; c && !ISVISIBLE(selmon, c); c = c->snext);
 	if(sel && sel != c) {
 		grabbuttons(sel, False);
@@ -763,11 +780,16 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */
 #ifdef XINERAMA
 void
 focusmon(const Arg *arg) {
-	if(arg->ui >= nmons)
-		return;
-	selmon = &mon[arg->ui];
-	focus(NULL);
-	drawbars();
+	unsigned int i;
+	Monitor *m; 
+
+	for(i = 0, m = mons; m; m = m->next, i++)
+		if(i == arg->ui) {
+			selmon = m;
+			focus(NULL);
+			drawbars();
+			break;
+		}
 }
 #endif /* XINERAMA */
 
@@ -993,7 +1015,7 @@ manage(Window w, XWindowAttributes *wa) {
 		die("fatal: could not malloc() %u bytes\n", sizeof(Client));
 	*c = cz;
 	c->win = w;
-	for(c->mon = 0; selmon != &mon[c->mon]; c->mon++);
+	c->m = selmon;
 
 	/* geometry */
 	c->x = wa->x;
@@ -1356,7 +1378,7 @@ setup(void) {
 	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
 
 	/* init cursors */
-	wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
+	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
 
@@ -1374,22 +1396,11 @@ setup(void) {
 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 
 	/* init bars */
-	wa.override_redirect = True;
-	wa.background_pixmap = ParentRelative;
-	wa.event_mask = ButtonPressMask|ExposureMask;
 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
 		w = TEXTW(layouts[i].symbol);
 		blw = MAX(blw, w);
 	}
-
-	for(i = 0; i < nmons; i++) {
-		mon[i].barwin = XCreateWindow(dpy, root, mon[i].wx, mon[i].by, mon[i].ww, bh, 0, DefaultDepth(dpy, screen),
-
-		                              CopyFromParent, DefaultVisual(dpy, screen),
-		                              CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
-		XDefineCursor(dpy, mon[i].barwin, cursor[CurNormal]);
-		XMapRaised(dpy, mon[i].barwin);
-	}
+	updatebars();
 	updatestatus();
 
 	/* EWMH support per view */
@@ -1410,9 +1421,9 @@ void
 showhide(Client *c) {
 	if(!c)
 		return;
-	if(ISVISIBLE((&mon[c->mon]), c)) { /* show clients top down */
+	if(ISVISIBLE((c->m), c)) { /* show clients top down */
 		XMoveWindow(dpy, c->win, c->x, c->y);
-		if(!lt[mon[c->mon].sellt]->arrange || c->isfloating)
+		if(!lt[c->m->sellt]->arrange || c->isfloating)
 			resize(c, c->x, c->y, c->w, c->h);
 		showhide(c->snext);
 	}
@@ -1453,10 +1464,15 @@ tag(const Arg *arg) {
 #ifdef XINERAMA
 void
 tagmon(const Arg *arg) {
-	if(!sel || arg->ui >= nmons)
-		return;
-	sel->mon = arg->ui;
-	arrange();
+	unsigned int i;
+	Monitor *m;
+
+	for(i = 0, m = mons; m; m = m->next, i++)
+		if(i == arg->ui) {
+			sel->m = m;
+			arrange();
+			break;
+		}
 }
 #endif /* XINERAMA */
 
@@ -1579,91 +1595,111 @@ unmapnotify(XEvent *e) {
 }
 
 void
+updatebars(void) {
+	Monitor *m;
+	XSetWindowAttributes wa;
+
+	wa.cursor = cursor[CurNormal];
+	wa.override_redirect = True;
+	wa.background_pixmap = ParentRelative;
+	wa.event_mask = ButtonPressMask|ExposureMask;
+
+	for(m = mons; m; m = m->next) {
+		m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
+
+		                          CopyFromParent, DefaultVisual(dpy, screen),
+		                          CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+		XDefineCursor(dpy, m->barwin, cursor[CurNormal]);
+		XMapRaised(dpy, m->barwin);
+	}
+}
+
+void
 updategeom(void) {
-#ifdef XINERAMA
-	int n;
-	unsigned int i = 0;
+	int i, n;
 	Client *c;
+	Monitor *newmons = NULL, *m;
+
+#ifdef XINERAMA
 	XineramaScreenInfo *info = NULL;
 
-	/* window area geometry */
-	if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
-		if(n != nmons) {
-			for(c = clients; c; c = c->next)
-				if(c->mon >= n)
-					c->mon = n - 1;
-			if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * n)))
-				die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
-			selmon = NULL;
-		}
-		for(i = 0; i < n ; i++) {
-			/* TODO: consider re-using XineramaScreenInfo */
-			mon[i].symbol[0] = '[';
-			mon[i].symbol[1] = '0' + info[i].screen_number;
-			mon[i].symbol[2] = ']';
-			mon[i].symbol[3] = 0;
-			if(!selmon) { /* not initialised yet */
-				mon[i].mfact = mfact;
-				mon[i].showbar = showbar;
-				mon[i].topbar = topbar;
-				mon[i].tagset[0] = mon[i].tagset[1] = 1;
-			}
-			mon[i].wx = info[i].x_org;
-			mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org;
-			mon[i].ww = info[i].width;
-			mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height;
-			mon[i].seltags = 0;
-			mon[i].sellt = 0;
-			if(mon[i].showbar)
-				mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh;
-			else
-				mon[i].by = -bh;
-		}
-		nmons = (unsigned int)n;
-		if(!selmon) {
-			selmon = &mon[0];
-			int di, x, y;
-			unsigned int dui;
-			Window dummy;
-			if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) 
-				for(i = 0; i < nmons; i++)
-					if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) {
-						selmon = &mon[i];
-						break;
-					}
+	if(XineramaIsActive(dpy))
+		info = XineramaQueryScreens(dpy, &n);
+#endif
+	/* allocate monitor(s) for the new geometry setup */
+	for(i = 0; i < n; i++) {
+		m = (Monitor *)malloc(sizeof(Monitor));
+		m->next = newmons;
+		newmons = m;
+	}
+
+	/* initialise monitor(s) */
+#ifdef XINERAMA
+	if(XineramaIsActive(dpy)) {
+		for(i = 0, m = newmons; m; m = m->next, i++) {
+			m->screen_number = info[i].screen_number;
+			m->wx = info[i].x_org;
+			m->wy = info[i].y_org;
+			m->ww = info[i].width;
+			m->wh = info[i].height;
 		}
 		XFree(info);
 	}
 	else
-#endif /* XINERAMA */
+#endif
+	/* default monitor setup */
 	{
-		if(!mon) {
-			nmons = 1;
-			if(!(mon = (Monitor *)malloc(sizeof(Monitor))))
-				die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
-		}
-		if(!selmon) {
-			mon[0].symbol[0] = '[';
-			mon[0].symbol[1] = '0';
-			mon[0].symbol[2] = ']';
-			mon[0].symbol[3] = 0;
-			mon[0].mfact = mfact;
-			mon[0].showbar = showbar;
-			mon[0].topbar = topbar;
-			mon[0].tagset[0] = mon[0].tagset[1] = 1;
+		m->screen_number = 0;
+		m->wx = sx;
+		m->wy = sy;
+		m->ww = sw;
+		m->wh = sh;
+	}
+
+	/* bar geometry setup */
+	for(m = newmons; m; m = m->next) {
+		/* TODO: consider removing the following values from config.h */
+		m->seltags = 0;
+		m->sellt = 0;
+		m->tagset[0] = m->tagset[1] = 1;
+		m->mfact = mfact;
+		m->showbar = showbar;
+		m->topbar = topbar;
+		if(m->showbar) {
+			m->wh -= bh;
+			m->by = m->topbar ? m->wy : m->wy + m->wh;
+			m->wy = m->topbar ? m->wy + bh : m->wy;
 		}
-		mon[0].wx = sx;
-		mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy;
-		mon[0].ww = sw;
-		mon[0].wh = mon[0].showbar ? sh - bh : sh;
-		mon[0].seltags = 0;
-		mon[0].sellt = 0;
-		if(mon[0].showbar)
-			mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh;
 		else
-			mon[0].by = -bh;
-		selmon = &mon[0];
+			m->by = -bh;
+		/* reassign all clients with same screen number */
+		for(c = clients; c; c = c->next)
+			if(c->m->screen_number == m->screen_number)
+				c->m = m;
+	}
+
+	/* reassign left over clients with disappeared screen number */
+	for(c = clients; c; c = c->next)
+		if(c->m->screen_number >= n)
+			c->m = newmons;
+
+	/* select focused monitor */
+	if(!selmon) {
+		selmon = newmons;
+		int di, x, y;
+		unsigned int dui;
+		Window dummy;
+		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;
 }
 
 void
othj5@gmail.com> 2013-12-09 23:51:13 +0000 Removed unused boolean result from autocomplete add and remove' href='/danisanti/profani-tty/commit/src/tools/autocomplete.c?id=0de1ff9b4de65ddca37186c943abf49a03cf8c30'>0de1ff9b ^
982f1174 ^
6bad38c2 ^
982f1174 ^



89d3b9fc ^
982f1174 ^

89d3b9fc ^
0de1ff9b ^
89d3b9fc ^

279737ba ^
527e739a ^
89d3b9fc ^




a85ba5e2 ^
89d3b9fc ^





4bd06a5d ^
95c48a0f ^
4bd06a5d ^












279737ba ^
954661e5 ^
89d3b9fc ^


a519d25e ^



89d3b9fc ^





b9b5d6a5 ^


a720ef26 ^
954661e5 ^
89d3b9fc ^

6bad38c2 ^
89d3b9fc ^
cc62fe37 ^
954661e5 ^
89d3b9fc ^



954661e5 ^
89d3b9fc ^

6bad38c2 ^
89d3b9fc ^
527e739a ^
89d3b9fc ^



af95c82f ^



a720ef26 ^

927af868 ^
af95c82f ^

a720ef26 ^
af95c82f ^
d6e92f62 ^

af95c82f ^



d6e92f62 ^

af95c82f ^
a720ef26 ^

af95c82f ^
a720ef26 ^

af95c82f ^

af95c82f ^
a720ef26 ^
af95c82f ^



2f3234a5 ^
af95c82f ^
a720ef26 ^

af95c82f ^



d6e92f62 ^

af95c82f ^



d6e92f62 ^
2f3234a5 ^
af95c82f ^
a720ef26 ^

af95c82f ^
a720ef26 ^

af95c82f ^



a720ef26 ^
af95c82f ^

f9b8da1a ^



f9b8da1a ^

f9b8da1a ^

e99a0e11 ^
f9b8da1a ^

f9b8da1a ^




e99a0e11 ^
36265dde ^
f9b8da1a ^
e99a0e11 ^

36265dde ^
e99a0e11 ^
f9b8da1a ^


d6e92f62 ^
f9b8da1a ^

e99a0e11 ^
f9b8da1a ^
d6e92f62 ^
f9b8da1a ^








af95c82f ^
279737ba ^
0c985110 ^
89d3b9fc ^

6bad38c2 ^
89d3b9fc ^
87c31078 ^
6bad38c2 ^
89d3b9fc ^


f5711001 ^
0c985110 ^
f5711001 ^












89d3b9fc ^





0c985110 ^
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