Repository navigation
Expand file tree
/
Copy pathwide.js
More file actions
66 lines (65 loc) · 2.6 KB
/
Copy pathwide.js
File metadata and controls
66 lines (65 loc) · 2.6 KB
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
/**
* This is a hot loadable layout for nwm. See module.exports
* at end of the file for details.
*
* Bottom Stack Tiling (a.k.a. wide)
*
* +----------+----------+ +----------+----------+
* | | | |
* | | | |
* | | | |
* +---------------------+ +---------------------+
* | | | | |
* | | | | |
* | | | | |
* +---------------------+ +---------------------+
* 2 windows 3 windows
*
* +---------------------+ +---------------------+
* | | | |
* | | | |
* | | | |
* +------+-------+------+ +----+-----+-----+----+
* | | | | | | | | |
* | | | | | | | | |
* | | | | | | | | |
* +------+-------+------+ +----+-----+-----+----+
* 4 windows 5 windows
*/
function wide(workspace) {
// the way DWM does it is to reserve half the screen for the first screen,
// then split the other half among the rest of the screens
var windows = workspace.visible();
var screen = workspace.monitor;
var window_ids = Object.keys(windows);
if(window_ids.length < 1) {
return;
}
var mainId = workspace.mainWindow;
if(window_ids.length == 1) {
windows[mainId].move(screen.x, screen.y);
windows[mainId].resize(screen.width, screen.height);
} else {
// when main scale = 50, the divisor is 2
var mainScaleFactor = (100 / workspace.getMainWindowScale() );
var halfHeight = Math.floor(screen.height / mainScaleFactor);
windows[mainId].move(screen.x, screen.y);
windows[mainId].resize(screen.width, halfHeight);
// remove from visible
window_ids = window_ids.filter(function(id) { return (id != mainId); });
var remainHeight = screen.height - halfHeight;
var sliceWidth = Math.floor(screen.width / (window_ids.length) );
window_ids.forEach(function(id, index) {
windows[id].move(screen.x + index*sliceWidth, screen.y + halfHeight);
windows[id].resize(sliceWidth, remainHeight);
});
}
};
// Hot loading works like this:
// You export a callback function, which gets called every time
// a hot load needs to occur.
// The function gets the running instance of nwm, and does it's thing
// e.g. adds a new layout etc.
module.exports = function(nwm) {
nwm.addLayout('wide', wide);
};