On Sat, Mar 15, 2008 at 05:55:11PM -0300, Brendan MacDonell wrote:
> On Sat, Mar 15, 2008 at 5:30 PM, Johannes Hofmann
> <[EMAIL PROTECTED]> wrote:
> >  Huh? That's a config parser in dwm!
> Luckily I'd say, since otherwise we'd seem to be stuck hardcoding
> values for screen sizes as 24-line functions for each set of geoms.
> This config parser isn't really much different from the regexes that
> were used in config.h for matching windows, nor is it difficult to
> understand, so I have no objections.

What do you think of the attached patch (against 4.8)? It reduces
the setgeoms() function a bit - agreed, not very much :-)
But you only need a custom setgeoms () function for multiscreen
setups anyway.

 Johannes
diff --git a/config.anselm.h b/config.anselm.h
--- a/config.anselm.h
+++ b/config.anselm.h
@@ -37,40 +37,34 @@ setanselmgeoms(void) {
 setanselmgeoms(void) {
 
        /* screen dimensions */
-       sx = 0;
-       sy = 0;
-       sw = DisplayWidth(dpy, screen);
-       sh = DisplayHeight(dpy, screen);
+       scr.x = 0;
+       scr.y = 0;
+       scr.w = DisplayWidth(dpy, screen);
+       scr.h = DisplayHeight(dpy, screen);
 
        /* bar position */
-       bx = sx;
-       by = sy;
-       bw = 1280;
-       bh = dc.font.height + 2;
+       bar = scr;
+       bar.w = 1280;
+       bar.h = dc.font.height + 2;
 
        /* window area */
-       wx = sx;
-       wy = sy + bh;
-       ww = sw;
-       wh = sh - bh;
+       win = scr;
+       win.y += bar.h;
+       win.h -= bar.h;
 
        /* master area */
-       mx = wx;
-       my = wy;
-       mw = 1280;
-       mh = 800 - bh;
+       mas = win;
+       mas.w = 1280;
+       mas.h = 800 - bar.h;
 
        /* tile area */
-       tx = 1280;
-       ty = 0;
-       tw = sw - 1280;
-       th = sh;
+       til.x = 1280;
+       til.y = 0;
+       til.w = scr.w - 1280;
+       til.h = scr.h;
 
        /* monocle area */
-       mox = mx;
-       moy = my;
-       mow = mw;
-       moh = mh;
+       mon = mas;
 }
 
 void
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -69,6 +69,10 @@ struct Client {
        Client *snext;
        Window win;
 };
+
+typedef struct {
+       int x, y, w, h;
+} Rectangle;
 
 typedef struct {
        int x, y, w, h;
@@ -193,9 +197,10 @@ void zoom(const char *arg);
 
 /* variables */
 char stext[256], buf[256];
-int screen, sx, sy, sw, sh;
+int screen;
 int (*xerrorxlib)(Display *, XErrorEvent *);
-int bx, by, bw, bh, blw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, 
wx, wy, ww, wh;
+int blw;
+Rectangle scr, bar, win, mas, til, mon;
 unsigned int numlockmask = 0;
 void (*handler[LASTEvent]) (XEvent *) = {
        [ButtonPress] = buttonpress,
@@ -296,7 +301,7 @@ ban(Client *c) {
 ban(Client *c) {
        if(c->isbanned)
                return;
-       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+       XMoveWindow(dpy, c->win, c->x + 2 * scr.w, c->y);
        c->isbanned = True;
 }
 
@@ -408,7 +413,7 @@ configurenotify(XEvent *e) {
 configurenotify(XEvent *e) {
        XConfigureEvent *ev = &e->xconfigure;
 
-       if(ev->window == root && (ev->width != sw || ev->height != sh)) {
+       if(ev->window == root && (ev->width != scr.w || ev->height != scr.h)) {
                setgeoms();
                updatebarpos();
                arrange();
@@ -426,17 +431,17 @@ configurerequest(XEvent *e) {
                        c->border = ev->border_width;
                if(c->isfixed || c->isfloating || lt->isfloating) {
                        if(ev->value_mask & CWX)
-                               c->x = sx + ev->x;
+                               c->x = scr.x + ev->x;
                        if(ev->value_mask & CWY)
-                               c->y = sy + ev->y;
+                               c->y = scr.y + ev->y;
                        if(ev->value_mask & CWWidth)
                                c->w = ev->width;
                        if(ev->value_mask & CWHeight)
                                c->h = ev->height;
-                       if((c->x - sx + c->w) > sw && c->isfloating)
-                               c->x = sx + (sw / 2 - c->w / 2); /* center in x 
direction */
-                       if((c->y - sy + c->h) > sh && c->isfloating)
-                               c->y = sy + (sh / 2 - c->h / 2); /* center in y 
direction */
+                       if((c->x - scr.x + c->w) > scr.w && c->isfloating)
+                               c->x = scr.x + (scr.w / 2 - c->w / 2); /* 
center in x direction */
+                       if((c->y - scr.y + c->h) > scr.h && c->isfloating)
+                               c->y = scr.y + (scr.h / 2 - c->h / 2); /* 
center in y direction */
                        if((ev->value_mask & (CWX|CWY))
                        && !(ev->value_mask & (CWWidth|CWHeight)))
                                configure(c);
@@ -519,13 +524,13 @@ drawbar(void) {
        drawtext(lt->symbol, dc.norm, False);
        x = dc.x + dc.w;
        dc.w = textw(stext);
-       dc.x = bw - dc.w;
+       dc.x = bar.w - dc.w;
        if(dc.x < x) {
                dc.x = x;
-               dc.w = bw - x;
+               dc.w = bar.w - x;
        }
        drawtext(stext, dc.norm, False);
-       if((dc.w = dc.x - x) > bh) {
+       if((dc.w = dc.x - x) > bar.h) {
                dc.x = x;
                if(c) {
                        drawtext(c->name, dc.sel, False);
@@ -534,7 +539,7 @@ drawbar(void) {
                else
                        drawtext(NULL, dc.norm, False);
        }
-       XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
+       XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bar.w, bar.h, 0, 0);
        XSync(dpy, False);
 }
 
@@ -986,20 +991,20 @@ manage(Window w, XWindowAttributes *wa) 
        c->w = wa->width;
        c->h = wa->height;
        c->oldborder = wa->border_width;
-       if(c->w == sw && c->h == sh) {
-               c->x = sx;
-               c->y = sy;
+       if(c->w == scr.w && c->h == scr.h) {
+               c->x = scr.x;
+               c->y = scr.y;
                c->border = wa->border_width;
        }
        else {
-               if(c->x + c->w + 2 * c->border > wx + ww)
-                       c->x = wx + ww - c->w - 2 * c->border;
-               if(c->y + c->h + 2 * c->border > wy + wh)
-                       c->y = wy + wh - c->h - 2 * c->border;
-               if(c->x < wx)
-                       c->x = wx;
-               if(c->y < wy)
-                       c->y = wy;
+               if(c->x + c->w + 2 * c->border > win.x + win.w)
+                       c->x = win.x + win.w - c->w - 2 * c->border;
+               if(c->y + c->h + 2 * c->border > win.y + win.h)
+                       c->y = win.y + win.h - c->h - 2 * c->border;
+               if(c->x < win.x)
+                       c->x = win.x;
+               if(c->y < win.y)
+                       c->y = win.y;
                c->border = BORDERPX;
        }
 
@@ -1056,7 +1061,7 @@ monocle(void) {
 
        for(c = clients; c; c = c->next)
                if(isvisible(c))
-                       resize(c, mox, moy, mow, moh, RESIZEHINTS);
+                       resize(c, mon.x, mon.y, mon.w, mon.h, RESIZEHINTS);
 }
 
 void
@@ -1087,14 +1092,14 @@ movemouse(Client *c) {
                        XSync(dpy, False);
                        nx = ocx + (ev.xmotion.x - x1);
                        ny = ocy + (ev.xmotion.y - y1);
-                       if(abs(wx - nx) < SNAP)
-                               nx = wx;
-                       else if(abs((wx + ww) - (nx + c->w + 2 * c->border)) < 
SNAP)
-                               nx = wx + ww - c->w - 2 * c->border;
-                       if(abs(wy - ny) < SNAP)
-                               ny = wy;
-                       else if(abs((wy + wh) - (ny + c->h + 2 * c->border)) < 
SNAP)
-                               ny = wy + wh - c->h - 2 * c->border;
+                       if(abs(win.x - nx) < SNAP)
+                               nx = win.x;
+                       else if(abs((win.x + win.w) - (nx + c->w + 2 * 
c->border)) < SNAP)
+                               nx = win.x + win.w - c->w - 2 * c->border;
+                       if(abs(win.y - ny) < SNAP)
+                               ny = win.y;
+                       else if(abs((win.y + win.h) - (ny + c->h + 2 * 
c->border)) < SNAP)
+                               ny = win.y + win.h - c->h - 2 * c->border;
                        if(!c->isfloating && !lt->isfloating && (abs(nx - c->x) 
> SNAP || abs(ny - c->y) > SNAP))
                                togglefloating(NULL);
                        if((lt->isfloating) || c->isfloating)
@@ -1203,14 +1208,14 @@ resize(Client *c, int x, int y, int w, i
        }
        if(w <= 0 || h <= 0)
                return;
-       if(x > sx + sw)
-               x = sw - w - 2 * c->border;
-       if(y > sy + sh)
-               y = sh - h - 2 * c->border;
-       if(x + w + 2 * c->border < sx)
-               x = sx;
-       if(y + h + 2 * c->border < sy)
-               y = sy;
+       if(x > scr.x + scr.w)
+               x = scr.w - w - 2 * c->border;
+       if(y > scr.y + scr.h)
+               y = scr.h - h - 2 * c->border;
+       if(x + w + 2 * c->border < scr.x)
+               x = scr.x;
+       if(y + h + 2 * c->border < scr.y)
+               y = scr.y;
        if(c->x != x || c->y != y || c->w != w || c->h != h) {
                c->x = wc.x = x;
                c->y = wc.y = y;
@@ -1393,40 +1398,31 @@ setdefaultgeoms(void) {
 setdefaultgeoms(void) {
 
        /* screen dimensions */
-       sx = 0;
-       sy = 0;
-       sw = DisplayWidth(dpy, screen);
-       sh = DisplayHeight(dpy, screen);
+       scr.x = 0;
+       scr.y = 0;
+       scr.w = DisplayWidth(dpy, screen);
+       scr.h = DisplayHeight(dpy, screen);
 
        /* bar position */
-       bx = sx;
-       by = sy;
-       bw = sw;
-       bh = dc.font.height + 2;
+       bar = scr;
+       bar.h = dc.font.height + 2;
 
        /* window area */
-       wx = sx;
-       wy = sy + bh;
-       ww = sw;
-       wh = sh - bh;
+       win = scr;
+       win.y += bar.h;
+       win.h -= bar.h;
 
        /* master area */
-       mx = wx;
-       my = wy;
-       mw = ((float)sw) * 0.55;
-       mh = wh;
+       mas = win;
+       mas.w = ((float)scr.w) * 0.55;
 
        /* tile area */
-       tx = mx + mw;
-       ty = wy;
-       tw = ww - mw;
-       th = wh;
+       til = win;
+       til.x = mas.x + mas.w;
+       til.w -= mas.w;
 
        /* monocle area */
-       mox = wx;
-       moy = wy;
-       mow = ww;
-       moh = wh;
+       mon = win;
 }
 
 void
@@ -1487,8 +1483,8 @@ setup(void) {
        dc.sel[ColBG] = getcolor(SELBGCOLOR);
        dc.sel[ColFG] = getcolor(SELFGCOLOR);
        initfont(FONT);
-       dc.h = bh;
-       dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, 
DefaultDepth(dpy, screen));
+       dc.h = bar.h;
+       dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), 
bar.h, DefaultDepth(dpy, screen));
        dc.gc = XCreateGC(dpy, root, 0, 0);
        XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
        if(!dc.font.set)
@@ -1513,7 +1509,7 @@ setup(void) {
        wa.background_pixmap = ParentRelative;
        wa.event_mask = ButtonPressMask|ExposureMask;
 
-       barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, 
screen),
+       barwin = XCreateWindow(dpy, root, bar.x, bar.y, bar.w, bar.h, 0, 
DefaultDepth(dpy, screen),
                                CopyFromParent, DefaultVisual(dpy, screen),
                                CWOverrideRedirect|CWBackPixmap|CWEventMask, 
&wa);
        XDefineCursor(dpy, barwin, cursor[CurNormal]);
@@ -1600,17 +1596,17 @@ tileh(void) {
        if(--n == 0)
                return;
 
-       x = tx;
-       w = tw / n;
-       if(w < bh)
-               w = tw;
+       x = til.x;
+       w = til.w / n;
+       if(w < bar.h)
+               w = til.w;
 
        for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
                if(i + 1 == n) /* remainder */
-                       tileresize(c, x, ty, (tx + tw) - x - 2 * c->border, th 
- 2 * c->border);
+                       tileresize(c, x, til.y, (til.x + til.w) - x - 2 * 
c->border, til.h - 2 * c->border);
                else
-                       tileresize(c, x, ty, w - 2 * c->border, th - 2 * 
c->border);
-               if(w != tw)
+                       tileresize(c, x, til.y, w - 2 * c->border, til.h - 2 * 
c->border);
+               if(w != til.w)
                        x = c->x + c->w + 2 * c->border;
        }
 }
@@ -1620,16 +1616,16 @@ tilemaster(unsigned int n) {
        Client *c = nexttiled(clients);
 
        if(n == 1)
-               tileresize(c, mox, moy, mow - 2 * c->border, moh - 2 * 
c->border);
+               tileresize(c, mon.x, mon.y, mon.w - 2 * c->border, mon.h - 2 * 
c->border);
        else
-               tileresize(c, mx, my, mw - 2 * c->border, mh - 2 * c->border);
+               tileresize(c, mas.x, mas.y, mas.w - 2 * c->border, mas.h - 2 * 
c->border);
        return c;
 }
 
 void
 tileresize(Client *c, int x, int y, int w, int h) {
        resize(c, x, y, w, h, RESIZEHINTS);
-       if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w 
> w)))
+       if((RESIZEHINTS) && ((c->h < bar.h) || (c->h > h) || (c->w < bar.h) || 
(c->w > w)))
                /* client doesn't accept size constraints */
                resize(c, x, y, w, h, False);
 }
@@ -1646,17 +1642,17 @@ tilev(void) {
        if(--n == 0)
                return;
 
-       y = ty;
-       h = th / n;
-       if(h < bh)
-               h = th;
+       y = til.y;
+       h = til.h / n;
+       if(h < bar.h)
+               h = til.h;
 
        for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
                if(i + 1 == n) /* remainder */
-                       tileresize(c, tx, y, tw - 2 * c->border, (ty + th) - y 
- 2 * c->border);
+                       tileresize(c, til.x, y, til.w - 2 * c->border, (til.y + 
til.h) - y - 2 * c->border);
                else
-                       tileresize(c, tx, y, tw - 2 * c->border, h - 2 * 
c->border);
-               if(h != th)
+                       tileresize(c, til.x, y, til.w - 2 * c->border, h - 2 * 
c->border);
+               if(h != til.h)
                        y = c->y + c->h + 2 * c->border;
        }
 }
@@ -1742,8 +1738,8 @@ updatebarpos(void) {
 
        if(dc.drawable != 0)
                XFreePixmap(dpy, dc.drawable);
-       dc.drawable = XCreatePixmap(dpy, root, bw, bh, DefaultDepth(dpy, 
screen));
-       XMoveResizeWindow(dpy, barwin, bx, by, bw, bh);
+       dc.drawable = XCreatePixmap(dpy, root, bar.w, bar.h, DefaultDepth(dpy, 
screen));
+       XMoveResizeWindow(dpy, barwin, bar.x, bar.y, bar.w, bar.h);
 }
 
 void

Reply via email to