-
Notifications
You must be signed in to change notification settings - Fork 13
/
utils.js
63 lines (60 loc) · 2.1 KB
/
utils.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
const Meta = imports.gi.Meta;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const logging = Me.imports.logging;
const logger = logging.getLogger('Gnomesome.Utils');
// of each added connection in `owner.bound_signals`,
// for later cleanup in disconnect_tracked_signals().
// Also logs any exceptions that occur.
function connect_and_track(owner, subject, name, cb, after) {
if (typeof owner.bound_signals === 'undefined') {
owner.bound_signals = [];
}
const method = after ? 'connect_after':'connect';
owner.bound_signals.push({
subject: subject,
binding: subject[method](name, function() {
const t = this;
try {
return cb.apply(t,arguments);
} catch(e) {
logger.error("Uncaught error in " + name + " signal handler: " + e + "\n" + e.stack);
throw e;
}
})
});
}
// Disconnect all tracked signals from the given object.
// Used for reverting signals bound via `connect_and_track()`
function disconnect_tracked_signals(owner, subject) {
if (arguments.length > 1 && !subject) {
throw new Error("[gnomesome] disconnect_tracked_signals called with null subject");
}
let count = 0;
for (let i = owner.bound_signals.length-1; i >= 0; i--) {
const sig = owner.bound_signals[i];
if (subject == null || subject === sig.subject) {
sig.subject.disconnect(sig.binding);
// delete signal
owner.bound_signals.splice(i, 1);
count++;
}
}
if (count>0) {
logger.info("disconnected " + count + " listeners from " +
owner + (subject == null ? "" : (" on " + subject)));
}
}
var DisplayWrapper = {
getScreen() {
return global.screen || global.display;
},
getWorkspaceManager() {
return global.screen || global.workspace_manager;
},
getMonitorManager() {
return global.screen || Meta.MonitorManager.get();
},
getDisplay() {
return global.display || global.screen;
},
};