X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=view.c;h=ac201e60e13ba39ceafba9fa52cd68cd860f9793;hb=0915da8842fd6e16b804ae3205ec2f6baaaa342c;hp=ac336e304ab25897c83b5dda2a922ded94f72e94;hpb=016c54196e682ae8658854febb746b0437a010dc;p=dwm.git diff --git a/view.c b/view.c index ac336e3..ac201e6 100644 --- a/view.c +++ b/view.c @@ -3,29 +3,45 @@ * See LICENSE file for license details. */ #include "dwm.h" +#include /* static */ static Client * -getslot(Client *c) +minclient() { - unsigned int i, tic; - Client *p; - - for(tic = 0; tic < ntags && !c->tags[tic]; tic++); - for(p = clients; p; p = p->next) { - for(i = 0; i < ntags && !p->tags[i]; i++); - if(tic < i) - return p; + 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; } - return p; + clients = newclients; } static Client * -tail() +nexttiled(Client *c) { - Client *c; - for(c = clients; c && c->next; c = c->next); + for(c = getnext(c->next); c && c->isfloat; c = getnext(c->next)); return c; } @@ -34,35 +50,6 @@ tail() void (*arrange)(Arg *) = DEFMODE; void -attach(Client *c) -{ - Client *p; - - if(!clients) { - clients = c; - return; - } - if(!(p = getnext(clients)) && !(p = getslot(c))) { - p = tail(); - c->prev = p; - p->next = c; - return; - } - - if(p == clients) { - c->next = clients; - clients->prev = c; - clients = c; - } - else { - p->prev->next = c; - c->prev = p->prev; - p->prev = c; - c->next = p; - } -} - -void detach(Client *c) { if(c->prev) @@ -79,8 +66,9 @@ dofloat(Arg *arg) { Client *c; + maximized = False; + for(c = clients; c; c = c->next) { - c->ismax = False; if(isvisible(c)) { resize(c, True, TopLeft); } @@ -88,11 +76,7 @@ dofloat(Arg *arg) ban(c); } if(!sel || !isvisible(sel)) - sel = getnext(clients); - if(sel) - focus(sel); - else - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + focus(getnext(clients)); restack(); } @@ -102,6 +86,8 @@ dotile(Arg *arg) int h, i, n, w; Client *c; + maximized = False; + w = sw - mw; for(n = 0, c = clients; c; c = c->next) if(isvisible(c) && !c->isfloat) @@ -113,7 +99,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); @@ -153,11 +138,7 @@ dotile(Arg *arg) ban(c); } if(!sel || !isvisible(sel)) - sel = getnext(clients); - if(sel) - focus(sel); - else - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + focus(getnext(clients)); restack(); } @@ -207,6 +188,31 @@ isvisible(Client *c) } void +resizecol(Arg *arg) +{ + unsigned int n; + Client *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(sel == getnext(clients)) { + if(mw + arg->i > sw - 100 || mw + arg->i < 100) + return; + mw += arg->i; + } + else { + if(mw - arg->i > sw - 100 || mw - arg->i < 100) + return; + mw -= arg->i; + } + arrange(NULL); +} + +void restack() { static unsigned int nwins = 0; @@ -233,13 +239,15 @@ restack() fi = 0; mi = 2 * f; - if(sel->isfloat || arrange == dofloat) { - wins[fi++] = sel->twin; - wins[fi++] = sel->win; - } - else { - wins[mi++] = sel->twin; - wins[mi++] = sel->win; + 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) { @@ -277,6 +285,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); } @@ -288,22 +297,40 @@ 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 = sel; + unsigned int n; + Client *c; - if(!c || (arrange != dotile) || c->isfloat || c->ismax) + 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 == getnext(clients)) - if(!(c = getnext(c->next))) + if((c = sel) == nexttiled(clients)) + if(!(c = nexttiled(c))) return; detach(c); - attach(c); + c->next = clients; + clients->prev = c; + clients = c; focus(c); arrange(NULL); }