about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-19 13:00:29 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-19 13:00:29 +0100
commit5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63 (patch)
tree2025c7842831bd512df4816717e5e47160f99f7c
parent39ed54a468f339535f82cce2c0a79b92e74a7c09 (diff)
downloaddwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.tar.gz
introduced tile.c, some refactoring of functions
-rw-r--r--Makefile2
-rw-r--r--config.arg.h2
-rw-r--r--config.default.h2
-rw-r--r--dwm.h13
-rw-r--r--main.c2
-rw-r--r--tag.c2
-rw-r--r--tile.c132
-rw-r--r--view.c136
8 files changed, 150 insertions, 141 deletions
diff --git a/Makefile b/Makefile
index e337ec2..18626a7 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
 
 include config.mk
 
-SRC = client.c draw.c event.c main.c tag.c util.c view.c
+SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c
 OBJ = ${SRC:.c=.o}
 
 all: options dwm
diff --git a/config.arg.h b/config.arg.h
index 2b94fd6..fae30d0 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -5,11 +5,11 @@
 #define TAGS \
 const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
 
-#define BORDERPX		1
 #define DEFMODE			dotile		/* dofloat */
 #define FLOATSYMBOL		"><>"
 #define TILESYMBOL		"[]="
 
+#define BORDERPX		1
 #define FONT			"-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
 #define NORMBORDERCOLOR		"#333"
 #define NORMBGCOLOR		"#222"
diff --git a/config.default.h b/config.default.h
index b8654bd..c1274a1 100644
--- a/config.default.h
+++ b/config.default.h
@@ -5,11 +5,11 @@
 #define TAGS \
 const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
 
-#define BORDERPX		1
 #define DEFMODE			dotile		/* dofloat */
 #define FLOATSYMBOL		"><>"
 #define TILESYMBOL		"[]="
 
+#define BORDERPX		1
 #define FONT			"-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
 #define NORMBORDERCOLOR		"#dddddd"
 #define NORMBGCOLOR		"#eeeeee"
diff --git a/dwm.h b/dwm.h
index 43b3730..c07229a 100644
--- a/dwm.h
+++ b/dwm.h
@@ -127,11 +127,17 @@ extern void sendevent(Window w, Atom a, long value);	/* send synthetic event to
 extern int xerror(Display *dsply, XErrorEvent *ee);	/* dwm's X error handler */
 
 /* tag.c */
-extern void initrregs(void);			/* initialize regexps of rules defined in config.h */
+extern void compileregexps(void);		/* initialize regexps of rules defined in config.h */
 extern void settags(Client *c, Client *trans);	/* sets tags of c */
 extern void tag(Arg *arg);			/* tags c with arg's index */
 extern void toggletag(Arg *arg);		/* toggles c tags with arg's index */
 
+/* tile.c */
+extern void dotile(void);			/* arranges all windows tiled */
+extern void incnmaster(Arg *arg);		/* increments nmaster with arg's index value */
+extern void resizemaster(Arg *arg);		/* resizes the master percent with arg's index value */
+extern void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
+
 /* util.c */
 extern void *emallocz(unsigned int size);	/* allocates zero-initialized memory, exits on error */
 extern void eprint(const char *errstr, ...);	/* prints errstr and exits with 1 */
@@ -140,15 +146,12 @@ extern void spawn(Arg *arg);			/* forks a new subprocess with to arg's cmd */
 /* view.c */
 extern void detach(Client *c);			/* detaches c from global client list */
 extern void dofloat(void);			/* arranges all windows floating */
-extern void dotile(void);			/* arranges all windows tiled */
 extern void focusnext(Arg *arg);		/* focuses next visible client, arg is ignored  */
 extern void focusprev(Arg *arg);		/* focuses previous visible client, arg is ignored */
-extern void incnmaster(Arg *arg);		/* increments nmaster with arg's index value */
 extern Bool isvisible(Client *c);		/* returns True if client is visible */
-extern void resizemaster(Arg *arg);		/* resizes the master percent with arg's index value */
+extern Client *nextmanaged(Client *c);		/* returns managed successor of c */
 extern void restack(void);			/* restores z layers of all clients */
 extern void togglefloat(Arg *arg);		/* toggles focusesd client between floating/non-floating state */
 extern void togglemode(Arg *arg);		/* toggles global arrange function (dotile/dofloat) */
 extern void toggleview(Arg *arg);		/* toggles the tag with arg's index (in)visible */
 extern void view(Arg *arg);			/* views the tag with arg's index */
-extern void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
diff --git a/main.c b/main.c
index 5ed8981..bd19e49 100644
--- a/main.c
+++ b/main.c
@@ -117,7 +117,7 @@ setup(void) {
 	wa.cursor = cursor[CurNormal];
 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
 	grabkeys();
-	initrregs();
+	compileregexps();
 	for(ntags = 0; tags[ntags]; ntags++);
 	seltag = emallocz(sizeof(Bool) * ntags);
 	seltag[0] = True;
diff --git a/tag.c b/tag.c
index a6db1d5..d3065d5 100644
--- a/tag.c
+++ b/tag.c
@@ -32,7 +32,7 @@ static unsigned int len = 0;
 /* extern */
 
 void
-initrregs(void) {
+compileregexps(void) {
 	unsigned int i;
 	regex_t *reg;
 
diff --git a/tile.c b/tile.c
new file mode 100644
index 0000000..a9bc0f5
--- /dev/null
+++ b/tile.c
@@ -0,0 +1,132 @@
+/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+#include "dwm.h"
+
+/* static */
+
+static void
+togglemax(Client *c) {
+	XEvent ev;
+		
+	if(c->isfixed)
+		return;
+
+	if((c->ismax = !c->ismax)) {
+		c->rx = c->x;
+		c->ry = c->y;
+		c->rw = c->w;
+		c->rh = c->h;
+		resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
+	}
+	else
+		resize(c, c->rx, c->ry, c->rw, c->rh, True);
+	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+}
+
+/* extern */
+
+void
+dotile(void) {
+	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
+	Client *c;
+
+	for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
+		n++;
+	/* window geoms */
+	mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
+	mw = (n > nmaster) ? (waw * master) / 1000 : waw;
+	th = (n > nmaster) ? wah / (n - nmaster) : 0;
+	tw = waw - mw;
+
+	for(i = 0, c = clients; c; c = c->next)
+		if(isvisible(c)) {
+			if(c->isbanned)
+				XMoveWindow(dpy, c->win, c->x, c->y);
+			c->isbanned = False;
+			if(c->isfloat)
+				continue;
+			c->ismax = False;
+			nx = wax;
+			ny = way;
+			if(i < nmaster) {
+				ny += i * mh;
+				nw = mw - 2 * BORDERPX;
+				nh = mh - 2 * BORDERPX;
+			}
+			else {  /* tile window */
+				nx += mw;
+				nw = tw - 2 * BORDERPX;
+				if(th > 2 * BORDERPX) {
+					ny += (i - nmaster) * th;
+					nh = th - 2 * BORDERPX;
+				}
+				else /* fallback if th <= 2 * BORDERPX */
+					nh = wah - 2 * BORDERPX;
+			}
+			resize(c, nx, ny, nw, nh, False);
+			i++;
+		}
+		else {
+			c->isbanned = True;
+			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+		}
+	if(!sel || !isvisible(sel)) {
+		for(c = stack; c && !isvisible(c); c = c->snext);
+		focus(c);
+	}
+	restack();
+}
+
+void
+incnmaster(Arg *arg) {
+	if((arrange == dofloat) || (nmaster + arg->i < 1)
+	|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
+		return;
+	nmaster += arg->i;
+	if(sel)
+		arrange();
+	else
+		drawstatus();
+}
+
+void
+resizemaster(Arg *arg) {
+	if(arrange != dotile)
+		return;
+	if(arg->i == 0)
+		master = MASTER;
+	else {
+		if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
+		|| waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
+			return;
+		master += arg->i;
+	}
+	arrange();
+}
+
+void
+zoom(Arg *arg) {
+	unsigned int n;
+	Client *c;
+
+	if(!sel)
+		return;
+	if(sel->isfloat || (arrange == dofloat)) {
+		togglemax(sel);
+		return;
+	}
+	for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
+		n++;
+
+	if((c = sel) == nextmanaged(clients))
+		if(!(c = nextmanaged(c->next)))
+			return;
+	detach(c);
+	if(clients)
+		clients->prev = c;
+	c->next = clients;
+	clients = c;
+	focus(c);
+	arrange();
+}
diff --git a/view.c b/view.c
index 66f550c..72aa04e 100644
--- a/view.c
+++ b/view.c
@@ -2,34 +2,6 @@
  * See LICENSE file for license details.
  */
 #include "dwm.h"
-#include <stdio.h>
-
-/* static */
-
-static Client *
-nexttiled(Client *c) {
-	for(; c && (c->isfloat || !isvisible(c)); c = c->next);
-	return c;
-}
-
-static void
-togglemax(Client *c) {
-	XEvent ev;
-		
-	if(c->isfixed)
-		return;
-
-	if((c->ismax = !c->ismax)) {
-		c->rx = c->x;
-		c->ry = c->y;
-		c->rw = c->w;
-		c->rh = c->h;
-		resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
-	}
-	else
-		resize(c, c->rx, c->ry, c->rw, c->rh, True);
-	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
-}
 
 /* extern */
 
@@ -70,58 +42,6 @@ dofloat(void) {
 }
 
 void
-dotile(void) {
-	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
-	Client *c;
-
-	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
-		n++;
-	/* window geoms */
-	mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
-	mw = (n > nmaster) ? (waw * master) / 1000 : waw;
-	th = (n > nmaster) ? wah / (n - nmaster) : 0;
-	tw = waw - mw;
-
-	for(i = 0, c = clients; c; c = c->next)
-		if(isvisible(c)) {
-			if(c->isbanned)
-				XMoveWindow(dpy, c->win, c->x, c->y);
-			c->isbanned = False;
-			if(c->isfloat)
-				continue;
-			c->ismax = False;
-			nx = wax;
-			ny = way;
-			if(i < nmaster) {
-				ny += i * mh;
-				nw = mw - 2 * BORDERPX;
-				nh = mh - 2 * BORDERPX;
-			}
-			else {  /* tile window */
-				nx += mw;
-				nw = tw - 2 * BORDERPX;
-				if(th > 2 * BORDERPX) {
-					ny += (i - nmaster) * th;
-					nh = th - 2 * BORDERPX;
-				}
-				else /* fallback if th <= 2 * BORDERPX */
-					nh = wah - 2 * BORDERPX;
-			}
-			resize(c, nx, ny, nw, nh, False);
-			i++;
-		}
-		else {
-			c->isbanned = True;
-			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-		}
-	if(!sel || !isvisible(sel)) {
-		for(c = stack; c && !isvisible(c); c = c->snext);
-		focus(c);
-	}
-	restack();
-}
-
-void
 focusnext(Arg *arg) {
 	Client *c;
    
@@ -153,18 +73,6 @@ focusprev(Arg *arg) {
 	}
 }
 
-void
-incnmaster(Arg *arg) {
-	if((arrange == dofloat) || (nmaster + arg->i < 1)
-	|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
-		return;
-	nmaster += arg->i;
-	if(sel)
-		arrange();
-	else
-		drawstatus();
-}
-
 Bool
 isvisible(Client *c) {
 	unsigned int i;
@@ -175,19 +83,10 @@ isvisible(Client *c) {
 	return False;
 }
 
-void
-resizemaster(Arg *arg) {
-	if(arrange != dotile)
-		return;
-	if(arg->i == 0)
-		master = MASTER;
-	else {
-		if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
-		|| waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
-			return;
-		master += arg->i;
-	}
-	arrange();
+Client *
+nextmanaged(Client *c) {
+	for(; c && (c->isfloat || !isvisible(c)); c = c->next);
+	return c;
 }
 
 void
@@ -203,7 +102,7 @@ restack(void) {
 	if(arrange != dofloat) {
 		if(!sel->isfloat)
 			XLowerWindow(dpy, sel->win);
-		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
+		for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
 			if(c == sel)
 				continue;
 			XLowerWindow(dpy, c->win);
@@ -252,28 +151,3 @@ view(Arg *arg) {
 	arrange();
 }
 
-void
-zoom(Arg *arg) {
-	unsigned int n;
-	Client *c;
-
-	if(!sel)
-		return;
-	if(sel->isfloat || (arrange == dofloat)) {
-		togglemax(sel);
-		return;
-	}
-	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
-		n++;
-
-	if((c = sel) == nexttiled(clients))
-		if(!(c = nexttiled(c->next)))
-			return;
-	detach(c);
-	if(clients)
-		clients->prev = c;
-	c->next = clients;
-	clients = c;
-	focus(c);
-	arrange();
-}
color stuff/new rendering stuff' href='/acidbong/suckless/dwm/commit/main.c?h=6.4&id=b55bd709ee6d0b09c141bf5ffe0647866e0374ef'>b55bd70 ^
b5159df ^
6651dd7 ^
10885d3 ^
b5159df ^


6fc8a63 ^
0b80d18 ^
6651dd7 ^
931e712 ^

b5159df ^
b55bd70 ^
b5159df ^







6651dd7 ^
b003a35 ^

931e712 ^
b003a35 ^

6651dd7 ^
b5159df ^

2e834e9 ^
6651dd7 ^
b5159df ^
b5159df ^

adaa28a ^




ca65478 ^
adaa28a ^



bf35794 ^

3399650 ^
ca65478 ^
0ff8065 ^
352e1b4 ^

3399650 ^
0ff8065 ^


352e1b4 ^
3399650 ^
0ff8065 ^
c09bf8d ^
080a38d ^
352e1b4 ^
3399650 ^



ca65478 ^
3399650 ^








e6cbe9c ^
3399650 ^

adaa28a ^
ca65478 ^
727449d ^
1076f2b

6651dd7 ^
bf35794 ^
b597fa4 ^
dba2306 ^

ca65478 ^
dba2306 ^
dc5d967 ^




1d7674b ^

dba2306 ^

dc5d967 ^
b597fa4 ^
4641aa2 ^

1076f2b
ca65478 ^
61a1910 ^
b5159df ^
dc5d967 ^
1076f2b
4970ef9 ^
ac24f13 ^
4970ef9 ^
1076f2b
4970ef9 ^

d42c3ba ^
1076f2b

86d1224 ^
e571de8 ^
1076f2b

dba2306 ^

86d1224 ^
1076f2b
f60c597 ^
dba2306 ^

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

e571de8 ^
478f6f9 ^


61a1910 ^
478f6f9 ^

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


35e96b8 ^
478f6f9 ^


2210ea7 ^

61a1910 ^

0e5c819 ^
478f6f9 ^
0e5c819 ^
478f6f9 ^

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