JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied Ph's patch regarding geom and lt initialization
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index ed7fc0d..c174994 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -212,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,
@@ -238,14 +239,14 @@ Client *stack = NULL;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
-Geom *geom = NULL;
-Layout *lt = NULL;
 Window root, barwin;
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 #define TAGSZ (LENGTH(tags) * sizeof(Bool))
-static Bool tmp[LENGTH(tags)];
+Bool tmp[LENGTH(tags)];
+Layout *lt = layouts;
+Geom *geom = geoms;
 
 /* function implementations */
 
@@ -260,10 +261,9 @@ applyrules(Client *c) {
        XGetClassHint(dpy, c->win, &ch);
        for(i = 0; i < LENGTH(rules); i++) {
                r = &rules[i];
-               if((r->title && strstr(c->name, r->title))
-               || (ch.res_class && r->class && strstr(ch.res_class, r->class))
-               || (ch.res_name && r->instance && strstr(ch.res_name, r->instance)))
-               {
+               if((!r->title || strstr(c->name, r->title))
+               && (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
+               && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
                        c->isfloating = r->isfloating;
                        if(r->tag) {
                                c->tags[idxoftag(r->tag)] = True;
@@ -330,7 +330,7 @@ buttonpress(XEvent *e) {
                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]);
@@ -805,39 +805,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
@@ -1086,7 +1067,7 @@ monocle(void) {
        Client *c;
 
        for(c = clients; c; c = c->next)
-               if(isvisible(c))
+               if((lt->isfloating || !c->isfloating) &&  isvisible(c))
                        resize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw, RESIZEHINTS);
 }
 
@@ -1196,9 +1177,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 */
@@ -1206,10 +1187,12 @@ 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 (w * c->maxay > h * c->maxax)
+               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)
+                       else if(w * c->minay < h * c->minax)
                                h = w * c->minay / c->minax;
                }
 
@@ -1465,20 +1448,19 @@ setlayout(const char *arg) {
 
 void
 setmfact(const char *arg) {
-       double delta;
+       double d;
 
-       if(!arg)
+       if(lt->isfloating)
                return;
-       delta = strtod(arg, NULL);
-       if(arg[0] == '-' || arg[0] == '+') {
-               if(mfact + delta < 0.1 || mfact + delta > 0.9)
-                       return;
-               mfact += delta;
-       }
+       if(!arg)
+               mfact = MFACT;
        else {
-               if(delta < 0.1 || delta > 0.9)
+               d = strtod(arg, NULL);
+               if(arg[0] == '-' || arg[0] == '+')
+                       d += mfact;
+               if(d < 0.1 || d > 0.9)
                        return;
-               mfact = delta;
+               mfact = d;
        }
        setgeom(geom->symbol);
 }
@@ -1499,7 +1481,7 @@ setup(void) {
        sw = DisplayWidth(dpy, screen);
        sh = DisplayHeight(dpy, screen);
        bh = dc.font.height + 2;
-       geom = &geoms[0];
+       mfact = MFACT;
        geom->apply();
 
        /* init atoms */
@@ -1535,9 +1517,6 @@ setup(void) {
        prevtags = emallocz(TAGSZ);
        seltags[0] = prevtags[0] = True;
 
-       /* init layouts */
-       lt = &layouts[0];
-
        /* init bar */
        for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
                w = textw(layouts[i].symbol);
@@ -1950,3 +1929,4 @@ main(int argc, char *argv[]) {
        XCloseDisplay(dpy);
        return 0;
 }
+