44 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) |
44 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) |
45 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) |
45 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) |
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) \ |
|
50 void 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 */ |
51 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
59 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
52 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
60 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
53 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
61 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
135 void focusin(XEvent *e); |
147 void focusin(XEvent *e); |
136 void focusnext(const char *arg); |
148 void focusnext(const char *arg); |
137 void focusprev(const char *arg); |
149 void focusprev(const char *arg); |
138 Client *getclient(Window w); |
150 Client *getclient(Window w); |
139 unsigned long getcolor(const char *colstr); |
151 unsigned long getcolor(const char *colstr); |
140 double getdouble(const char *s); |
|
141 long getstate(Window w); |
152 long getstate(Window w); |
142 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
153 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
143 void grabbuttons(Client *c, Bool focused); |
154 void grabbuttons(Client *c, Bool focused); |
144 void grabkeys(void); |
155 void grabkeys(void); |
145 unsigned int idxoftag(const char *t); |
156 unsigned int idxoftag(const char *t); |
224 Client *sel = NULL; |
235 Client *sel = NULL; |
225 Client *stack = NULL; |
236 Client *stack = NULL; |
226 Cursor cursor[CurLast]; |
237 Cursor cursor[CurLast]; |
227 Display *dpy; |
238 Display *dpy; |
228 DC dc = {0}; |
239 DC dc = {0}; |
|
240 Geom *geom = NULL; |
229 Layout *lt = NULL; |
241 Layout *lt = NULL; |
230 Window root, barwin; |
242 Window root, barwin; |
231 |
243 |
232 /* configuration, allows nested code to access above variables */ |
244 /* configuration, allows nested code to access above variables */ |
233 #include "config.h" |
245 #include "config.h" |
234 #define TAGSZ (LENGTH(tags) * sizeof(Bool)) |
246 #define TAGSZ (LENGTH(tags) * sizeof(Bool)) |
235 static Bool tmp[LENGTH(tags)]; |
247 static Bool tmp[LENGTH(tags)]; |
236 |
248 |
237 /* function implementations */ |
249 /* function implementations */ |
238 |
|
239 void |
|
240 applygeometry(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 |
250 |
288 void |
251 void |
289 applyrules(Client *c) { |
252 applyrules(Client *c) { |
290 unsigned int i; |
253 unsigned int i; |
291 Bool matched = False; |
254 Bool matched = False; |
1436 |
1399 |
1437 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, |
1400 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, |
1438 PropModeReplace, (unsigned char *)data, 2); |
1401 PropModeReplace, (unsigned char *)data, 2); |
1439 } |
1402 } |
1440 |
1403 |
1441 double |
|
1442 getdouble(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 |
|
1459 void |
1404 void |
1460 setgeom(const char *arg) { |
1405 setgeom(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 } |
1465 |
1418 |
1466 void |
1419 void |
1495 /* init screen */ |
1448 /* init screen */ |
1496 screen = DefaultScreen(dpy); |
1449 screen = DefaultScreen(dpy); |
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); |
1509 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
1464 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
1510 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False); |
1465 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False); |