forked from rliang/gnome-shell-extension-tilingnome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layouts.js
47 lines (45 loc) · 1.76 KB
/
layouts.js
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
function horizontal(settings, wins, { x, y, width, height }) {
const sr = settings.get_double('split-ratio');
const mc = settings.get_uint('master-count');
const w1 = mc < wins.length ? Math.floor(width * sr) : width;
return wins.slice(0, mc).map((_, i, part) => ({
x: x,
y: y + (i * height / part.length),
width: w1,
height: Math.ceil(height / part.length)
})).concat(wins.slice(mc).map((_, i, part) => ({
x: x + w1,
y: y + (i * height / part.length),
width: width - w1,
height: Math.ceil(height / part.length)
})));
}
function vertical(settings, wins, { x, y, width, height }) {
const sr = settings.get_double('split-ratio');
const mc = settings.get_uint('master-count');
const h1 = mc < wins.length ? Math.floor(height * sr) : height;
return wins.slice(0, mc).map((_, i, part) => ({
x: x + (i * width / part.length),
y: y,
width: Math.ceil(width / part.length),
height: h1
})).concat(wins.slice(mc).map((_, i, part) => ({
x: x + (i * width / part.length),
y: y + h1,
width: Math.ceil(width / part.length),
height: height - h1
})));
}
function spiral(settings, wins, area, part) {
if (wins.length === 1)
return [area];
part = part || 0;
const sr = settings.get_double('split-ratio');
const mr = [
{x: area.x, y: area.y, width: area.width * sr, height: area.height},
{x: area.x, y: area.y, width: area.width, height: area.height * sr},
{x: area.x + area.width * sr, y: area.y, width: area.width * (1 - sr), height: area.height},
{x: area.x, y: area.y + area.height * sr, width: area.width, height: area.height * (1 - sr)},
];
return [mr[part]].concat(spiral(settings, wins.slice(1), mr[[2, 3, 0, 1][part]], part + 1 > 3 ? 0 : part + 1));
}