JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
sanders solution is convincing and elegant
[dwm.git] / view.c
diff --git a/view.c b/view.c
index 8df93ef..3b5abba 100644 (file)
--- a/view.c
+++ b/view.c
@@ -38,6 +38,13 @@ reorder()
        clients = newclients;
 }
 
+static Client *
+nexttiled(Client *c)
+{
+       for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
+       return c;
+}
+
 /* extern */
 
 void (*arrange)(Arg *) = DEFMODE;
@@ -82,8 +89,8 @@ dotile(Arg *arg)
        maximized = False;
 
        w = sw - mw;
-       for(n = 0, c = clients; c && !c->isfloat; c = c->next)
-               if(isvisible(c))
+       for(n = 0, c = clients; c; c = c->next)
+               if(isvisible(c) && !c->isfloat)
                        n++;
 
        if(n > 1)
@@ -186,8 +193,8 @@ resizecol(Arg *arg)
        unsigned int n;
        Client *c;
 
-       for(n = 0, c = clients; c && !c->isfloat; c = c->next)
-               if(isvisible(c))
+       for(n = 0, c = clients; c; c = c->next)
+               if(isvisible(c) && !c->isfloat)
                        n++;
        if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
                return;
@@ -208,52 +215,20 @@ resizecol(Arg *arg)
 void
 restack()
 {
-       static unsigned int nwins = 0;
-       static Window *wins = NULL;
-       unsigned int f, fi, m, mi, n;
        Client *c;
        XEvent ev;
-
-       for(f = 0, m = 0, c = clients; c; c = c->next)
-               if(isvisible(c)) {
-                       if(c->isfloat || arrange == dofloat)
-                               f++;
-                       else
-                               m++;
-               }
-       if(!(n = 2 * (f + m))) {
-               drawstatus();
+       
+       if(!sel)
                return;
+       if(sel->isfloat || arrange == dofloat) {
+               XRaiseWindow(dpy, sel->win);
+               XRaiseWindow(dpy, sel->twin);
        }
-       if(nwins < n) {
-               nwins = n;
-               wins = erealloc(wins, nwins * sizeof(Window));
-       }
-
-       fi = 0;
-       mi = 2 * f;
-       if(sel) {
-               if(sel->isfloat || arrange == dofloat) {
-                       wins[fi++] = sel->twin;
-                       wins[fi++] = sel->win;
-               }
-               else {
-                       wins[mi++] = sel->twin;
-                       wins[mi++] = sel->win;
-               }
-       }
-       for(c = clients; c; c = c->next)
-               if(isvisible(c) && c != sel) {
-                       if(c->isfloat || arrange == dofloat) {
-                               wins[fi++] = c->twin;
-                               wins[fi++] = c->win;
-                       }
-                       else {
-                               wins[mi++] = c->twin;
-                               wins[mi++] = c->win;
-                       }
+       if(arrange != dofloat) 
+               for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
+                       XLowerWindow(dpy, c->twin);
+                       XLowerWindow(dpy, c->win);
                }
-       XRestackWindows(dpy, wins, n);
        drawall();
        XSync(dpy, False);
        while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
@@ -311,14 +286,14 @@ zoom(Arg *arg)
        unsigned int n;
        Client *c;
 
-       for(n = 0, c = clients; c && !c->isfloat; c = c->next)
-               if(isvisible(c))
+       for(n = 0, c = clients; c; c = c->next)
+               if(isvisible(c) && !c->isfloat)
                        n++;
        if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
                return;
 
-       if((c = sel) == getnext(clients))
-               if(!(c = getnext(c->next)) || c->isfloat)
+       if((c = sel) == nexttiled(clients))
+               if(!(c = nexttiled(c->next)))
                        return;
        detach(c);
        c->next = clients;