-
Notifications
You must be signed in to change notification settings - Fork 13
/
splitlayout.js
126 lines (110 loc) · 5.36 KB
/
splitlayout.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const Me = imports.misc.extensionUtils.getCurrentExtension();
const GnomesomeSettings = Me.imports.gnomesome_settings;
const logging = Me.imports.logging;
const logger = logging.getLogger('Gnomesome.Layout.Split');
function apply(gswindows, split_pos, n_master, orientation) {
const settings = new GnomesomeSettings.Prefs();
logger.debug("Info: relayout max_nwindows" + gswindows.length);
if (gswindows.length <= 0) {
// no windows available
return;
}
// check consistency and add allowed windows
var monitor_idx = gswindows[0].get_monitor();
var workspace = gswindows[0].get_workspace();
var gswindows_to_layout = gswindows;
for (var idx = 0; idx < gswindows.length; ++idx) {
gswindows[idx].unmaximize_if_not_floating();
}
const work_area = workspace.get_work_area_for_monitor(monitor_idx);
work_area.x += settings.OUTER_GAPS.get();
work_area.y += settings.OUTER_GAPS.get();
work_area.width -= 2 * settings.OUTER_GAPS.get();
work_area.height -= 2 * settings.OUTER_GAPS.get();
logger.debug("Info: windows to layout " + gswindows_to_layout.length);
var user = false;
// handle dependend on number of windows
if (gswindows_to_layout.length === 0) {
// nothing to do
} else if (gswindows_to_layout.length === 1) {
// only one image, fill work area
gswindows_to_layout[0].window.move_resize_frame(
user,
work_area.x, work_area.y,
work_area.width, work_area.height);
} else {
// determine areas
var gsmasters = gswindows_to_layout.slice(0, n_master);
var gsclients = gswindows_to_layout.slice(n_master, gswindows_to_layout.length);
logger.debug("master client" + gsmasters.length + " " + gsclients.length);
if (orientation === 1) {
// Horizontal layout
let master_width = work_area.width * split_pos - settings.INNER_GAPS.get() / 2;
let client_width = work_area.width - master_width - settings.INNER_GAPS.get();
if (gsclients.length === 0) {master_width = work_area.width; client_width = 0;}
if (gsmasters.length === 0) {master_width = 0; client_width = work_area.width;}
if (gsmasters.length > 0) {
const sub_height = (work_area.height - (gsmasters.length - 1) * settings.INNER_GAPS.get()) / gsmasters.length;
for (let idx = 0; idx < gsmasters.length; ++idx) {
// first image half size, all others in rows
gsmasters[idx].window.move_resize_frame(
user,
work_area.x,
work_area.y + idx * (sub_height + settings.INNER_GAPS.get()),
master_width, sub_height);
}
}
if (gsclients.length > 0) {
const sub_height = (work_area.height - (gsclients.length - 1) * settings.INNER_GAPS.get()) / gsclients.length;
for (let idx = 0; idx < gsclients.length; ++idx) {
gsclients[idx].window.move_resize_frame(
user,
work_area.x + master_width + settings.INNER_GAPS.get(),
work_area.y + idx * (sub_height + settings.INNER_GAPS.get()),
client_width, sub_height);
}
}
} else {
// vertical layout
let master_height = work_area.height * split_pos - settings.INNER_GAPS.get() / 2;
let client_height = work_area.height - master_height - settings.INNER_GAPS.get();
if (gsclients.length === 0) {master_height = work_area.height; client_height = 0;}
if (gsmasters.length === 0) {master_height = 0; client_height = work_area.height;}
if (gsmasters.length > 0) {
const sub_width = (work_area.width - (gsmasters.length - 1) * settings.INNER_GAPS.get()) / gsmasters.length;
for (let idx = 0; idx < gsmasters.length; ++idx) {
// first image half size, all others in rows
gsmasters[idx].window.move_resize_frame(
user,
work_area.x + idx * (sub_width + settings.INNER_GAPS.get()),
work_area.y,
sub_width, master_height);
}
}
if (gsclients.length > 0) {
var sub_width = (work_area.width - (gsclients.length - 1) * settings.INNER_GAPS.get()) / gsclients.length;
for (let idx = 0; idx < gsclients.length; ++idx) {
gsclients[idx].window.move_resize_frame(
user,
work_area.x + idx * (sub_width + settings.INNER_GAPS.get()),
work_area.y + master_height + settings.INNER_GAPS.get(),
sub_width, client_height);
}
}
}
}
}
function enterVBoxLayout(gswindows, split_pos, n_master) {
}
function applyVBoxLayout(gswindows, split_pos, n_master) {
apply(gswindows, split_pos, n_master, 1);
}
function exitVBoxLayout(gswindows, split_pos, n_master) {
}
function exitHBoxLayout(gswindows, split_pos, n_master) {
}
function applyHBoxLayout(gswindows, split_pos, n_master) {
apply(gswindows, split_pos, n_master, 0);
}
function enterHBoxLayout(gswindows, split_pos, n_master) {
}