-
Notifications
You must be signed in to change notification settings - Fork 22
/
extension.js
61 lines (46 loc) · 1.95 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
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
class StealMyFocus {
constructor() {
this._windowDemandsAttentionId = global.display.connect('window-demands-attention', this._onWindowDemandsAttention.bind(this));
this._windowMarkedUrgentId = global.display.connect('window-marked-urgent', this._onWindowDemandsAttention.bind(this));
log("Disabling 'Window Is Ready' Notification");
}
_onWindowDemandsAttention(display, window) {
if (!window || window.has_focus() || window.is_skip_taskbar())
return;
let settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.noannoyance');
let preventDisable = settings.get_boolean('enable-ignorelist');
let byClassList = settings.get_strv('by-class');
if (preventDisable) {
if (byClassList.includes(window.get_wm_class())) {
global.log(`Ignored "${window.get_wm_class()}"s Request to Steal Focus`);
return;
}
}
Main.activateWindow(window);
}
destroy() {
global.display.disconnect(this._windowDemandsAttentionId);
global.display.disconnect(this._windowMarkedUrgentId);
log("Reenabling 'Window Is Ready' Notification");
}
}
let stealmyfocus;
let oldHandler;
function init() {
}
function enable() {
global.display.disconnect(Main.windowAttentionHandler._windowDemandsAttentionId);
global.display.disconnect(Main.windowAttentionHandler._windowMarkedUrgentId);
oldHandler = Main.windowAttentionHandler;
stealmyfocus = new StealMyFocus();
Main.windowAttentionHandler = stealmyfocus;
}
function disable() {
stealmyfocus.destroy();
stealmyfocus = null;
oldHandler._windowDemandsAttentionId = global.display.connect('window-demands-attention', oldHandler._onWindowDemandsAttention.bind(oldHandler));
oldHandler._windowMarkedUrgentId = global.display.connect('window-marked-urgent', oldHandler._onWindowDemandsAttention.bind(oldHandler));
Main.windowAttentionHandler = oldHandler;
}