X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=layout.c;h=6a65599e020e9fa49773ff0d8a268c69d739cbb8;hb=352cae4380713949d3800ebcda7aff3bb5ab9efc;hp=d754afbed24c95ba207f8273605ea11d6fd3d56b;hpb=8012fcf3334148d2b39646fd372a7514cc74c250;p=dwm.git diff --git a/layout.c b/layout.c index d754afb..6a65599 100644 --- a/layout.c +++ b/layout.c @@ -3,14 +3,14 @@ */ #include "dwm.h" -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; @@ -69,11 +69,58 @@ LAYOUTS /* extern */ void -incnmaster(Arg *arg) { - if((lt->arrange != tile) || (nmaster + arg->i < 1) - || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) +focusnext(Arg arg) { + Client *c; + + if(!sel) + return; + 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 +focusprev(Arg arg) { + Client *c; + + if(!sel) + return; + 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); + } + if(c) { + focus(c); + restack(); + } +} + +void +incmasterw(Arg arg) { + if(lt->arrange != tile) + return; + if(arg.i == 0) + masterw = MASTERWIDTH; + else { + if(waw * (masterw + arg.i) / 1000 >= waw - 2 * BORDERPX + || waw * (masterw + arg.i) / 1000 <= 2 * BORDERPX) + return; + masterw += arg.i; + } + lt->arrange(); +} + +void +incnmaster(Arg arg) { + if((lt->arrange != tile) || (nmaster + arg.i < 1) + || (wah / (nmaster + arg.i) <= 2 * BORDERPX)) return; - nmaster += arg->i; + nmaster += arg.i; if(sel) lt->arrange(); else @@ -93,19 +140,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->isversatile || !isvisible(c)); c = c->next); + return c; } void @@ -132,10 +170,10 @@ restack(void) { } void -setlayout(Arg *arg) { +setlayout(Arg arg) { unsigned int i; - if(arg->i == -1) { + if(arg.i == -1) { for(i = 0; i < nlayouts && lt != &layout[i]; i++); if(i == nlayouts - 1) lt = &layout[0]; @@ -143,9 +181,9 @@ setlayout(Arg *arg) { lt = &layout[++i]; } else { - if(arg->i < 0 || arg->i >= nlayouts) + if(arg.i < 0 || arg.i >= nlayouts) return; - lt = &layout[arg->i]; + lt = &layout[arg.i]; } if(sel) lt->arrange(); @@ -154,11 +192,21 @@ setlayout(Arg *arg) { } void -toggleversatile(Arg *arg) { - if(!sel || lt->arrange == versatile) +togglemax(Arg arg) { + XEvent ev; + + if(!sel || !sel->isversatile || sel->isfixed || lt->arrange != versatile) 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); + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } void @@ -183,3 +231,21 @@ versatile(void) { } restack(); } + +void +zoom(Arg arg) { + unsigned int n; + Client *c; + + if(!sel || lt->arrange != tile || sel->isversatile) + 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(); +}