-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathkeybinder.js
More file actions
129 lines (106 loc) · 5.8 KB
/
keybinder.js
File metadata and controls
129 lines (106 loc) · 5.8 KB
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
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
This file is part of CoverflowAltTab.
CoverflowAltTab is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CoverflowAltTab is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CoverflowAltTab. If not, see <http://www.gnu.org/licenses/>.
*/
/* CoverflowAltTab::Keybinder
*
* Originally, created to be helper classes to handle the different keybinding APIs.
*/
import Shell from 'gi://Shell';
import Meta from 'gi://Meta';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import {__ABSTRACT_METHOD__} from './lib.js'
class AbstractKeybinder {
enable() { __ABSTRACT_METHOD__(this, this.enable) }
disable() { __ABSTRACT_METHOD__(this, this.disable) }
}
export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder {
constructor(settings, ...args) {
super(...args);
this._settings = settings;
this._startAppSwitcherBind = null;
this._keybindingActions = new Map();
}
getAction(actionName) {
return this._keybindingActions.get(actionName);
}
addKeybinding(actionName) {
let action = Main.wm.addKeybinding(
actionName,
this._settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL,
() => {}
);
this._keybindingActions.set(actionName, action)
action = Main.wm.addKeybinding(
actionName + "-backward",
this._settings,
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL,
() => {}
)
this._keybindingActions.set(actionName + "-backward", action)
}
removeKeybinding(actionName) {
Main.wm.removeKeybinding(actionName);
this._keybindingActions.delete(actionName);
Main.wm.removeKeybinding(actionName + "-backward");
this._keybindingActions.delete(actionName + "-backward");
}
enable(startAppSwitcherBind, platform) {
let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode;
this._startAppSwitcherBind = startAppSwitcherBind;
platform.addSettingsChangedCallback(this._onSettingsChanged.bind(this));
this.addKeybinding("coverflow-switch-windows");
this.addKeybinding("coverflow-switch-applications");
Main.wm.setCustomKeybindingHandler('switch-group', mode.NORMAL, startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-group-backward', mode.NORMAL, startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler("coverflow-switch-windows", mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler("coverflow-switch-windows-backward", mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler("coverflow-switch-applications", mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler("coverflow-switch-applications-backward", mode.NORMAL, this._startAppSwitcherBind);
}
disable() {
let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode;
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-group', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-group-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
this.removeKeybinding("coverflow-switch-windows");
this.removeKeybinding("coverflow-switch-applications");
}
_onSettingsChanged(settings, key=null) {
let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode;
if (key === null || key === 'bind-to-switch-applications') {
if (settings.get_boolean('bind-to-switch-applications')) {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, this._startAppSwitcherBind);
} else {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
}
}
if (key === null || key === 'bind-to-switch-windows') {
if (settings.get_boolean('bind-to-switch-windows')) {
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, this._startAppSwitcherBind);
} else {
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
}
}
}
}