summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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 @@
46#define LENGTH(x) (sizeof x / sizeof x[0]) 46#define LENGTH(x) (sizeof x / sizeof x[0])
47#define MAXTAGLEN 16 47#define MAXTAGLEN 16
48#define MOUSEMASK (BUTTONMASK|PointerMotionMask) 48#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
49#define DEFGEOM(GEONAME,BX,BY,BW,WX,WY,WW,WH,MX,MY,MW,MH,TX,TY,TW,TH,MOX,MOY,MOW,MOH) \
50void GEONAME(void) { \
51 bx = (BX); by = (BY); bw = (BW); \
52 wx = (WX); wy = (WY); ww = (WW); wh = (WH); \
53 mx = (MX); my = (MY); mw = (MW); mh = (MH); \
54 tx = (TX); ty = (TY); tw = (TW); th = (TH); \
55 mox = (MOX); moy = (MOY); mow = (MOW); moh = (MOH); \
56}
49 57
50/* enums */ 58/* enums */
51enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 59enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
@@ -86,6 +94,11 @@ typedef struct {
86} DC; /* draw context */ 94} DC; /* draw context */
87 95
88typedef struct { 96typedef struct {
97 const char *symbol;
98 void (*apply)(void);
99} Geom;
100
101typedef struct {
89 unsigned long mod; 102 unsigned long mod;
90 KeySym keysym; 103 KeySym keysym;
91 void (*func)(const char *arg); 104 void (*func)(const char *arg);
@@ -107,7 +120,6 @@ typedef struct {
107} Rule; 120} Rule;
108 121
109/* function declarations */ 122/* function declarations */
110void applygeom(const char *arg);
111void applyrules(Client *c); 123void applyrules(Client *c);
112void arrange(void); 124void arrange(void);
113void attach(Client *c); 125void attach(Client *c);
@@ -137,7 +149,6 @@ void focusnext(const char *arg);
137void focusprev(const char *arg); 149void focusprev(const char *arg);
138Client *getclient(Window w); 150Client *getclient(Window w);
139unsigned long getcolor(const char *colstr); 151unsigned long getcolor(const char *colstr);
140double getdouble(const char *s);
141long getstate(Window w); 152long getstate(Window w);
142Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 153Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
143void grabbuttons(Client *c, Bool focused); 154void grabbuttons(Client *c, Bool focused);
@@ -226,6 +237,7 @@ Client *stack = NULL;
226Cursor cursor[CurLast]; 237Cursor cursor[CurLast];
227Display *dpy; 238Display *dpy;
228DC dc = {0}; 239DC dc = {0};
240Geom *geom = NULL;
229Layout *lt = NULL; 241Layout *lt = NULL;
230Window root, barwin; 242Window root, barwin;
231 243
@@ -237,55 +249,6 @@ static Bool tmp[LENGTH(tags)];
237/* function implementations */ 249/* function implementations */
238 250
239void 251void
240applygeometry(const char *arg) {
241 static const char *lastArg = NULL;
242 char delim, op, *s, *e, *p;
243 double val;
244 int i, *map[] = { &bx, &by, &bw, &bh,
245 &wx, &wy, &ww, &wh,
246 &mx, &my, &mw, &mh,
247 &tx, &ty, &tw, &th,
248 &mox, &moy, &mow, &moh };
249
250 if(!arg)
251 arg = lastArg;
252 else
253 lastArg = arg;
254 if(!lastArg)
255 return;
256 strncpy(buf, arg, sizeof buf);
257 for(i = 0, e = s = buf; i < LENGTH(map) && e; e++)
258 if(*e == ' ' || *e == 0) {
259 delim = *e;
260 *e = 0;
261 op = 0;
262 /* check if there is an operator */
263 for(p = s; p < e && *p != '-' && *p != '+' && *p != '*'; p++);
264 if(*p) {
265 op = *p;
266 *p = 0;
267 }
268 val = getdouble(s);
269 if(op && p > s) { /* intermediate operand, e.g. H-B */
270 *(map[i]) = (int)val;
271 s = ++p;
272 val = getdouble(s);
273 }
274 switch(op) {
275 default: *(map[i]) = (int)val; break;
276 case '-': *(map[i]) -= (int)val; break;
277 case '+': *(map[i]) += (int)val; break;
278 case '*': *(map[i]) = (int)(((double)*(map[i])) * val); break;
279 }
280 if(delim == 0)
281 e = NULL;
282 else
283 s = ++e;
284 i++;
285 }
286}
287
288void
289applyrules(Client *c) { 252applyrules(Client *c) {
290 unsigned int i; 253 unsigned int i;
291 Bool matched = False; 254 Bool matched = False;
@@ -1438,27 +1401,17 @@ setclientstate(Client *c, long state) {
1438 PropModeReplace, (unsigned char *)data, 2); 1401 PropModeReplace, (unsigned char *)data, 2);
1439} 1402}
1440 1403
1441double
1442getdouble(const char *s) {
1443 char *endp;
1444 double result = 0;
1445
1446 switch(*s) {
1447 default:
1448 result = strtod(s, &endp);
1449 if(s == endp || *endp != 0)
1450 result = strtol(s, &endp, 0);
1451 break;
1452 case 'B': result = dc.font.height + 2; break;
1453 case 'W': result = sw; break;
1454 case 'H': result = sh; break;
1455 }
1456 return result;
1457}
1458
1459void 1404void
1460setgeom(const char *arg) { 1405setgeom(const char *arg) {
1461 applygeometry(arg); 1406 unsigned int i;
1407
1408 for(i = 0; arg && i < LENGTH(geoms); i++)
1409 if(!strcmp(geoms[i].symbol, arg))
1410 break;
1411 if(i == LENGTH(geoms))
1412 return;
1413 geom = &geoms[i];
1414 geom->apply();
1462 updatebarpos(); 1415 updatebarpos();
1463 arrange(); 1416 arrange();
1464} 1417}
@@ -1497,12 +1450,14 @@ setup(void) {
1497 root = RootWindow(dpy, screen); 1450 root = RootWindow(dpy, screen);
1498 initfont(FONT); 1451 initfont(FONT);
1499 1452
1500 /* apply default dimensions */ 1453 /* apply default geometry */
1501 sx = 0; 1454 sx = 0;
1502 sy = 0; 1455 sy = 0;
1503 sw = DisplayWidth(dpy, screen); 1456 sw = DisplayWidth(dpy, screen);
1504 sh = DisplayHeight(dpy, screen); 1457 sh = DisplayHeight(dpy, screen);
1505 applygeometry(GEOMETRY); 1458 bh = dc.font.height + 2;
1459 geom = &geoms[0];
1460 geom->apply();
1506 1461
1507 /* init atoms */ 1462 /* init atoms */
1508 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 1463 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);