X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=layout.c;h=bb477d64c9440b0c2343142265e76fa7f9e697c4;hb=587100873a66e34251041678504a8c1e28410591;hp=e5f635c7542d4d0963cc7094d78fc51e2364783b;hpb=29c26b88e7333fb8ea022c4bb4277bc0394ab9e3;p=dwm.git diff --git a/layout.c b/layout.c index e5f635c..bb477d6 100644 --- a/layout.c +++ b/layout.c @@ -2,15 +2,16 @@ * 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 +22,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 +31,7 @@ tile(void) { if(c->isbanned) XMoveWindow(dpy, c->win, c->x, c->y); c->isbanned = False; - if(c->isversatile) + if(c->isuntiled) continue; c->ismax = False; nx = wax; @@ -69,14 +70,27 @@ LAYOUTS /* extern */ void -focusnext(Arg *arg) { +focusclient(const char *arg) { Client *c; - if(!sel) + if(!sel || !arg) + return; + switch(atoi(arg)) { + default: return; - for(c = sel->next; c && !isvisible(c); c = c->next); - if(!c) - for(c = clients; c && !isvisible(c); c = c->next); + case 1: + for(c = sel->next; c && !isvisible(c); c = c->next); + if(!c) + for(c = clients; c && !isvisible(c); c = c->next); + break; + case -1: + 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); + } + break; + } if(c) { focus(c); restack(); @@ -84,28 +98,35 @@ focusnext(Arg *arg) { } void -focusprev(Arg *arg) { - Client *c; - - if(!sel) +incmasterw(const char *arg) { + int i; + if(lt->arrange != tile) 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(); + 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(Arg *arg) { - if((lt->arrange != tile) || (nmaster + arg->i < 1) - || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) - return; - nmaster += arg->i; +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 @@ -127,26 +148,11 @@ initlayouts(void) { Client * nexttiled(Client *c) { - for(; c && (c->isversatile || !isvisible(c)); c = c->next); + for(; c && (c->isuntiled || !isvisible(c)); c = c->next); return c; } 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(); -} - -void restack(void) { Client *c; XEvent ev; @@ -154,10 +160,10 @@ restack(void) { drawstatus(); if(!sel) return; - if(sel->isversatile || lt->arrange == versatile) + if(sel->isuntiled || lt->arrange == untile) XRaiseWindow(dpy, sel->win); - if(lt->arrange != versatile) { - if(!sel->isversatile) + if(lt->arrange != untile) { + if(!sel->isuntiled) XLowerWindow(dpy, sel->win); for(c = nexttiled(clients); c; c = nexttiled(c->next)) { if(c == sel) @@ -170,10 +176,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]; @@ -181,9 +187,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(); @@ -192,7 +199,26 @@ setlayout(Arg *arg) { } void -versatile(void) { +togglemax(const char *arg) { + XEvent ev; + + if(!sel || (lt->arrange != untile && !sel->isuntiled) || sel->isfixed) + return; + 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 +untile(void) { Client *c; for(c = clients; c; c = c->next) { @@ -213,3 +239,21 @@ versatile(void) { } restack(); } + +void +zoom(const char *arg) { + unsigned int n; + Client *c; + + if(!sel || lt->arrange != tile || sel->isuntiled) + 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(); +}