-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathhelper.js
230 lines (200 loc) · 7.87 KB
/
helper.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
* Arc Menu: The new applications menu for Gnome 3.
*
* Copyright (C) 2017 LinxGem33
* Copyright (C) 2017 Alexander Rüedlinger
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Import Libraries
const Lang = imports.lang;
const Main = imports.ui.main;
const Meta = imports.gi.Meta;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Shell = imports.gi.Shell;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Constants = Me.imports.constants;
// Local constants
const MUTTER_SCHEMA = 'org.gnome.mutter';
const WM_KEYBINDINGS_SCHEMA = 'org.gnome.desktop.wm.keybindings';
/**
* The Menu HotKeybinder class helps us to bind and unbind a menu hotkey
* to the Arc Menu. Currently, valid hotkeys are Super_L and Super_R.
*/
var MenuHotKeybinder = new Lang.Class({
Name: 'ArcMenu.MenuHotKeybinder',
_init: function(menuToggler) {
this._menuToggler = menuToggler;
this._mutterSettings = new Gio.Settings({ 'schema': MUTTER_SCHEMA });
this._wmKeybindings = new Gio.Settings({ 'schema': WM_KEYBINDINGS_SCHEMA });
this._keybindingHandlerId = Main.layoutManager.connect('startup-complete',
Lang.bind(this, this._setKeybindingHandler));
this._setKeybindingHandler();
},
// Enable a hot key for opening the menu
enableHotKey: function(hotkey) {
if (hotkey == Constants.SUPER_L) {
this._disableOverlayKey();
} else {
this._enableOverlayKey();
}
this._wmKeybindings.set_strv('panel-main-menu', [hotkey]);
},
// Disable the set hot key for opening the menu
disableHotKey: function() {
// Restore the default settings
if (this._isOverlayKeyDisabled()) {
this._enableOverlayKey();
}
let defaultPanelMainMenu = this._wmKeybindings.get_default_value('panel-main-menu');
this._wmKeybindings.set_value('panel-main-menu', defaultPanelMainMenu);
},
// Set the menu keybinding handler
_setKeybindingHandler: function() {
Main.wm.setCustomKeybindingHandler('panel-main-menu',
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
Lang.bind(this, this._menuToggler));
},
// Check if the overlay keybinding is disabled in mutter
_isOverlayKeyDisabled: function() {
return this._mutterSettings.get_string('overlay-key') == Constants.EMPTY_STRING;
},
// Disable the overlay keybinding in mutter
_disableOverlayKey: function() {
// Simple hack to deactivate the overlay key by setting
// the keybinding of the overlay key to an empty string
this._mutterSettings.set_string('overlay-key', Constants.EMPTY_STRING);
},
// Enable and restore the default settings of the overlay key in mutter
_enableOverlayKey: function() {
this._mutterSettings.set_value('overlay-key', this._getDefaultOverlayKey());
},
// Get the default overelay keybinding from mutter
_getDefaultOverlayKey: function() {
return this._mutterSettings.get_default_value('overlay-key');
},
// Destroy this object
destroy: function() {
// Clean up and restore the default behaviour
this.disableHotKey();
if (this._keybindingHandlerId) {
// Disconnect the keybinding handler
Main.layoutManager.disconnect(this._keybindingHandlerId);
this._keybindingHandlerId = null;
}
}
});
/**
* The Keybinding Manager class allows us to bind and unbind keybindings
* to a keybinding handler.
*/
var KeybindingManager = new Lang.Class({
Name: 'ArcMenu.KeybindingManager',
_init: function(settings) {
this._settings = settings;
this._keybindings = new Map();
},
// Bind a keybinding to a keybinding handler
bind: function(keybindingNameKey, keybindingValueKey, keybindingHandler) {
if (!this._keybindings.has(keybindingNameKey)) {
this._keybindings.set(keybindingNameKey, keybindingValueKey);
let keybinding = this._settings.get_string(keybindingNameKey);
this._setKeybinding(keybindingNameKey, keybinding);
Main.wm.addKeybinding(keybindingValueKey, this._settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
Lang.bind(this, keybindingHandler));
return true;
}
return false;
},
// Set or update a keybinding in the Arc Menu settings
_setKeybinding: function(keybindingNameKey, keybinding) {
if (this._keybindings.has(keybindingNameKey)) {
let keybindingValueKey = this._keybindings.get(keybindingNameKey);
let [key, mods] = Gtk.accelerator_parse(keybinding);
if (Gtk.accelerator_valid(key, mods)) {
let shortcut = Gtk.accelerator_name(key, mods);
this._settings.set_strv(keybindingValueKey, [shortcut]);
} else {
this._settings.set_strv(keybindingValueKey, []);
}
}
},
// Unbind a keybinding
unbind: function(keybindingNameKey) {
if (this._keybindings.has(keybindingNameKey)) {
let keybindingValueKey = this._keybindings.get(keybindingNameKey);
Main.wm.removeKeybinding(keybindingValueKey);
this._keybindings.delete(keybindingNameKey);
return true;
}
return false;
},
// Destroy this object
destroy: function() {
let keyIter = this._keybindings.keys();
for (let i = 0; i < this._keybindings.size; i++) {
let keybindingNameKey = keyIter.next().value;
this.unbind(keybindingNameKey);
}
}
});
/**
* The Hot Corner Manager class allows us to disable and enable
* the gnome-shell hot corners.
*/
var HotCornerManager = new Lang.Class({
Name: 'ArcMenu.HotCornerManager',
_init: function(settings) {
this._settings = settings;
this._hotCornersChangedId = Main.layoutManager.connect('hot-corners-changed', Lang.bind(this, this._redisableHotCorners));
},
_redisableHotCorners: function() {
if (this._settings.get_boolean('disable-activities-hotcorner')) {
this.disableHotCorners();
}
},
// Get all hot corners from the main layout manager
_getHotCorners: function() {
return Main.layoutManager.hotCorners;
},
// Enable all hot corners
enableHotCorners: function() {
// Restore the default behaviour and recreate the hot corners
Main.layoutManager._updateHotCorners();
},
// Disable all hot corners
disableHotCorners: function() {
let hotCorners = this._getHotCorners();
// Monkey patch each hot corner
hotCorners.forEach(function(corner) {
if (corner) {
corner._toggleOverview = function() {};
corner._pressureBarrier._trigger = function() {};
}
});
},
// Destroy this object
destroy: function() {
if (this._hotCornersChangedId) {
Main.layoutManager.disconnect(this._hotCornersChangedId);
this._hotCornersChangedId = null;
}
// Clean up and restore the default behaviour
this.enableHotCorners();
}
});