X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=view.c;h=9bd75846f7f32f8bd9cb6c1d61ceb2a9c82c4161;hb=51f6405b0d7a9ba34696cafbc08303b1e5b14cfa;hp=1ac31415cdf957ab02b59af407b9204a9dd4de7b;hpb=0b80d1842d1c921a8a94c11fd9222dad9311cc97;p=dwm.git diff --git a/view.c b/view.c index 1ac3141..9bd7584 100644 --- a/view.c +++ b/view.c @@ -11,6 +11,40 @@ nexttiled(Client *c) { return c; } +static Bool +ismaster(Client *c) { + Client *cl; + unsigned int i; + + for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++); + return i < nmaster; +} + +static void +pop(Client *c) { + detach(c); + if(clients) + clients->prev = c; + c->next = clients; + clients = c; +} + +static void +swap(Client *c1, Client *c2) { + Client tmp = *c1; + Client *c1p = c1->prev; + Client *c1n = c1->next; + Client *c2p = c2->prev; + Client *c2n = c2->next; + + *c1 = *c2; + *c2 = tmp; + c1->prev = c1p; + c1->next = c1n; + c2->prev = c2p; + c2->next = c2n; +} + static void togglemax(Client *c) { XEvent ev; @@ -34,6 +68,15 @@ togglemax(Client *c) { while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } +static Client * +topofstack() { + Client *c; + unsigned int i; + + for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++); + return (i < nmaster) ? NULL : c; +} + /* extern */ void (*arrange)(void) = DEFMODE; @@ -149,7 +192,7 @@ focusprev(Arg *arg) { void incnmaster(Arg *arg) { - if(nmaster + arg->i < 1) + if((nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh)) return; nmaster += arg->i; arrange(); @@ -248,7 +291,7 @@ view(Arg *arg) { void zoom(Arg *arg) { - unsigned int i, n; + unsigned int n; Client *c; if(!sel) @@ -259,22 +302,21 @@ zoom(Arg *arg) { } for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) n++; - if(n <= nmaster || (arrange == dofloat)) - return; - for(c = nexttiled(clients), i = 0; c && (c != sel) && i < nmaster; c = nexttiled(c->next)) - i++; - if(c == sel && i < nmaster) - for(; c && i < nmaster; c = nexttiled(c->next)) - i++; - if(!c) + c = sel; + if(arrange == dofloat) return; + else if(n <= nmaster) + pop(c); + else if(ismaster(sel)) { + if(!(c = topofstack())) + return; + swap(c, sel); + c = sel; + } + else + pop(c); - detach(c); - if(clients) - clients->prev = c; - c->next = clients; - clients = c; focus(c); arrange(); }