forked from G-dH/custom-hot-corners-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
387 lines (325 loc) · 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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/**
* Custom Hot Corners - Extended
*
* @author GdH <[email protected]>
* @copyright 2021-2024
* @license GPL-3.0
*/
'use strict';
import GLib from 'gi://GLib';
import Meta from 'gi://Meta';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as AltTab from 'resource:///org/gnome/shell/ui/altTab.js';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Settings from './src/common/settings.js';
import * as HotCorners from './src/extension/hotCorners.js';
import * as PanelButton from './src/extension/panelButton.js';
import * as ActionTrigger from './src/extension/actionTrigger.js';
import * as ActionList from './src/prefs/actionList.js';
import * as Actions from './src/extension/actions.js';
import * as Utils from './src/common/utils.js';
let chce;
export default class CustomHotCornersExtended extends Extension {
_init() {
chce = this;
Utils.init(this);
ActionList.init(this);
HotCorners.init(this);
ActionTrigger.init(this);
Actions.init(this);
PanelButton.init(this);
Settings.init(this);
this._mscOptions = null;
this.CORNERS_VISIBLE = false;
this.RIPPLE_ANIMATION = true;
this.BARRIER_FALLBACK = false;
this._myCorners = [null, null];
this._delayId = 0;
this._timeoutsCollector = [];
this._cornersCollector = [];
this._actorsCollector = [];
this._actionTimeoutId = null;
this._extensionEnabled = false;
this._watch = {};
this._listTriggers = Settings.listTriggers();
}
enable() {
this._init();
this._origUpdateHotCorners = Main.layoutManager._updateHotCorners;
this._extensionEnabled = true;
this._mscOptions = new Settings.MscOptions();
if (!this.actionTrigger)
this.actionTrigger = new ActionTrigger.ActionTrigger(this._mscOptions);
this._updateMscOptions(null, true);
this._replace_updateHotCornersFunc();
this._updateWatch();
this._updateSupportedExtensionsAvailability();
this._mscOptions.set('showOsdMonitorIndexes', false);
this._mscOptions.connect('changed', (settings, key) => this._updateMscOptions(key));
// this._originalHotCornerEnabled = Main.layoutManager._interfaceSettings.get_boolean('enable-hot-corners');
let enableDelay;
if (this.actionTrigger)
enableDelay = 1;
else
enableDelay = 4;
// delay binding shortcuts that slows down the unlock animation and rebasing extensions
// also reset hot corners to be sure they weren't overridden by another extension
if (this._delayId)
GLib.source_remove(this._delayId);
this._delayId = GLib.timeout_add_seconds(
GLib.PRIORITY_DEFAULT,
enableDelay,
() => {
this.actionTrigger._bindShortcuts();
this._replace_updateHotCornersFunc();
this._delayId = 0;
return GLib.SOURCE_REMOVE;
}
);
console.log(`${this.metadata.name}: enabled`);
}
disable() {
if (this._delayId) {
GLib.source_remove(this._delayId);
this._delayId = 0;
}
this._timeoutsCollector.forEach(c => GLib.Source.remove(c));
this._timeoutsCollector = [];
this._watch.timeout = 0;
this._removeHotCorners();
if (this._mscOptions) {
this._mscOptions.destroy();
this._updateSupportedExtensionsAvailability(true);
this._mscOptions = null;
}
// effects should survive screen lock
let fullDisable = !(Main.sessionMode.isLocked && Utils.extensionEnabled());
if (fullDisable) {
if (this.actionTrigger)
this.actionTrigger.clean(true);
this.actionTrigger = null;
} else if (this.actionTrigger) {
this.actionTrigger.clean(false);
}
this._extensionEnabled = false;
// restore original hot corners
Main.layoutManager._updateHotCorners = this._origUpdateHotCorners;
Main.layoutManager._updateHotCorners();
this._myCorners = [null, null];
if (this._panelButton) {
this._panelButton.destroy();
this._panelButton = null;
}
HotCorners.cleanGlobals();
ActionTrigger.cleanGlobals();
Utils.cleanGlobals();
Actions.cleanGlobals();
PanelButton.cleanGlobals();
Settings.cleanGlobals();
ActionList.cleanGlobals();
if (this._displayRedirectionDisabled) {
Meta.enable_unredirect_for_display(global.display);
this._displayRedirectionDisabled = false;
}
chce = null;
console.log(`${this.metadata.name}: ${fullDisable ? 'disabled' : 'suspended'}`);
}
_replace_updateHotCornersFunc() {
Main.layoutManager._updateHotCorners = this._updateHotCorners;
Main.layoutManager._updateHotCorners();
}
_getEnabledExtensions(uuid = this.metadata.uuid) {
let extensions = [];
Main.extensionManager._extensions.forEach(e => {
if (e.state === 1 && e.uuid.includes(uuid))
extensions.push(e);
});
return !!extensions.length;
}
_updateSupportedExtensionsAvailability(reset = false) {
let supportedExtensions = [];
if (!reset) {
// test ArcMenu
if (global.toggleArcMenu)
supportedExtensions.push('arcmenu');
// test AATWS
const aatws = AltTab.WindowSwitcherPopup.prototype;
if (aatws._showPopup || aatws.showOrig)
supportedExtensions.push('aatws');
let windowSearchProviderEnabled = false;
if (Main.overview._overview._controls.layoutManager._searchController._searchResults._providers) {
Main.overview._overview._controls.layoutManager._searchController._searchResults._providers.forEach(p => {
if (p.id.includes('open-windows'))
windowSearchProviderEnabled = true;
});
}
if (windowSearchProviderEnabled)
supportedExtensions.push('window-search-provider');
}
this._mscOptions.set('supportedExtensions', supportedExtensions);
}
_updateMscOptions(key, doNotUpdateHC = false) {
const actions = this.actionTrigger.actions;
if (key === 'show-osd-monitor-indexes')
this._updateOsdMonitorIndexes();
actions.WIN_WRAPAROUND = this._mscOptions.get('winSwitchWrap');
actions.WIN_SKIP_MINIMIZED = this._mscOptions.get('winSkipMinimized');
actions.WIN_STABLE_SEQUENCE = this._mscOptions.get('winStableSequence');
this.RIPPLE_ANIMATION = this._mscOptions.get('rippleAnimation');
if (this.CORNERS_VISIBLE !== this._mscOptions.get('cornersVisible')) {
this.CORNERS_VISIBLE = this._mscOptions.get('cornersVisible');
if (!doNotUpdateHC)
this._updateHotCorners();
}
if (this.BARRIER_FALLBACK !== this._mscOptions.get('barrierFallback')) {
this.BARRIER_FALLBACK = this._mscOptions.get('barrierFallback');
if (!doNotUpdateHC)
this._updateHotCorners();
}
this._updateWatch();
if (key === 'buttons-trigger-on-press')
this._updateHotCorners();
if (this._mscOptions.get('enablePanelMenu')) {
if (!this._panelButton) {
this._panelButton = new PanelButton.MenuButton(this._mscOptions);
Main.panel.addToStatusArea('CustomHotCorners', this._panelButton, 0, 'right');
}
} else if (this._panelButton) {
this._panelButton.destroy();
this._panelButton = null;
}
}
_updateOsdMonitorIndexes() {
if (this._mscOptions.get('showOsdMonitorIndexes'))
this.actionTrigger.actions._showMonitorIndexesOsd();
}
_removePanelBarrier() {
if (Main.layoutManager._rightPanelBarrier) {
Main.layoutManager._rightPanelBarrier.destroy();
Main.layoutManager._rightPanelBarrier = null;
}
}
_updateHotCorners() {
// when the layout manager calls this function as a callback with its own 'this', we need to override it by chce
chce._removeHotCorners();
Main.layoutManager.hotCorners = [];
chce._updateWatchedCorners();
// corners can be temporarily disabled from panel menu
const cornersDisabled = !chce._mscOptions.get('hotCornersEnabled', true);
if (cornersDisabled)
return;
let primaryIndex = Main.layoutManager.primaryIndex;
// avoid creating new corners if this extension is disabled...
// ...since this method overrides the original one in GS and something can call it
if (!chce._extensionEnabled)
return;
let monIndexes = [...Main.layoutManager.monitors.keys()];
// index of the primary monitor to the first position
monIndexes.splice(0, 0, monIndexes.splice(primaryIndex, 1)[0]);
chce._fullscreenRequired = false;
for (let i = 0; i < Main.layoutManager.monitors.length; ++i) {
// Monitor 1 in preferences will always refer to the primary monitor
const corners = Settings.Corner.forMonitor(i, monIndexes[i], global.display.get_monitor_geometry(monIndexes[i]));
chce._setExpansionLimits(corners);
for (let corner of corners) {
chce._cornersCollector.push(corner);
for (let trigger of chce._listTriggers) {
// Update hot corner if something changes
// corner has it's own connect method defined in settings, this is not direct gsettings connect
// corner.connect('changed', (settings, key) => chce._updateCorner(corner, key, trigger), trigger);
corner.connect('changed', chce._updateHotCorners, trigger);
}
if (chce._shouldExistHotCorner(corner)) {
Main.layoutManager.hotCorners.push(new HotCorners.CustomHotCorner(corner, chce));
chce._updateWatchedCorners();
if (i === 0 && corner.top && !corner.left)
chce._removePanelBarrier();
}
}
}
// If any corner action should be available in fullscreen mode,
// disable bypassing the compositor when the display switches to fullscreen mode
// and keep track of its state - each disable has to be enabled, it works as a stack
if (chce._fullscreenRequired && !chce._displayRedirectionDisabled) {
Meta.disable_unredirect_for_display(global.display);
chce._displayRedirectionDisabled = true;
}
}
_removeHotCorners() {
this._cornersCollector.forEach(c => c.destroy());
this._cornersCollector = [];
Main.layoutManager.hotCorners.forEach(c => c && c.destroy());
Main.layoutManager.hotCorners = [];
this._updateWatchedCorners();
// when some other extension steal my hot corners I still need to be able to destroy all actors I made
this._actorsCollector.filter(a => a).forEach(a => a.destroy());
this._actorsCollector = [];
}
_setExpansionLimits(corners) {
const cornerOrder = [0, 1, 3, 2];
for (let i = 0; i < corners.length; i++) {
let prevCorner = (i + corners.length - 1) % corners.length;
let nextCorner = (i + 1) % corners.length;
prevCorner = corners[cornerOrder[prevCorner]];
nextCorner = corners[cornerOrder[nextCorner]];
let corner = corners[cornerOrder[i]];
if ((corner.left && prevCorner.left) || (!corner.left && !prevCorner.left)) {
corner.fullExpandVertical = !prevCorner.get('vExpand');
corner.fullExpandHorizontal = !nextCorner.get('hExpand');
} else if ((corner.top && prevCorner.top) || (!corner.top && !prevCorner.top)) {
corner.fullExpandVertical = !nextCorner.get('vExpand');
corner.fullExpandHorizontal = !prevCorner.get('hExpand');
}
}
}
_shouldExistHotCorner(corner) {
let answer = false;
for (let trigger of chce._listTriggers) {
const cornerActive = corner.action[trigger] !== 'disabled';
answer = answer || cornerActive;
chce._fullscreenRequired = chce._fullscreenRequired || (cornerActive && corner.get('fullscreen', trigger));
}
return answer;
}
_updateWatch() {
this._watch.active = this._mscOptions.get('watchCorners');
if (this._watch.active && !this._watch.timeout) {
this._watch.timeout = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
3000,
() => {
// some extensions can replace the function (Dash to Panel)
if (Main.layoutManager._updateHotCorners !== this._updateHotCorners) {
Main.layoutManager._updateHotCorners = this._updateHotCorners;
this._updateHotCorners();
log('_updateWatch: updateHotCorners function had to be updated because of external override');
}
let cornersChanged = false;
this._myCorners[0].forEach(c => {
cornersChanged = cornersChanged || !Main.layoutManager.hotCorners.includes(c);
});
if (cornersChanged) {
this._updateHotCorners();
log(this.metadata.name, 'Hot Corners had to be updated because of external override');
return this._watch.active;
}
// some extensions (ArcMenu) can modify pressure barrier triggers, which normally just emits a triggered event
if (this._myCorners[1] && Main.layoutManager.hotCorners[0] && Main.layoutManager.hotCorners[0]._pressureBarrier._trigger !== this._myCorners[1]) {
this._updateHotCorners();
log(this.metadata.name, 'Hot Corners had to be updated because of external override');
}
if (!this._watch.active) {
this._timeoutsCollector.splice(this._timeoutsCollector.indexOf(this._watch.timeout), 1);
this._watch.timeout = null;
}
return this._watch.active;
}
);
this._timeoutsCollector.push(this._watch.timeout);
}
}
_updateWatchedCorners() {
this._myCorners[0] = [...Main.layoutManager.hotCorners];
this._myCorners[1] = Main.layoutManager.hotCorners[0] ? Main.layoutManager.hotCorners[0]._pressureBarrier._trigger : null;
}
}