forked from yqrashawn/yqdotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.phoenix.js
149 lines (130 loc) · 3.09 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env babel
/* -*- mode: js2 -*- */
/**
* @fileOverview phoenix configuration file
* @name .phoenix.js
* @author Rashawn Zhang <[email protected]@gmail.com>
*/
g = this;
const screens = Screen.all();
const screenLeft = screens[0];
const screenRight = screens[1];
var WINDOW_LIST = Window.all();
const IGNORED_APP = [
"Contexts",
"Qbserve",
"Unclutter",
"Emacs",
"Google Chrome",
"iTerm2",
"Finder",
"Phoenix",
"BearyChat",
"Karabiner-Elements",
"Karabiner-EventViewer",
"Alfred 3",
"CleanMyMac 3 Menu",
"Bartender 2",
"WeChat",
"Dash",
"Code",
"Mail",
];
const filterList = function(w) {
WINDOW_LIST = WINDOW_LIST.filter(function(window) {
if (window && window.app()) {
if (!window.title().length) return false;
if (IGNORED_APP.indexOf(window.app().name()) !== -1) return false;
if (w && window.hash() !== w.hash()) return true;
if (!w) return true;
}
});
};
const refresh = function() {
WINDOW_LIST = Window.all();
filterList();
};
const windowOpen = new Event("windowDidOpen", function(w) {
refresh();
});
const windowFocus = new Event("windowDidFocus", function(w) {
refresh();
});
const windowDidClose = new Event("windowDidClose", function(w) {
refresh();
});
const appDidTerminate = new Event("appDidTerminate", function(app) {
refresh();
});
const tmodal = new Modal();
g.tmodal = tmodal;
tmodal.duration = 0;
tmodal.origin = { x: 0, y: 600 };
var switchToSecondPrevWindow = new Key(
"f16",
["alt", "ctrl", "shift"],
function() {
if (WINDOW_LIST[2]) return WINDOW_LIST[2].focus();
if (WINDOW_LIST[1]) return WINDOW_LIST[1].focus();
}
);
const trucate = function(str) {
if (str.length > 15) {
str = str.substr(0, 15);
const spaceIdx = str.lastIndexOf(" ");
if (spaceIdx !== -1) {
str = str.substr(0, spaceIdx + 1);
}
}
return str;
};
const numToHomeRow = ["space", "a", "s", "d", "f", "h", "j", "k", "l"];
var keys = [];
var switchTo = new Key("f16", ["alt", "ctrl"], function() {
filterList();
tmodal.text = WINDOW_LIST.map(function(window, index) {
return `[${
numToHomeRow[index]
}] - ${window.app().name()} - ${trucate(window.title())}`;
})
.toString()
.replace(/,/g, "\n");
if (WINDOW_LIST.length === 0) {
tmodal.text = "no uncontrolled window";
tmodal.duration = 1;
} else {
tmodal.duration = 0;
}
keys.forEach(function(keyHandler) {
keyHandler.disable();
});
WINDOW_LIST.forEach(function(window, index) {
keys.push(
new Key(numToHomeRow[index], [], function(key) {
WINDOW_LIST[index].raise();
WINDOW_LIST[index].focus();
tmodal.close();
keys.forEach(function(keyHandler) {
keyHandler.disable();
});
})
);
});
keys.push(
new Key("escape", [], function() {
tmodal.close();
keys.forEach(function(keyHandler) {
keyHandler.disable();
});
})
);
keys.push(
new Key("g", ["ctrl"], function() {
tmodal.close();
keys.forEach(function(keyHandler) {
keyHandler.disable();
});
})
);
tmodal.show();
});