X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/e237b2a76fb3dac1f43b91e5c7b6adb9ef04c9ed..dba22848c7d077c1a988a901c9390dc3c8cc9d64:/dwm.c diff --git a/dwm.c b/dwm.c index 3f896dc..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); @@ -136,6 +137,7 @@ 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); @@ -163,7 +165,7 @@ void restack(void); 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); @@ -234,6 +236,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; @@ -409,11 +460,8 @@ void 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 @@ -1390,44 +1438,29 @@ setclientstate(Client *c, long state) { 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 @@ -1464,8 +1497,12 @@ setup(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);