JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added viewall to mainstream (only Ross Mohns version, not the toggle)
[dwm.git] / view.c
diff --git a/view.c b/view.c
index 3270160..bb0647a 100644 (file)
--- a/view.c
+++ b/view.c
@@ -3,31 +3,39 @@
  * See LICENSE file for license details.
  */
 #include "dwm.h"
+#include <stdio.h>
 
 /* static */
 
+static Client *
+minclient()
+{
+       Client *c, *min;
+
+       for(min = c = clients; c; c = c->next)
+               if(c->weight < min->weight)
+                       min = c;
+       return min;
+}
+
+
 static void
 reorder()
 {
-       Client *c, *orig, *p;
-
-       orig = clients;
-       clients = NULL;
+       Client *c, *newclients, *tail;
 
-       while((c = orig)) {
-               orig = orig->next;
+       newclients = tail = NULL;
+       while((c = minclient())) {
                detach(c);
-
-               for(p = clients; p && p->next && p->weight <= c->weight; p = p->next);
-               c->prev = p;
-               if(p) {
-                       if((c->next = p->next))
-                               c->next->prev = c;
-                       p->next = c;
+               if(tail) {
+                       c->prev = tail;
+                       tail->next = c;
+                       tail = c;
                }
                else
-                       clients = c;
+                       tail = newclients = c;
        }
+       clients = newclients;
 }
 
 /* extern */
@@ -257,7 +265,6 @@ void
 view(Arg *arg)
 {
        unsigned int i;
-       Client *c;
 
        for(i = 0; i < ntags; i++)
                seltag[i] = False;
@@ -267,6 +274,16 @@ view(Arg *arg)
 }
 
 void
+viewall(Arg *arg)
+{
+       unsigned int i;
+
+       for(i = 0; i < ntags; i++)
+               seltag[i] = True;
+       arrange(NULL);
+}
+
+void
 zoom(Arg *arg)
 {
        Client *c = sel;