-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
48 lines (41 loc) · 1.15 KB
/
extension.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
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import Config from './config.js';
import KeyBinder from './keybinder.js';
import Window from './window.js';
export default class ScratchpadExtension extends Extension {
enable() {
log("[gnome-scratchpad] enabling extension");
this.config = new Config().parse();
this.keyBinder = new KeyBinder();
this.applyBindings();
}
applyBindings() {
for (const binding of this.config.bindings) {
this.keyBinder.listenFor(binding.keybind, () => {
this.toggleWindow(binding);
});
}
this.keyBinder.listenFor(this.config.hide_keybind, () => {
this.hideWindows();
});
}
disable() {
log("[gnome-scratchpad] disabling extension");
this.keyBinder.clearBindings();
}
toggleWindow(binding) {
let win = Window.find(binding);
if (win === null) { return; }
if (win.focused()) {
win.hide();
} else {
win.arrange(this.config.window_width, this.config.window_height);
win.show();
}
}
hideWindows() {
for (const binding of this.config.bindings) {
Window.find(binding)?.hide();
}
}
}