X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=view.c;h=86902d4779b638a374a8e00498f5311841c64e17;hb=26157e6973f240a9b5ee407b9d2d5eca9358844f;hp=9ba8e0bcd541c17b54b44b97e3f3b4474d822749;hpb=8a6679b3b4999559059df3ae9e08951099511036;p=dwm.git diff --git a/view.c b/view.c index 9ba8e0b..86902d4 100644 --- a/view.c +++ b/view.c @@ -3,38 +3,45 @@ * See LICENSE file for license details. */ #include "dwm.h" +#include -/* extern */ +/* static */ -void (*arrange)(Arg *) = DEFMODE; +static Client * +minclient() +{ + Client *c, *min; -void -attach(Client *c) + for(min = c = clients; c; c = c->next) + if(c->weight < min->weight) + min = c; + return min; +} + + +static void +reorder() { - Client *first = getnext(clients); + Client *c, *newclients, *tail; - if(!first) { - if(clients) { - for(first = clients; first->next; first = first->next); - first->next = c; - c->prev = first; + newclients = tail = NULL; + while((c = minclient())) { + detach(c); + if(tail) { + c->prev = tail; + tail->next = c; + tail = c; } else - clients = c; - } - else if(first == clients) { - c->next = clients; - clients->prev = c; - clients = c; - } - else { - first->prev->next = c; - c->prev = first->prev; - first->prev = c; - c->next = first; + tail = newclients = c; } + clients = newclients; } +/* extern */ + +void (*arrange)(Arg *) = DEFMODE; + void detach(Client *c) { @@ -50,22 +57,20 @@ detach(Client *c) void dofloat(Arg *arg) { - Client *c; + Client *c, *fc; + + maximized = False; for(c = clients; c; c = c->next) { - c->ismax = False; if(isvisible(c)) { resize(c, True, TopLeft); } else ban(c); } - if(!sel || !isvisible(sel)) - sel = getnext(clients); - if(sel) - focus(sel); - else - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + if(!(fc = sel) || !isvisible(fc)) + fc = getnext(clients); + focus(fc); restack(); } @@ -73,7 +78,9 @@ void dotile(Arg *arg) { int h, i, n, w; - Client *c; + Client *c, *fc; + + maximized = False; w = sw - mw; for(n = 0, c = clients; c; c = c->next) @@ -86,7 +93,6 @@ dotile(Arg *arg) h = sh - bh; for(i = 0, c = clients; c; c = c->next) { - c->ismax = False; if(isvisible(c)) { if(c->isfloat) { resize(c, True, TopLeft); @@ -125,12 +131,9 @@ dotile(Arg *arg) else ban(c); } - if(!sel || !isvisible(sel)) - sel = getnext(clients); - if(sel) - focus(sel); - else - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + if(!(fc = sel) || !isvisible(fc)) + fc = getnext(clients); + focus(fc); restack(); } @@ -250,6 +253,7 @@ toggleview(Arg *arg) for(i = 0; i < ntags && !seltag[i]; i++); if(i == ntags) seltag[arg->i] = True; /* cannot toggle last view */ + reorder(); arrange(NULL); } @@ -261,6 +265,18 @@ view(Arg *arg) for(i = 0; i < ntags; i++) seltag[i] = False; seltag[arg->i] = True; + reorder(); + arrange(NULL); +} + +void +viewall(Arg *arg) +{ + unsigned int i; + + for(i = 0; i < ntags; i++) + seltag[i] = True; + reorder(); arrange(NULL); } @@ -269,14 +285,16 @@ zoom(Arg *arg) { Client *c = sel; - if(!c || (arrange != dotile) || c->isfloat || c->ismax) + if(!c || (arrange != dotile) || c->isfloat || maximized) return; if(c == getnext(clients)) if(!(c = getnext(c->next))) return; detach(c); - attach(c); + c->next = clients; + clients->prev = c; + clients = c; focus(c); arrange(NULL); }