forked from TypicalFence/Amethyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic-ratio-tall.js
51 lines (49 loc) · 2.01 KB
/
static-ratio-tall.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
function layout() {
return {
name: "Static Ratio Tall",
initialState: {
mainPaneCount: 1
},
commands: {
command3: {
description: "Increase main pane count",
updateState: (state) => {
return { ...state, mainPaneCount: state.mainPaneCount + 1 };
}
},
command4: {
description: "Decrease main pane count",
updateState: (state) => {
return { ...state, mainPaneCount: Math.max(1, state.mainPaneCount - 1) };
}
}
},
getFrameAssignments: (windows, screenFrame, state) => {
const mainPaneCount = Math.min(state.mainPaneCount, windows.length);
const secondaryPaneCount = windows.length - mainPaneCount;
const hasSecondaryPane = secondaryPaneCount > 0;
const mainPaneWindowHeight = Math.round(screenFrame.height / mainPaneCount);
const secondaryPaneWindowHeight = Math.round(hasSecondaryPane ? (screenFrame.height / secondaryPaneCount) : 0);
return windows.reduce((frames, window, index) => {
const isMain = index < mainPaneCount;
let frame;
if (isMain) {
frame = {
x: screenFrame.x,
y: screenFrame.y + mainPaneWindowHeight * index,
width: screenFrame.width / 2,
height: mainPaneWindowHeight
};
} else {
frame = {
x: screenFrame.x + screenFrame.width / 2,
y: screenFrame.y + secondaryPaneWindowHeight * (index - mainPaneCount),
width: screenFrame.width / 2,
height: secondaryPaneWindowHeight
}
}
return { ...frames, [window.id]: frame };
}, {});
}
};
}