all repos — dwm @ 71365a524f67235024de7db277c63f8ac4f46569

fork of suckless dynamic window manager

tile.c (view raw)

  1/* See LICENSE file for copyright and license details. */
  2int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;
  3
  4void setmfact(const char *arg);
  5void tile(void);
  6void tileresize(Client *c, int x, int y, int w, int h);
  7void updatetilegeom(void);
  8
  9void
 10setmfact(const char *arg) {
 11	double d;
 12
 13	if(!arg || lt->arrange != tile)
 14		return;
 15	else {
 16		d = strtod(arg, NULL);
 17		if(arg[0] == '-' || arg[0] == '+')
 18			d += mfact;
 19		if(d < 0.1 || d > 0.9)
 20			return;
 21		mfact = d;
 22	}
 23	updatetilegeom();
 24	arrange();
 25}
 26
 27void
 28tile(void) {
 29	int y, h;
 30	unsigned int i, n;
 31	Client *c;
 32
 33	for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++);
 34	if(n == 0)
 35		return;
 36
 37	/* master */
 38	c = nextunfloating(clients);
 39
 40	if(n == 1)
 41		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
 42	else
 43		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
 44
 45	if(--n == 0)
 46		return;
 47
 48	/* tile stack */
 49	y = ty;
 50	h = th / n;
 51	if(h < bh)
 52		h = th;
 53
 54	for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
 55		if(i + 1 == n) /* remainder */
 56			tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw);
 57		else
 58			tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw);
 59		if(h != th)
 60			y = c->y + c->h + 2 * c->bw;
 61	}
 62}
 63
 64void
 65tileresize(Client *c, int x, int y, int w, int h) {
 66	resize(c, x, y, w, h, resizehints);
 67	if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
 68		/* client doesn't accept size constraints */
 69		resize(c, x, y, w, h, False);
 70}
 71
 72void
 73zoom(const char *arg) {
 74	Client *c = sel;
 75
 76	if(c == nextunfloating(clients))
 77		if(!c || !(c = nextunfloating(c->next)))
 78			return;
 79	if(lt->arrange == tile && !sel->isfloating) {
 80		detach(c);
 81		attach(c);
 82		focus(c);
 83	}
 84	arrange();
 85}
 86
 87void
 88updatetilegeom(void) {
 89	/* master area geometry */
 90	mx = wx;
 91	my = wy;
 92	mw = mfact * ww;
 93	mh = wh;
 94
 95	/* tile area geometry */
 96	tx = mx + mw;
 97	ty = wy;
 98	tw = ww - mw;
 99	th = wh;
100}