X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=view.c;h=72aa04e075d40253e6ad0384a988a6f1469e0c66;hb=5d9146ff372ae0c5196e290fb2c1f828d4137e20;hp=90080fb1f5bbdef26cf101ff5074ab28b6f46066;hpb=14d05e7c725a4a07136ceb123cf760272afc1a87;p=dwm.git diff --git a/view.c b/view.c index 90080fb..72aa04e 100644 --- a/view.c +++ b/view.c @@ -1,72 +1,11 @@ -/* - * (C)opyright MMVI Anselm R. Garbe +/* (C)opyright MMVI-MMVII Anselm R. Garbe * See LICENSE file for license details. */ #include "dwm.h" -/* static */ - -static Client * -minclient(void) { - Client *c, *min; - - if((clients && clients->isfloat) || arrange == dofloat) - return clients; /* don't touch floating order */ - for(min = c = clients; c; c = c->next) - if(c->weight < min->weight) - min = c; - return min; -} - -static Client * -nexttiled(Client *c) { - for(c = getnext(c); c && c->isfloat; c = getnext(c->next)); - return c; -} - -static void -reorder(void) { - 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; -} - -static void -togglemax(Client *c) -{ - XEvent ev; - if((c->ismax = !c->ismax)) { - c->rx = c->x; c->x = sx; - c->ry = c->y; c->y = bh; - c->rw = c->w; c->w = sw - 2 * BORDERPX; - c->rh = c->h; c->h = sh - bh - 2 * BORDERPX; - } - else { - c->x = c->rx; - c->y = c->ry; - c->w = c->rw; - c->h = c->rh; - } - resize(c, True, TopLeft); - while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); -} - /* extern */ -void (*arrange)(Arg *) = DEFMODE; -Bool isvertical = VERTICALSTACK; -StackPos stackpos = STACKPOS; +void (*arrange)(void) = DEFMODE; void detach(Client *c) { @@ -80,96 +19,20 @@ detach(Client *c) { } void -dofloat(Arg *arg) { +dofloat(void) { Client *c; for(c = clients; c; c = c->next) { if(isvisible(c)) { - resize(c, True, TopLeft); - } - else - ban(c); - } - if(!sel || !isvisible(sel)) { - for(c = stack; c && !isvisible(c); c = c->snext); - focus(c); - } - restack(); -} - -/* This algorithm is based on a (M)aster area and a (S)tacking area. - * It supports following arrangements: - * MMMS MMMM SMMM - * MMMS MMMM SMMM - * MMMS SSSS SMMM - */ -void -dotile(Arg *arg) { - int h, i, n, w; - Client *c; - - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) - n++; - - if(isvertical) { - if(stackpos == StackBottom) { - w = sw; - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; + if(c->isbanned) + XMoveWindow(dpy, c->win, c->x, c->y); + c->isbanned = False; + resize(c, c->x, c->y, c->w, c->h, True); } else { - w = sw - master; - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; - } - } - else { /* horizontal stack */ - - } - - for(i = 0, c = clients; c; c = c->next) { - if(isvisible(c)) { - if(c->isfloat) { - resize(c, True, TopLeft); - continue; - } - c->ismax = False; - if(n == 1) { - c->x = sx; - c->y = sy + bh; - c->w = sw - 2 * BORDERPX; - c->h = sh - 2 * BORDERPX - bh; - } - else if(i == 0) { - c->x = sx; - c->y = sy + bh; - c->w = master - 2 * BORDERPX; - c->h = sh - 2 * BORDERPX - bh; - } - else if(h > bh) { - c->x = sx + master; - c->y = sy + (i - 1) * h + bh; - c->w = w - 2 * BORDERPX; - if(i + 1 == n) - c->h = sh - c->y - 2 * BORDERPX; - else - c->h = h - 2 * BORDERPX; - } - else { /* fallback if h < bh */ - c->x = sx + master; - c->y = sy + bh; - c->w = w - 2 * BORDERPX; - c->h = sh - 2 * BORDERPX - bh; - } - resize(c, False, TopLeft); - i++; + c->isbanned = True; + XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); } - else - ban(c); } if(!sel || !isvisible(sel)) { for(c = stack; c && !isvisible(c); c = c->snext); @@ -184,9 +47,9 @@ focusnext(Arg *arg) { if(!sel) return; - - if(!(c = getnext(sel->next))) - c = getnext(clients); + for(c = sel->next; c && !isvisible(c); c = c->next); + if(!c) + for(c = clients; c && !isvisible(c); c = c->next); if(c) { focus(c); restack(); @@ -199,10 +62,10 @@ focusprev(Arg *arg) { if(!sel) return; - - if(!(c = getprev(sel->prev))) { + for(c = sel->prev; c && !isvisible(c); c = c->prev); + if(!c) { for(c = clients; c && c->next; c = c->next); - c = getprev(c); + for(; c && !isvisible(c); c = c->prev); } if(c) { focus(c); @@ -220,28 +83,10 @@ isvisible(Client *c) { return False; } -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 == dofloat)) - return; - - if(sel == getnext(clients)) { - if(master + arg->i > sw - 100 || master + arg->i < 100) - return; - master += arg->i; - } - else { - if(master - arg->i > sw - 100 || master - arg->i < 100) - return; - master -= arg->i; - } - arrange(NULL); +Client * +nextmanaged(Client *c) { + for(; c && (c->isfloat || !isvisible(c)); c = c->next); + return c; } void @@ -249,29 +94,37 @@ restack(void) { Client *c; XEvent ev; - if(!sel) { - drawstatus(); + drawstatus(); + if(!sel) return; - } - if(sel->isfloat || arrange == dofloat) { + if(sel->isfloat || arrange == dofloat) XRaiseWindow(dpy, sel->win); - XRaiseWindow(dpy, sel->twin); - } - if(arrange != dofloat) - for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - XLowerWindow(dpy, c->twin); + if(arrange != dofloat) { + if(!sel->isfloat) + XLowerWindow(dpy, sel->win); + for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { + if(c == sel) + continue; XLowerWindow(dpy, c->win); } - drawall(); + } XSync(dpy, False); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } void +togglefloat(Arg *arg) { + if(!sel || arrange == dofloat) + return; + sel->isfloat = !sel->isfloat; + arrange(); +} + +void togglemode(Arg *arg) { arrange = (arrange == dofloat) ? dotile : dofloat; if(sel) - arrange(NULL); + arrange(); else drawstatus(); } @@ -284,8 +137,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); + arrange(); } void @@ -293,49 +145,9 @@ view(Arg *arg) { unsigned int i; 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); + seltag[i] = (arg->i == -1) ? True : False; + if(arg->i >= 0 && arg->i < ntags) + seltag[arg->i] = True; + arrange(); } -void -zoom(Arg *arg) { - unsigned int n; - Client *c; - - if(!sel) - return; - - if(sel->isfloat || (arrange == dofloat)) { - togglemax(sel); - return; - } - - for(n = 0, c = clients; c; c = c->next) - if(isvisible(c) && !c->isfloat) - n++; - if(n < 2 || (arrange == dofloat)) - return; - - if((c = sel) == nexttiled(clients)) - if(!(c = nexttiled(c->next))) - return; - detach(c); - if(clients) - clients->prev = c; - c->next = clients; - clients = c; - focus(c); - arrange(NULL); -}