all repos — dwm @ 2d81b78b853565a3e34a8a9190e2362a6fdde739

fork of suckless dynamic window manager

tile.c (view raw)

 1/* See LICENSE file for copyright and license details. */
 2#include "dwm.h"
 3#include <stdio.h>
 4
 5/* static */
 6
 7static double master = MASTER;
 8
 9/* extern */
10
11void
12incmaster(const char *arg) {
13	double delta;
14
15	if(lt->arrange != tile)
16		return;
17
18	/* arg handling, manipulate master */
19	if(arg && (1 == sscanf(arg, "%lf", &delta))) {
20		if(delta + master > 0.1 && delta + master < 0.9)
21			master += delta;
22	}
23
24	lt->arrange();
25}
26
27void
28tile(void) {
29	unsigned int i, n, nx, ny, nw, nh, mw, th;
30	Client *c;
31
32	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
33		n++;
34
35	/* window geoms */
36	mw = (n == 1) ? waw : master * waw;
37	th = (n > 1) ? wah / (n - 1) : 0;
38	if(n > 1 && th < bh)
39		th = wah;
40
41	nx = wax;
42	ny = way;
43	for(i = 0, c = clients; c; c = c->next)
44		if(isvisible(c)) {
45			unban(c);
46			if(c->isfloating)
47				continue;
48			c->ismax = False;
49			if(i == 0) { /* master */
50				nw = mw - 2 * c->border;
51				nh = wah - 2 * c->border;
52			}
53			else {  /* tile window */
54				if(i == 1) {
55					ny = way;
56					nx += mw;
57				}
58				nw = waw - mw - 2 * c->border;
59				if(i + 1 == n) /* remainder */
60					nh = (way + wah) - ny - 2 * c->border;
61				else
62					nh = th - 2 * c->border;
63			}
64			resize(c, nx, ny, nw, nh, False);
65			if(n > 1 && th != wah)
66				ny += nh + 2 * c->border;
67			i++;
68		}
69		else
70			ban(c);
71	focus(NULL);
72	restack();
73}
74
75void
76zoom(const char *arg) {
77	Client *c;
78
79	if(!sel || lt->arrange == floating || sel->isfloating)
80		return;
81	if((c = sel) == nexttiled(clients))
82		if(!(c = nexttiled(c->next)))
83			return;
84	detach(c);
85	attach(c);
86	focus(c);
87	lt->arrange();
88}