fibonacci.c 1.4 K raw
1
void
2
fibonacci(Monitor *mon, int s) {
3
	unsigned int i, n, nx, ny, nw, nh;
4
	Client *c;
5
6
	for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
7
	if(n == 0)
8
		return;
9
10
	nx = mon->wx + mon->gappx;
11
	ny = mon->wy + mon->gappx;
12
	nw = mon->ww - 2 * mon->gappx;
13
	nh = mon->wh - 2 * mon->gappx;
14
	
15
	for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
16
		if((i % 2 && (nh - mon->gappx) / 2 > 2 * c->bw)
17
		   || (!(i % 2) && (nw - mon->gappx) / 2 > 2 * c->bw)) {
18
			if(i < n - 1) {
19
				if(i % 2)
20
					nh = (nh - mon->gappx) / 2;
21
				else
22
					nw = (nw - mon->gappx) / 2;
23
				if((i % 4) == 2 && !s)
24
					nx += nw + mon->gappx;
25
				else if((i % 4) == 3 && !s)
26
					ny += nh + mon->gappx;
27
			}
28
			if((i % 4) == 0) {
29
				if(s)
30
					ny += nh + mon->gappx;
31
				else
32
					ny -= nh + mon->gappx;
33
			}
34
			else if((i % 4) == 1)
35
				nx += nw + mon->gappx;
36
			else if((i % 4) == 2)
37
				ny += nh + mon->gappx;
38
			else if((i % 4) == 3) {
39
				if(s)
40
					nx += nw + mon->gappx;
41
				else
42
					nx -= nw + mon->gappx;
43
			}
44
			if(i == 0)
45
			{
46
				if(n != 1)
47
					nw = (mon->ww - 2 * mon->gappx) * mon->mfact;
48
				ny = mon->wy + mon->gappx;
49
			}
50
			else if(i == 1)
51
				nw = mon->ww - nw - mon->gappx - 2 * mon->gappx;
52
			i++;
53
		}
54
		resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
55
	}
56
}
57
58
void
59
dwindle(Monitor *mon) {
60
	fibonacci(mon, 1);
61
}
62
63
void
64
spiral(Monitor *mon) {
65
	fibonacci(mon, 0);
66
}