} Rule;
/* function declarations */
+void applygeom(const char *arg);
void applyrules(Client *c);
void arrange(void);
void attach(Client *c);
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);
void run(void);
void scan(void);
void setclientstate(Client *c, long state);
-void setdefgeoms(void);
+void setgeom(const char *arg);
void setlayout(const char *arg);
void setup(void);
void spawn(const char *arg);
/* 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;
configurenotify(XEvent *e) {
XConfigureEvent *ev = &e->xconfigure;
- if(ev->window == root && (ev->width != sw || ev->height != sh)) {
- setgeoms();
- updatebarpos();
- arrange();
- }
+ if(ev->window == root && (ev->width != sw || ev->height != sh))
+ setgeom(NULL);
}
void
PropModeReplace, (unsigned char *)data, 2);
}
-void
-setdefgeoms(void) {
-
- /* screen dimensions */
- sx = 0;
- sy = 0;
- sw = DisplayWidth(dpy, screen);
- sh = DisplayHeight(dpy, screen);
-
- /* bar position */
- bx = sx;
- by = sy;
- bw = sw;
- bh = dc.font.height + 2;
-
- /* window area */
- wx = sx;
- wy = sy + bh;
- ww = sw;
- wh = sh - bh;
-
- /* master area */
- mx = wx;
- my = wy;
- mw = ((float)sw) * 0.55;
- mh = wh;
-
- /* tile area */
- tx = mx + mw;
- ty = wy;
- tw = ww - mw;
- th = wh;
+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;
+}
- /* monocle area */
- mox = wx;
- moy = wy;
- mow = ww;
- moh = wh;
+void
+setgeom(const char *arg) {
+ applygeometry(arg);
+ updatebarpos();
+ arrange();
}
void
root = RootWindow(dpy, screen);
initfont(FONT);
- /* apply default geometries */
- setgeoms();
+ /* apply default dimensions */
+ sx = 0;
+ sy = 0;
+ sw = DisplayWidth(dpy, screen);
+ sh = DisplayHeight(dpy, screen);
+ applygeometry(GEOMETRY);
/* init atoms */
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);