X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=tile.c;h=82696769e02a403fc6af59e7efe0a20e939260a3;hp=fe25943b548c060e40334528baa2812bee6da62d;hb=6bdef73a4f0c2a96f8984ddc10b55f1d753ab5fe;hpb=5d9146ff372ae0c5196e290fb2c1f828d4137e20 diff --git a/tile.c b/tile.c index fe25943..8269676 100644 --- a/tile.c +++ b/tile.c @@ -1,134 +1,102 @@ -/* (C)opyright MMVI-MMVII Anselm R. Garbe - * See LICENSE file for license details. - */ -#include "dwm.h" +/* See LICENSE file for copyright and license details. */ +int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh; -unsigned int master = MASTER; -unsigned int nmaster = NMASTER; +void setmfact(const char *arg); +void tile(void); +void tileresize(Client *c, int x, int y, int w, int h); +void updatetilegeom(void); -/* static */ - -static void -togglemax(Client *c) { - XEvent ev; +void +setmfact(const char *arg) { + double d; - if(c->isfixed) + if(!arg || lt->arrange != tile) return; - if((c->ismax = !c->ismax)) { - c->rx = c->x; - c->ry = c->y; - c->rw = c->w; - c->rh = c->h; - resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); + else { + d = strtod(arg, NULL); + if(arg[0] == '-' || arg[0] == '+') + d += mfact; + if(d < 0.1 || d > 0.9) + return; + mfact = d; } - else - resize(c, c->rx, c->ry, c->rw, c->rh, True); - while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + updatetilegeom(); + arrange(); } -/* extern */ - void -dotile(void) { - unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; +tile(void) { + int x, y, h, w; + unsigned int i, n; Client *c; - for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) - n++; - /* window geoms */ - mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); - mw = (n > nmaster) ? (waw * master) / 1000 : waw; - th = (n > nmaster) ? wah / (n - nmaster) : 0; - tw = waw - mw; + for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++); + if(n == 0) + return; - for(i = 0, c = clients; c; c = c->next) - if(isvisible(c)) { - if(c->isbanned) - XMoveWindow(dpy, c->win, c->x, c->y); - c->isbanned = False; - if(c->isfloat) - continue; - c->ismax = False; - nx = wax; - ny = way; - if(i < nmaster) { - ny += i * mh; - nw = mw - 2 * BORDERPX; - nh = mh - 2 * BORDERPX; - } - else { /* tile window */ - nx += mw; - nw = tw - 2 * BORDERPX; - if(th > 2 * BORDERPX) { - ny += (i - nmaster) * th; - nh = th - 2 * BORDERPX; - } - else /* fallback if th <= 2 * BORDERPX */ - nh = wah - 2 * BORDERPX; - } - resize(c, nx, ny, nw, nh, False); - i++; - } - 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); + /* master */ + c = nextunfloating(clients); + + if(n == 1) + tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); + else + tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw); + + if(--n == 0) + return; + + /* tile stack */ + x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw; + y = ty; + w = (tx > c->x + c->w) ? wx + ww - x : tw; + h = th / n; + if(h < bh) + h = th; + + for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) { + if(i + 1 == n) /* remainder */ + tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw); + else + tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw); + if(h != th) + y = c->y + c->h + 2 * c->bw; } - restack(); } void -incnmaster(Arg *arg) { - if((arrange == dofloat) || (nmaster + arg->i < 1) - || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) - return; - nmaster += arg->i; - if(sel) - arrange(); - else - drawstatus(); +tileresize(Client *c, int x, int y, int w, int h) { + resize(c, x, y, w, h, resizehints); + if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) + /* client doesn't accept size constraints */ + resize(c, x, y, w, h, False); } void -resizemaster(Arg *arg) { - if(arrange != dotile) - return; - if(arg->i == 0) - master = MASTER; - else { - if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX - || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) +zoom(const char *arg) { + Client *c = sel; + + if(c == nextunfloating(clients)) + if(!c || !(c = nextunfloating(c->next))) return; - master += arg->i; + if(lt->arrange == tile && !sel->isfloating) { + detach(c); + attach(c); + focus(c); } arrange(); } void -zoom(Arg *arg) { - unsigned int n; - Client *c; +updatetilegeom(void) { + /* master area geometry */ + mx = wx; + my = wy; + mw = mfact * ww; + mh = wh; - if(!sel) - return; - if(sel->isfloat || (arrange == dofloat)) { - togglemax(sel); - return; - } - for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) - n++; - - if((c = sel) == nextmanaged(clients)) - if(!(c = nextmanaged(c->next))) - return; - detach(c); - if(clients) - clients->prev = c; - c->next = clients; - clients = c; - focus(c); - arrange(); + /* tile area geometry */ + tx = mx + mw; + ty = wy; + tw = ww - mw; + th = wh; }