JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied Donald Chai's showhide patch in slightly modified ways
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 2a4bacc..50bbd6a 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -180,6 +180,7 @@ static void setclientstate(Client *c, long state);
 static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
 static void setup(void);
+static void showhide(Client *c);
 static void spawn(const Arg *arg);
 static void tag(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
@@ -271,18 +272,8 @@ applyrules(Client *c) {
 
 void
 arrange(void) {
-       Client *c;
-
-       for(c = clients; c; c = c->next)
-               if(ISVISIBLE(c)) {
-                       XMoveWindow(dpy, c->win, c->x, c->y);
-                       if(!lt[sellt]->arrange || c->isfloating)
-                               resize(c, c->x, c->y, c->w, c->h, True);
-               }
-               else {
-                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-               }
-
+       if(stack)
+               showhide(stack);
        focus(NULL);
        if(lt[sellt]->arrange)
                lt[sellt]->arrange();
@@ -331,21 +322,20 @@ buttonpress(XEvent *e) {
        for(i = 0; i < LENGTH(buttons); i++)
                if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
                   && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
-                       buttons[i].func(click == ClkTagBar ? &arg : &buttons[i].arg);
+                       buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
 }
 
 void
 checkotherwm(void) {
        otherwm = False;
-       XSetErrorHandler(xerrorstart);
+       xerrorxlib = XSetErrorHandler(xerrorstart);
 
        /* this causes an error if some other window manager is running */
        XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
        XSync(dpy, False);
        if(otherwm)
                die("dwm: another window manager is already running\n");
-       XSetErrorHandler(NULL);
-       xerrorxlib = XSetErrorHandler(xerror);
+       XSetErrorHandler(xerror);
        XSync(dpy, False);
 }
 
@@ -763,10 +753,10 @@ grabkeys(void) {
 
                XUngrabKey(dpy, AnyKey, AnyModifier, root);
                for(i = 0; i < LENGTH(keys); i++) {
-                       code = XKeysymToKeycode(dpy, keys[i].keysym);
-                       for(j = 0; j < LENGTH(modifiers); j++)
-                               XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True,
-                                        GrabModeAsync, GrabModeAsync);
+                       if((code = XKeysymToKeycode(dpy, keys[i].keysym)))
+                               for(j = 0; j < LENGTH(modifiers); j++)
+                                       XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
+                                                True, GrabModeAsync, GrabModeAsync);
                }
        }
 }
@@ -1056,9 +1046,9 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 
                /* adjust for aspect limits */
                if(c->mina > 0 && c->maxa > 0) {
-                       if(c->maxa < (float)(w / h))
+                       if(c->maxa < (float)w / h)
                                w = h * c->maxa;
-                       else if(c->mina < (float)(h / w))
+                       else if(c->mina < (float)h / w)
                                h = w * c->mina;
                }
 
@@ -1378,6 +1368,19 @@ setup(void) {
 }
 
 void
+showhide(Client *c) {
+       if(ISVISIBLE(c)) { /* show clients top down */
+               XMoveWindow(dpy, c->win, c->x, c->y);
+               if(!lt[sellt]->arrange || c->isfloating)
+                       resize(c, c->x, c->y, c->w, c->h, True);
+       }
+       if(c->snext) /* hide clients bottom up */
+               showhide(c->snext);
+       if(!ISVISIBLE(c))
+               XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+}
+
+void
 spawn(const Arg *arg) {
        /* The double-fork construct avoids zombie processes and keeps the code
         * clean from stupid signal handlers. */
@@ -1625,7 +1628,7 @@ updatesizehints(Client *c) {
        else
                c->maxa = c->mina = 0.0;
        c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
-                       && c->maxw == c->minw && c->maxh == c->minh);
+                    && c->maxw == c->minw && c->maxh == c->minh);
 }
 
 void