about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2008-03-15 14:17:42 +0000
committerAnselm R Garbe <garbeam@gmail.com>2008-03-15 14:17:42 +0000
commitdba22848c7d077c1a988a901c9390dc3c8cc9d64 (patch)
treeb3e91f7a977bbb9debd6120df8058f112cc883b2
parent33b1960220f468ff2888e8ba3517e9a62ed99974 (diff)
downloaddwm-dba22848c7d077c1a988a901c9390dc3c8cc9d64.tar.gz
made the string-based setgeom working
-rw-r--r--config.def.h16
-rw-r--r--config.mk2
-rw-r--r--dwm.c125
3 files changed, 68 insertions, 75 deletions
diff --git a/config.def.h b/config.def.h
index 0866e2e..f6d90d8 100644
--- a/config.def.h
+++ b/config.def.h
@@ -9,7 +9,19 @@
 #define SELBORDERCOLOR		"#0066ff"
 #define SELBGCOLOR		"#0066ff"
 #define SELFGCOLOR		"#ffffff"
-#define GEOMETRY		"0 0 W B 0 B W H-B 0 B W*0.55 H-B W*0.45 B H-B 0 B W H-B"
+#define GEOMETRY		"0 0 W B " \
+				"0 B W H-B " \
+				"0 B W*0.55 H-B " \
+				"W*0.55 B W*0.45 H-B " \
+				"0 B W H-B"
+
+/* Anselm's dual head geometry in the office */
+#define DUALGEOMETRY		"0 0 1280 B " \
+				"0 B W H-B " \
+				"0 B 1280 800-B " \
+				"1280 0 W-1280 H " \
+				"0 B 1280 800-B"
+
 
 /* tagging */
 const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
@@ -38,7 +50,7 @@ Layout layouts[] = {
 #define MODKEY			Mod1Mask
 Key keys[] = {
 	/* modifier			key		function	argument */
-	{ MODKEY,			XK_a,		setgeom,	"0 0 W B 0 B W H-B 0 B 1280 800-B 1280 0 W-1280 H 0 B 1280 800-B" },
+	{ MODKEY,			XK_a,		setgeom,	DUALGEOMETRY },
 	{ MODKEY,			XK_d,		setgeom,	GEOMETRY },
 	{ MODKEY,			XK_p,		spawn,
 		"exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
diff --git a/config.mk b/config.mk
index 5176248..f365e8f 100644
--- a/config.mk
+++ b/config.mk
@@ -17,7 +17,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
 # flags
 CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
 LDFLAGS = -s ${LIBS}
-#CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" -DWORK
+#CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
 #LDFLAGS = -g ${LIBS}
 
 # Solaris
diff --git a/dwm.c b/dwm.c
index 5d93d34..4a9ca82 100644
--- a/dwm.c
+++ b/dwm.c
@@ -107,6 +107,7 @@ typedef struct {
 } Rule;
 
 /* function declarations */
+void applygeom(const char *arg);
 void applyrules(Client *c);
 void arrange(void);
 void attach(Client *c);
@@ -236,6 +237,55 @@ 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;
@@ -410,11 +460,8 @@ void
 configurenotify(XEvent *e) {
 	XConfigureEvent *ev = &e->xconfigure;
 
-	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
+	if(ev->window == root && (ev->width != sw || ev->height != sh))
 		setgeom(NULL);
-		updatebarpos();
-		arrange();
-	}
 }
 
 void
@@ -1391,31 +1438,11 @@ setclientstate(Client *c, long state) {
 			PropModeReplace, (unsigned char *)data, 2);
 }
 
-/**
- * Idea:
- *
- * having a geom syntax as follows, which is interpreted as integer.
- *
- * [-,+][<0..n>|<W,H,B>]
- *
- *
- * B = bar height, W = DisplayWidth(), H = DisplayHeight()
- *
- * -/+/* /: is relative to current
- *
- * Then we would come down with <bx>,<by>,<bw>,<bh>,...
- *
- * "0 0 W B 0 0 W W N E B,W,B,
- *
- *
- */
-
 double
 getdouble(const char *s) {
 	char *endp;
 	double result = 0;
 
-	fprintf(stderr, "getdouble '%s'\n", s);
 	switch(*s) {
 	default: 
 		result = strtod(s, &endp);
@@ -1426,58 +1453,12 @@ getdouble(const char *s) {
 	case 'W': result = sw; break;
 	case 'H': result = sh; break;
 	}
-	fprintf(stderr, "getdouble returns '%f'\n", result);
 	return result;
 }
 
 void
 setgeom(const char *arg) {
-	static const char *lastArg = NULL;
-	char 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; e && *e; e++)
-		if(*e == ' ') {
-			*e = 0;
-			fprintf(stderr, "next geom arg='%s'\n", s);
-			op = 0;
-			/* check if there is an operator */
-			for(p = s; *p && *p != '-' && *p != '+' && *p != '*' && *p != ':'; p++);
-			if(*p) {
-				op = *p;
-				*p = 0;
-			}
-			val = getdouble(s);
-			fprintf(stderr, "val1: %d\n", val);
-			if(p > s) { /* intermediate operand, e.g. H-B */
-				*(map[i]) = val;
-				s = ++p;
-				val = getdouble(s);
-				fprintf(stderr, "val2: %d\n", val);
-			}
-			switch(op) {
-			default: *(map[i])   = val; break;
-			case '-': *(map[i]) -= val; break;
-			case '+': *(map[i]) += val; break;
-			case '*': *(map[i]) *= val; break;
-			case ':': if(val != 0) *(map[i]) /= val; break;
-			}
-			fprintf(stderr, "map[i]='%d'\n", val);
-			s = ++e;
-			i++;
-		}
+	applygeometry(arg);
 	updatebarpos();
 	arrange();
 }
@@ -1521,7 +1502,7 @@ setup(void) {
 	sy = 0;
 	sw = DisplayWidth(dpy, screen);
 	sh = DisplayHeight(dpy, screen);
-	setgeom(GEOMETRY);
+	applygeometry(GEOMETRY);
 
 	/* init atoms */
 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
155c661288bc7dcd05'>b63d287c ^
c82d2a40 ^
8f8c57cc ^

b63d287c ^

8f8c57cc ^




b63d287c ^



8f8c57cc ^

899516a7 ^
8f8c57cc ^




d3f9d547 ^
8f8c57cc ^


b63d287c ^



8f8c57cc ^

8f8c57cc ^








8f8c57cc ^

b63d287c ^


8f8c57cc ^



899516a7 ^
8f8c57cc ^









d3f9d547 ^
8f8c57cc ^


d3f9d547 ^
8f8c57cc ^
d3f9d547 ^
8f8c57cc ^








08fc6e5c ^
8f8c57cc ^
d3f9d547 ^
8f8c57cc ^




c82d2a40 ^
8f8c57cc ^

d3f9d547 ^
8f8c57cc ^




d3f9d547 ^

8f8c57cc ^





d3f9d547 ^
8f8c57cc ^



d3f9d547 ^
06cddc6b ^
8f8c57cc ^
d3f9d547 ^
8f8c57cc ^
c82d2a40 ^
8f8c57cc ^
b63d287c ^
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