-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathextension.js
More file actions
138 lines (115 loc) · 3.83 KB
/
Copy pathextension.js
File metadata and controls
138 lines (115 loc) · 3.83 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
130
131
132
133
134
135
136
137
138
/**
* WTMB (Window Thumbnails)
* extension.js
*
* @author GdH <G-dH@github.com>
* @copyright 2024
* @license GPL-3.0
*/
'use strict';
import GLib from 'gi://GLib';
import * as Extension from 'resource:///org/gnome/shell/extensions/extension.js';
// Me imports
import * as Settings from './settings.js';
import { WinTmb } from './winTmb.js';
import * as Keybindings from './keybindings.js';
import * as Util from './util.js';
export default class WTMB extends Extension.Extension {
enable() {
const Me = {};
Me.extension = this;
Me.metadata = this.metadata;
Me.gSettings = this.getSettings();
Me._ = this.gettext.bind(this);
Me.Util = Util;
Util.init(Me);
Me.opt = new Settings.Options(Me);
this.Me = Me;
this._winTmb = new WinTmb(Me);
Me.opt.connect('changed', (settings, key) => {
if (key.includes('shortcut'))
this._updateKeyBinding();
});
// Delay keybinding so it doesn't affect screen unlocking animation
this._keyBindDelayId = GLib.timeout_add(
GLib.PRIORITY_LOW, 400,
() => {
this._updateKeyBinding();
this._keyBindDelayId = 0;
return GLib.SOURCE_REMOVE;
}
);
// Restore thumbnails if needed
this._winTmb.restoreThumbnails();
console.debug(`${this.metadata.name}: enabled`);
}
disable() {
if (this._keyBindDelayId) {
GLib.source_remove(this._keyBindDelayId);
this._keyBindDelayId = 0;
}
if (this._keybindingsManager) {
this._keybindingsManager.destroy();
this._keybindingsManager = null;
}
this._winTmb.destroy();
this.Me.opt.destroy();
this.Me.opt = null;
this.Me.Util.cleanGlobals();
this.Me = null;
this._winTmb = null;
console.debug(`${this.metadata.name}: disabled`);
}
_getKeybindingsManager() {
if (!this._keybindingsManager)
this._keybindingsManager = new Keybindings.Manager();
return this._keybindingsManager;
}
_updateKeyBinding() {
const manager = this._getKeybindingsManager();
manager.removeAll();
this._bindShortcuts();
}
_bindShortcuts() {
if (!this._gSettingsKBid)
this._gSettingsKBid = this.Me.opt.connect('changed::create-tmb-shortcut', this._updateKeyBinding.bind(this));
const shortcuts = [
{
keyVar: 'createTmbShortcut',
callback: () => this._winTmb.createThumbnail(),
},
{
keyVar: 'minimizeToTmbShortcut',
callback: () => this._winTmb.minimizeToThumbnail(),
},
{
keyVar: 'removeLastShortcut',
callback: () => this._winTmb.removeLast(),
},
{
keyVar: 'removeAllShortcut',
callback: () => this._winTmb.removeAll(),
},
{
keyVar: 'toggleVisibilityShortcut',
callback: () => this._winTmb.toggleShowAll(),
},
{
keyVar: 'switchSourceNextShortcut',
callback: () => this._winTmb.switchSourceNext(),
},
{
keyVar: 'switchSourcePrevShortcut',
callback: () => this._winTmb.switchSourcePrev(),
},
];
const manager = this._getKeybindingsManager();
for (const shortcut of shortcuts) {
const keyVar = shortcut.keyVar;
const accel = this.Me.opt.get(keyVar, true)[0];
const callback = shortcut.callback;
if (accel && accel !== '')
manager.add(accel, keyVar, callback);
}
}
}