-
Notifications
You must be signed in to change notification settings - Fork 1
/
phoenix.js
131 lines (117 loc) · 3.94 KB
/
phoenix.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
"use strict";
function centered_modal(message) {
var modal = new Modal();
modal.message = message;
var screen_frame = Screen.main().frameInRectangle();
var result_frame = modal.frame();
modal.origin = {
x: 0.5 * (screen_frame.width - result_frame.width),
y: 0.5 * (screen_frame.height - result_frame.height),
};
return modal;
}
var h_reload = new Key('r', ['alt'], function () {
Phoenix.reload();
});
/* Window Handling */
function move_window(rect, screen) {
screen = screen || Screen.main();
var scr = screen.visibleFrameInRectangle();
var r = {
x: Math.round(scr.x + rect.x*scr.width),
y: Math.round(scr.y + rect.y*scr.height),
width: Math.round(scr.width * rect.width),
height: Math.round(scr.height * rect.height),
};
Window.focused().setFrame(r);
}
function move_window_to_next_screen() {
var currW = Window.focused();
var cwFrame = currW.frame();
var currScreen = currW.screen();
var nextScreen = currScreen.next();
var currScreenSize = currScreen.visibleFrameInRectangle();
var relative = {
x: (cwFrame.x - currScreenSize.x) / currScreenSize.width,
y: (cwFrame.y - currScreenSize.y) / currScreenSize.height,
width: cwFrame.width / currScreenSize.width,
height: cwFrame.height / currScreenSize.height,
};
move_window(relative, nextScreen);
}
/* Spaces */
/* Support a prefix key with multiple suffix keys */
function PrefixKey(key, modifiers, description) {
this.modal = centered_modal(description);
this.suffixes = [];
this.handlers = [];
var that = this;
this.prefix = new Key(key, modifiers, function () {
that.enableSuffixes();
that.modal.show();
});
}
PrefixKey.prototype.enableSuffixes = function () {
var that = this;
this.suffixes.forEach(function (x) {
var h = new Key(x.key, x.modifiers, function () {
that.disableSuffixes();
x.cb();
that.modal.close();
Phoenix.reload();
});
h.enable();
that.handlers.push(h);
});
};
PrefixKey.prototype.disableSuffixes = function () {
this.handlers.forEach( function (x) {
x.disable();
});
this.handlers = [];
};
PrefixKey.prototype.addSuffix = function (key, modifiers, cb) {
this.suffixes.push({key: key, modifiers: modifiers, cb: cb});
};
/* Window handling prefix key */
var wPrefix = new PrefixKey('space', ['alt'],
"h/l - Left/Right Half\nj/k – Top/Bottom Half\nc - Center\ng - Wide Center\nf - Max\no/p - big left/right\nO/P - medium left/right\ns - next screen\nesc - Abort");
wPrefix.addSuffix('h', [], function () {
move_window({x: 0, y: 0, width: 0.5, height: 1.0});
});
wPrefix.addSuffix('l', [], function () {
move_window({x: 0.5, y: 0, width: 0.5, height: 1.0});
});
wPrefix.addSuffix('j', [], function () {
move_window({x: 0, y: 0.5, width: 1.0, height: 0.5});
});
wPrefix.addSuffix('k', [], function () {
move_window({x: 0, y: 0, width: 1.0, height: 0.5});
});
wPrefix.addSuffix('g', [], function () {
move_window({x: 0.15, y: 0, width: 0.7, height: 1.0});
});
wPrefix.addSuffix('f', [], function () {
move_window({x: 0, y: 0, width: 1.0, height: 1.0});
});
wPrefix.addSuffix('c', [], function () {
move_window({x: 0.2, y: 0.2, width: 0.6, height: 0.6});
});
wPrefix.addSuffix('o', [], function () {
move_window({x: 0, y: 0, width: 0.9, height: 1.0});
});
wPrefix.addSuffix('o', ['shift'], function () {
move_window({x: 0, y: 0, width: 0.8, height: 1.0});
});
wPrefix.addSuffix('p', [], function () {
move_window({x: 0.1, y: 0, width: 0.9, height: 1.0});
});
wPrefix.addSuffix('p', ['shift'], function () {
move_window({x: 0.2, y: 0, width: 0.8, height: 1.0});
});
wPrefix.addSuffix('s', [], function () {
move_window_to_next_screen();
});
// Exit from the phoenix prefix mode
wPrefix.addSuffix('escape', [], function () {});
wPrefix.addSuffix('space', ['alt'], function () {});