X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=layout.c;h=9de26bcc53ec0cf6d73afbe919cee3777e290d05;hp=d754afbed24c95ba207f8273605ea11d6fd3d56b;hb=399993c6b5d594278bf822e2981ebfe8bfcb58c7;hpb=8012fcf3334148d2b39646fd372a7514cc74c250 diff --git a/layout.c b/layout.c index d754afb..9de26bc 100644 --- a/layout.c +++ b/layout.c @@ -1,16 +1,16 @@ -/* (C)opyright MMVI-MMVII Anselm R. Garbe - * See LICENSE file for license details. - */ +/* © 2004-2007 Anselm R. Garbe + * See LICENSE file for license details. */ #include "dwm.h" +#include -unsigned int master = MASTER; -unsigned int nmaster = NMASTER; unsigned int blw = 0; Layout *lt = NULL; /* static */ static unsigned int nlayouts = 0; +static unsigned int masterw = MASTERWIDTH; +static unsigned int nmaster = NMASTER; static void tile(void) { @@ -21,7 +21,7 @@ tile(void) { n++; /* window geoms */ mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); - mw = (n > nmaster) ? (waw * master) / 1000 : waw; + mw = (n > nmaster) ? (waw * masterw) / 1000 : waw; th = (n > nmaster) ? wah / (n - nmaster) : 0; tw = waw - mw; @@ -30,7 +30,7 @@ tile(void) { if(c->isbanned) XMoveWindow(dpy, c->win, c->x, c->y); c->isbanned = False; - if(c->isversatile) + if(c->isfloating) continue; c->ismax = False; nx = wax; @@ -69,11 +69,82 @@ LAYOUTS /* extern */ void -incnmaster(Arg *arg) { - if((lt->arrange != tile) || (nmaster + arg->i < 1) - || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) +floating(void) { + Client *c; + + for(c = clients; c; c = c->next) { + if(isvisible(c)) { + 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 { + c->isbanned = True; + XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + } + } + if(!sel || !isvisible(sel)) { + for(c = stack; c && !isvisible(c); c = c->snext); + focus(c); + } + restack(); +} + +void +focusclient(const char *arg) { + Client *c; + + if(!sel || !arg) + return; + if(atoi(arg) < 0) { + for(c = sel->prev; c && !isvisible(c); c = c->prev); + if(!c) { + for(c = clients; c && c->next; c = c->next); + for(; c && !isvisible(c); c = c->prev); + } + } + else { + 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(); + } +} + +void +incmasterw(const char *arg) { + int i; + if(lt->arrange != tile) return; - nmaster += arg->i; + if(!arg) + masterw = MASTERWIDTH; + else { + i = atoi(arg); + if(waw * (masterw + i) / 1000 >= waw - 2 * BORDERPX + || waw * (masterw + i) / 1000 <= 2 * BORDERPX) + return; + masterw += i; + } + lt->arrange(); +} + +void +incnmaster(const char *arg) { + int i; + + if(!arg) + nmaster = NMASTER; + else { + i = atoi(arg); + if((lt->arrange != tile) || (nmaster + i < 1) + || (wah / (nmaster + i) <= 2 * BORDERPX)) + return; + nmaster += i; + } if(sel) lt->arrange(); else @@ -93,19 +164,10 @@ initlayouts(void) { } } -void -resizemaster(Arg *arg) { - if(lt->arrange != tile) - return; - if(arg->i == 0) - master = MASTER; - else { - if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX - || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) - return; - master += arg->i; - } - lt->arrange(); +Client * +nexttiled(Client *c) { + for(; c && (c->isfloating || !isvisible(c)); c = c->next); + return c; } void @@ -116,10 +178,10 @@ restack(void) { drawstatus(); if(!sel) return; - if(sel->isversatile || lt->arrange == versatile) + if(sel->isfloating || lt->arrange == floating) XRaiseWindow(dpy, sel->win); - if(lt->arrange != versatile) { - if(!sel->isversatile) + if(lt->arrange != floating) { + if(!sel->isfloating) XLowerWindow(dpy, sel->win); for(c = nexttiled(clients); c; c = nexttiled(c->next)) { if(c == sel) @@ -132,10 +194,10 @@ restack(void) { } void -setlayout(Arg *arg) { - unsigned int i; +setlayout(const char *arg) { + int i; - if(arg->i == -1) { + if(!arg) { for(i = 0; i < nlayouts && lt != &layout[i]; i++); if(i == nlayouts - 1) lt = &layout[0]; @@ -143,9 +205,10 @@ setlayout(Arg *arg) { lt = &layout[++i]; } else { - if(arg->i < 0 || arg->i >= nlayouts) + i = atoi(arg); + if(i < 0 || i >= nlayouts) return; - lt = &layout[arg->i]; + lt = &layout[i]; } if(sel) lt->arrange(); @@ -154,32 +217,38 @@ setlayout(Arg *arg) { } void -toggleversatile(Arg *arg) { - if(!sel || lt->arrange == versatile) +togglemax(const char *arg) { + XEvent ev; + + if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed) return; - sel->isversatile = !sel->isversatile; - lt->arrange(); + if((sel->ismax = !sel->ismax)) { + sel->rx = sel->x; + sel->ry = sel->y; + sel->rw = sel->w; + sel->rh = sel->h; + resize(sel, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); + } + else + resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True); + drawstatus(); + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } void -versatile(void) { +zoom(const char *arg) { + unsigned int n; Client *c; - for(c = clients; c; c = c->next) { - if(isvisible(c)) { - 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 { - c->isbanned = True; - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); - } - } - if(!sel || !isvisible(sel)) { - for(c = stack; c && !isvisible(c); c = c->snext); - focus(c); - } - restack(); + if(!sel || lt->arrange != tile || sel->isfloating) + return; + for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) + n++; + if((c = sel) == nexttiled(clients)) + if(!(c = nexttiled(c->next))) + return; + detach(c); + attach(c); + focus(c); + lt->arrange(); }