forked from gTile/gTile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotkeys.ts
69 lines (61 loc) · 2.03 KB
/
hotkeys.ts
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
import {log} from './logging';
import { KeyBindingSettingName } from './settings_data';
declare const imports: any;
declare const global: any;
// Library imports
const Main = imports.ui.main;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
// Extension imports
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Settings = Me.imports.settings;
/**
* Bindings is a dictionary that maps a hotkey name to a function that handles
* the press of the key that is bound to that action.
*/
export type Bindings = Map<KeyBindingSettingName, () => void>;
export type BindingsOld = {[name in KeyBindingSettingName]: () => void};
export function bind(keyBindings: Bindings) {
log("Binding keys");
let mySettings = Settings.get();
keyBindings.forEach((callback: () => void, key: KeyBindingSettingName) => {
//const key = keyString as KeyBindingSettingName;
if (Main.wm.addKeybinding && Shell.ActionMode) { // introduced in 3.16
Main.wm.addKeybinding(
key,
mySettings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL,
callback
);
}
else if (Main.wm.addKeybinding && Shell.KeyBindingMode) { // introduced in 3.7.5
Main.wm.addKeybinding(
key,
mySettings,
Meta.KeyBindingFlags.NONE,
Shell.KeyBindingMode.NORMAL | Shell.KeyBindingMode.MESSAGE_TRAY,
callback
);
}
else {
global.display.add_keybinding(
key,
mySettings,
Meta.KeyBindingFlags.NONE,
callback
);
}
});
}
export function unbind(keyBindings: Bindings) {
log("Unbinding keys");
for (let key of keyBindings.keys()) {
if (Main.wm.removeKeybinding) { // introduced in 3.7.2
Main.wm.removeKeybinding(key);
}
else {
global.display.remove_keybinding(key);
}
}
}