-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
142 lines (120 loc) · 3.89 KB
/
main.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var loaded = {};
function load(fn) {
if (!loaded[fn]) {
require('phoenix/' + fn);
loaded[fn] = true;
}
}
load('utils.js');
load('Grid.js');
load('Screen.ext.js');
load('Window.ext.js');
var modSwitch = ['cmd'],
modMoveGrid = ['alt', 'cmd'],
modMoveFull = ['ctrl', 'alt', 'cmd'];
var screens = Screen.allScreensWithNames(function(screen, frame) {
// utils.debug(JSON.stringify(frame));
if (frame.width == 2560 && frame.height == 1440) {
return 'thunderbolt';
} else if (frame.width == 1440 && frame.height == 900) {
return 'retina';
} else {
throw new Error('Unrecognized screen: ' + JSON.stringify(frame));
}
});
if (screens.thunderbolt) {
withThunderbolt();
} else {
withoutThunderbolt();
}
function withThunderbolt() {
// Config if Thunderbolt screen is present: 3 grid layouts (5-square,
// left/right, full); always use full retina screen
var grid1 = new Grid(screens, 12, {
thunderbolt : {
topLeft : { x : [0, 6], y : [0, 7] },
topRight : { x : [6, 12], y : [0, 7] },
bottomLeft : { x : [0, 4], y : [7, 12] },
bottomMiddle : { x : [4, 8], y : [7, 12] },
bottomRight : { x : [8, 12], y : [7, 12] }
},
retina : {
full : { x : [0, 12], y : [0, 12] }
}
});
var grid2 = new Grid(screens, 12, {
thunderbolt : {
left : { x : [0, 6], y : [0, 12] },
right : { x : [6, 12], y : [0, 12] }
},
retina : {
full : { x : [0, 12], y : [0, 12] }
}
});
var grid3 = new Grid(screens, 12, {
thunderbolt : {
full : { x : [0, 12], y : [0, 12] }
},
retina : {
full : { x : [0, 12], y : [0, 12] }
}
});
// modMoveGrid + arrow keys moves windows around in the 5-square grid
// (grid1)
['left', 'right', 'up', 'down'].forEach(function(dir) {
api.bind(dir, modMoveGrid, function() {
Window.focusedWindow().moveInGrid(grid1, dir);
});
});
// modMoveFull + left / right move windows to left or right half of screen
// (grid2)
['left', 'right'].forEach(function(dir) {
api.bind(dir, modMoveFull, function() {
Window.focusedWindow().moveInGrid(grid2, dir);
});
});
// modMoveFull + up maximizes windows (grid3)
api.bind('up', modMoveFull, function() {
Window.focusedWindow().moveInGrid(grid3, 'up');
});
}
function withoutThunderbolt() {
// Config if Thunderbolt screen is not present: 5 possible positions:
// - top left corner
// - top right corner
// - bottom left corner
// - bottom right corner
// - maximized
// This allows easy switching between up to 4 windows at a time, or
// temporarily making use of all available screen real estate in one
// window.
var size = 12,
begin = [0, size - 1],
end = [1, size];
var grid1 = new Grid(screens, size, {
retina : {
topLeft : { x : begin, y : begin },
topRight : { x : end , y : begin },
bottomLeft : { x : begin, y : end },
bottomRight : { x : end , y : end },
}
});
var grid2 = new Grid(screens, size, {
retina : {
full : { x : [0, size], y : [0, size] }
}
});
// modMoveGrid + anything move windows to corners of screen
// (grid1)
['left', 'right', 'up', 'down'].forEach(function(dir) {
api.bind(dir, modMoveGrid, function() {
Window.focusedWindow().moveInGrid(grid1, dir);
});
});
// modMoveFull + anything maximizes windows (grid2)
['left', 'right', 'up', 'down'].forEach(function(dir) {
api.bind(dir, modMoveFull, function() {
Window.focusedWindow().moveInGrid(grid2, dir);
});
});
}