about summary refs log tree commit diff stats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c99
1 files changed, 27 insertions, 72 deletions
diff --git a/dwm.c b/dwm.c
index 4a9ca82..f83e800 100644
--- a/dwm.c
+++ b/dwm.c
@@ -46,6 +46,14 @@
 #define LENGTH(x)		(sizeof x / sizeof x[0])
 #define MAXTAGLEN		16
 #define MOUSEMASK		(BUTTONMASK|PointerMotionMask)
+#define DEFGEOM(GEONAME,BX,BY,BW,WX,WY,WW,WH,MX,MY,MW,MH,TX,TY,TW,TH,MOX,MOY,MOW,MOH) \
+void GEONAME(void) { \
+	bx = (BX); by = (BY); bw = (BW); \
+	wx = (WX); wy = (WY); ww = (WW); wh = (WH); \
+	mx = (MX); my = (MY); mw = (MW); mh = (MH); \
+	tx = (TX); ty = (TY); tw = (TW); th = (TH); \
+	mox = (MOX); moy = (MOY); mow = (MOW); moh = (MOH); \
+}
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };	/* cursor */
@@ -86,6 +94,11 @@ typedef struct {
 } DC; /* draw context */
 
 typedef struct {
+	const char *symbol;
+	void (*apply)(void);
+} Geom;
+
+typedef struct {
 	unsigned long mod;
 	KeySym keysym;
 	void (*func)(const char *arg);
@@ -107,7 +120,6 @@ typedef struct {
 } Rule;
 
 /* function declarations */
-void applygeom(const char *arg);
 void applyrules(Client *c);
 void arrange(void);
 void attach(Client *c);
@@ -137,7 +149,6 @@ void focusnext(const char *arg);
 void focusprev(const char *arg);
 Client *getclient(Window w);
 unsigned long getcolor(const char *colstr);
-double getdouble(const char *s);
 long getstate(Window w);
 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 void grabbuttons(Client *c, Bool focused);
@@ -226,6 +237,7 @@ Client *stack = NULL;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
+Geom *geom = NULL;
 Layout *lt = NULL;
 Window root, barwin;
 
@@ -237,55 +249,6 @@ static Bool tmp[LENGTH(tags)];
 /* function implementations */
 
 void
-applygeometry(const char *arg) {
-	static const char *lastArg = NULL;
-	char delim, op, *s, *e, *p;
-	double val;
-	int i, *map[] = { &bx,  &by,  &bw,  &bh,
-	                  &wx,  &wy,  &ww,  &wh,
-	                  &mx,  &my,  &mw,  &mh,
-	                  &tx,  &ty,  &tw,  &th,
-	                  &mox, &moy, &mow, &moh };
-
-	if(!arg)
-		arg = lastArg;
-	else
-		lastArg = arg;
-	if(!lastArg)
-		return;
-	strncpy(buf, arg, sizeof buf);
-	for(i = 0, e = s = buf; i < LENGTH(map) && e; e++)
-		if(*e == ' ' || *e == 0) {
-			delim = *e;
-			*e = 0;
-			op = 0;
-			/* check if there is an operator */
-			for(p = s; p < e && *p != '-' && *p != '+' && *p != '*'; p++);
-			if(*p) {
-				op = *p;
-				*p = 0;
-			}
-			val = getdouble(s);
-			if(op && p > s) { /* intermediate operand, e.g. H-B */
-				*(map[i]) = (int)val;
-				s = ++p;
-				val = getdouble(s);
-			}
-			switch(op) {
-			default:  *(map[i])  = (int)val; break;
-			case '-': *(map[i]) -= (int)val; break;
-			case '+': *(map[i]) += (int)val; break;
-			case '*': *(map[i])  = (int)(((double)*(map[i])) * val); break;
-			}
-			if(delim == 0)
-				e = NULL;
-			else
-				s = ++e;
-			i++;
-		}
-}
-
-void
 applyrules(Client *c) {
 	unsigned int i;
 	Bool matched = False;
@@ -1438,27 +1401,17 @@ setclientstate(Client *c, long state) {
 			PropModeReplace, (unsigned char *)data, 2);
 }
 
-double
-getdouble(const char *s) {
-	char *endp;
-	double result = 0;
-
-	switch(*s) {
-	default: 
-		result = strtod(s, &endp);
-		if(s == endp || *endp != 0)
-			result = strtol(s, &endp, 0);
-		break;
-	case 'B': result = dc.font.height + 2; break;
-	case 'W': result = sw; break;
-	case 'H': result = sh; break;
-	}
-	return result;
-}
-
 void
 setgeom(const char *arg) {
-	applygeometry(arg);
+	unsigned int i;
+
+	for(i = 0; arg && i < LENGTH(geoms); i++)
+		if(!strcmp(geoms[i].symbol, arg))
+			break;
+	if(i == LENGTH(geoms))
+		return;
+	geom = &geoms[i];
+	geom->apply();
 	updatebarpos();
 	arrange();
 }
@@ -1497,12 +1450,14 @@ setup(void) {
 	root = RootWindow(dpy, screen);
 	initfont(FONT);
 
-	/* apply default dimensions */
+	/* apply default geometry */
 	sx = 0;
 	sy = 0;
 	sw = DisplayWidth(dpy, screen);
 	sh = DisplayHeight(dpy, screen);
-	applygeometry(GEOMETRY);
+	bh = dc.font.height + 2;
+	geom = &geoms[0];
+	geom->apply();
 
 	/* init atoms */
 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
ml/021arithmetic.cc.html?h=main&id=672e3e50c6ed6de161e40aa256c3fc0f2b1f7cf9'>672e3e50 ^
9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^


672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^

9542bb11 ^


90560d71 ^









65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^


672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^






65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^


672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^

9542bb11 ^


90560d71 ^









65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^




672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^
4fe9f5e8 ^
90560d71 ^

9542bb11 ^

90560d71 ^





65361948 ^


672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^
672e3e50 ^
65361948 ^



9570363a ^
65361948 ^

c5ffb6e1 ^

90560d71 ^
c5ffb6e1 ^

90560d71 ^
c5ffb6e1 ^

672e3e50 ^



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