X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=view.c;h=86902d4779b638a374a8e00498f5311841c64e17;hb=26157e6973f240a9b5ee407b9d2d5eca9358844f;hp=d9aa6e4a2f328974c98fddb4c1cdf0de20e3c46b;hpb=aa13727067af829b94461eb36aa029297ed8e6b9;p=dwm.git diff --git a/view.c b/view.c index d9aa6e4..86902d4 100644 --- a/view.c +++ b/view.c @@ -3,30 +3,74 @@ * See LICENSE file for license details. */ #include "dwm.h" +#include + +/* 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, *newclients, *tail; + + newclients = tail = NULL; + while((c = minclient())) { + detach(c); + if(tail) { + c->prev = tail; + tail->next = c; + tail = c; + } + else + tail = newclients = c; + } + clients = newclients; +} /* extern */ void (*arrange)(Arg *) = DEFMODE; void +detach(Client *c) +{ + if(c->prev) + c->prev->next = c->next; + if(c->next) + c->next->prev = c->prev; + if(c == clients) + clients = c->next; + c->next = c->prev = NULL; +} + +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(); } @@ -34,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) @@ -47,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); @@ -86,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(); } @@ -168,21 +210,21 @@ restack() fi = 0; mi = 2 * f; if(sel->isfloat || arrange == dofloat) { - wins[fi++] = sel->title; + wins[fi++] = sel->twin; wins[fi++] = sel->win; } else { - wins[mi++] = sel->title; + 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->title; + wins[fi++] = c->twin; wins[fi++] = c->win; } else { - wins[mi++] = c->title; + wins[mi++] = c->twin; wins[mi++] = c->win; } } @@ -195,7 +237,7 @@ restack() void togglemode(Arg *arg) { - arrange = arrange == dofloat ? dotile : dofloat; + arrange = (arrange == dofloat) ? dotile : dofloat; if(sel) arrange(NULL); else @@ -211,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); } @@ -222,32 +265,36 @@ 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); } void zoom(Arg *arg) { - Client *c; + Client *c = sel; - if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax) + if(!c || (arrange != dotile) || c->isfloat || maximized) return; - if(sel == getnext(clients)) { - if((c = getnext(sel->next))) - sel = c; - else + if(c == getnext(clients)) + if(!(c = getnext(c->next))) return; - } - - /* pop */ - sel->prev->next = sel->next; - if(sel->next) - sel->next->prev = sel->prev; - sel->prev = NULL; - clients->prev = sel; - sel->next = clients; - clients = sel; - focus(sel); + detach(c); + c->next = clients; + clients->prev = c; + clients = c; + focus(c); arrange(NULL); }