~kaction/dvtm

ref: 68d08a5ba688c7a74a7ba6e1b7d87bcaa1374ab5 dvtm/fibonacci.c -rw-r--r-- 1.9 KiB
68d08a5b — Dmitry Bogatov Release 0.15.1 10 months ago
`                                                                                `
```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94```
```static void fibonacci(int s)
{
unsigned int nx, ny, nw, nnw, nh, nnh, i, n, mod;
Client *c;

for (n = 0, c = nextvisible(clients); c; c = nextvisible(c->next))
if (!c->minimized)
n++;

/* initial position and dimensions */
nx = wax;
ny = way;
nw = (n == 1) ? waw : screen.mfact * waw;
/* don't waste space dviding by 2 doesn't work for odd numbers
* plus we need space for the border too. therefore set up these
* variables for the next new width/height
*/
nnw = waw - nw - 1;
nnh = nh = wah;

/* set the mod factor, 2 for dwindle, 4 for spiral */
mod = s ? 4 : 2;

for (i = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) {
if (c->minimized)
continue;
/* dwindle: even case, spiral: case 0 */
if (i % mod == 0) {
if (i) {
if (s) {
nh = nnh;
ny -= nh;
} else {
ny += nh;
nh = nnh;
}
/* don't adjust the width for the last client */
if (i < n - 1) {
nw /= 2;
nnw -= nw + 1;
}
}
} else if (i % mod == 1) {	/* dwindle: odd case, spiral: case 1 */
nx += nw;
mvvline(ny, nx, ACS_VLINE, nh);
++nx;
nw = nnw;
/* don't adjust the height for the last client */
if (i < n - 1) {
nh /= 2;
nnh -= nh;
}
} else if (i % mod == 2 && s) {	/* spiral: case 2 */
ny += nh;
nh = nnh;
/* don't adjust the width for the last client */
if (i < n - 1) {
nw /= 2;
nnw -= nw + 1;
nx += nnw;
mvvline(ny, nx, ACS_VLINE, nh);
++nx;
} else {
}
} else if (s) {	/* spiral: case 3 */
nw = nnw;
nx -= nw + 1;	/* border */
/* don't adjust the height for the last client */
if (i < n - 1) {
nh /= 2;
nnh -= nh;
ny += nnh;
}
}

resize(c, nx, ny, nw, nh);
i++;
}
}

static void spiral(void)
{
fibonacci(1);
}

static void dwindle(void)
{
fibonacci(0);
}
```