JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied Peter Hartlich's simplification patch of setmfact and his revival of MFACT...
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 54d021f..91b0149 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -178,6 +178,7 @@ void scan(void);
 void setclientstate(Client *c, long state);
 void setgeom(const char *arg);
 void setlayout(const char *arg);
+void setmfact(const char *arg);
 void setup(void);
 void spawn(const char *arg);
 void tag(const char *arg);
@@ -211,6 +212,7 @@ char stext[256], buf[256];
 int screen, sx, sy, sw, sh;
 int (*xerrorxlib)(Display *, XErrorEvent *);
 int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
+double mfact;
 unsigned int numlockmask = 0;
 void (*handler[LASTEvent]) (XEvent *) = {
        [ButtonPress] = buttonpress,
@@ -322,10 +324,14 @@ buttonpress(XEvent *e) {
        XButtonPressedEvent *ev = &e->xbutton;
 
        if(ev->window == barwin) {
+               if((ev->x < bgw) && ev->button == Button1) {
+                       setgeom(NULL);
+                       return;
+               }
                x = bgw;
                for(i = 0; i < LENGTH(tags); i++) {
                        x += textw(tags[i]);
-                       if(ev->x > bgw && ev->x < x) {
+                       if(ev->x >= bgw && ev->x < x) {
                                if(ev->button == Button1) {
                                        if(ev->state & MODKEY)
                                                tag(tags[i]);
@@ -341,6 +347,8 @@ buttonpress(XEvent *e) {
                                return;
                        }
                }
+               if((ev->x < x + blw) && ev->button == Button1) 
+                       setlayout(NULL);
        }
        else if((c = getclient(ev->window))) {
                focus(c);
@@ -426,7 +434,7 @@ configurenotify(XEvent *e) {
        if(ev->window == root && (ev->width != sw || ev->height != sh)) {
                sw = ev->width;
                sh = ev->height;
-               setgeom(NULL);
+               setgeom(geom->symbol);
        }
 }
 
@@ -798,39 +806,20 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
 
 void
 grabbuttons(Client *c, Bool focused) {
-       XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
+       int i, j;
+       unsigned int buttons[]   = { Button1, Button2, Button3 };
+       unsigned int modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask,
+                                    MODKEY|numlockmask|LockMask} ;
 
-       if(focused) {
-               XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button1, MODKEY|LockMask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button1, MODKEY|numlockmask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button1, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-
-               XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button2, MODKEY|LockMask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button2, MODKEY|numlockmask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button2, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-
-               XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button3, MODKEY|LockMask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button3, MODKEY|numlockmask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-               XGrabButton(dpy, Button3, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
-       }
+       XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
+       if(focused)
+               for(i = 0; i < LENGTH(buttons); i++)
+                       for(j = 0; j < LENGTH(modifiers); j++)
+                               XGrabButton(dpy, buttons[i], modifiers[j], c->win, False,
+                                           BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
        else
-               XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
-                               GrabModeAsync, GrabModeSync, None, None);
+               XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
+                           BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
 }
 
 void
@@ -1189,9 +1178,9 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 
        if(sizehints) {
                /* set minimum possible */
-               if (w < 1)
+               if(w < 1)
                        w = 1;
-               if (h < 1)
+               if(h < 1)
                        h = 1;
 
                /* temporarily remove base dimensions */
@@ -1199,7 +1188,9 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
                h -= c->baseh;
 
                /* adjust for aspect limits */
-               if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) {
+               if(c->minax != c->maxax && c->minay != c->maxay 
+               && c->minax > 0 && c->maxax > 0 && c->minay > 0 && c->maxay > 0)
+               {
                        if (w * c->maxay > h * c->maxax)
                                w = h * c->maxax / c->maxay;
                        else if (w * c->minay < h * c->minax)
@@ -1417,12 +1408,18 @@ void
 setgeom(const char *arg) {
        unsigned int i;
 
-       for(i = 0; arg && i < LENGTH(geoms); i++)
-               if(!strcmp(geoms[i].symbol, arg))
-                       break;
-       if(i == LENGTH(geoms))
-               return;
-       geom = &geoms[i];
+       if(!arg) {
+               if(++geom == &geoms[LENGTH(geoms)])
+                       geom = &geoms[0];
+       }
+       else {
+               for(i = 0; i < LENGTH(geoms); i++)
+                       if(!strcmp(geoms[i].symbol, arg))
+                               break;
+               if(i == LENGTH(geoms))
+                       return;
+               geom = &geoms[i];
+       }
        geom->apply();
        updatebarpos();
        arrange();
@@ -1430,20 +1427,18 @@ setgeom(const char *arg) {
 
 void
 setlayout(const char *arg) {
-       static Layout *revert = 0;
        unsigned int i;
 
-       if(!arg)
-               return;
-       for(i = 0; i < LENGTH(layouts); i++)
-               if(!strcmp(arg, layouts[i].symbol))
-                       break;
-       if(i == LENGTH(layouts))
-               return;
-       if(revert && &layouts[i] == lt)
-               lt = revert;
+       if(!arg) {
+               if(++lt == &layouts[LENGTH(layouts)])
+                       lt = &layouts[0];
+       }
        else {
-               revert = lt;
+               for(i = 0; i < LENGTH(layouts); i++)
+                       if(!strcmp(arg, layouts[i].symbol))
+                               break;
+               if(i == LENGTH(layouts))
+                       return;
                lt = &layouts[i];
        }
        if(sel)
@@ -1453,6 +1448,25 @@ setlayout(const char *arg) {
 }
 
 void
+setmfact(const char *arg) {
+       double d;
+
+       if(lt->isfloating)
+               return;
+       if(!arg)
+               mfact = MFACT;
+       else {
+               d = strtod(arg, NULL);
+               if(arg[0] == '-' || arg[0] == '+')
+                       d += mfact;
+               if(d < 0.1 || d > 0.9)
+                       return;
+               mfact = d;
+       }
+       setgeom(geom->symbol);
+}
+
+void
 setup(void) {
        unsigned int i, w;
        XSetWindowAttributes wa;
@@ -1468,6 +1482,7 @@ setup(void) {
        sw = DisplayWidth(dpy, screen);
        sh = DisplayHeight(dpy, screen);
        bh = dc.font.height + 2;
+       mfact = MFACT;
        geom = &geoms[0];
        geom->apply();