summaryrefslogtreecommitdiff
path: root/archive/.local/share/gnome-shell/extensions/steal-my-focus@kagesenshi.org/extension.js
blob: 1127b3a0e5634d9d7adbf7b4b66c6d282167b7b8 (plain)
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
const Main = imports.ui.main;
const WindowAttentionHandler = imports.ui.windowAttentionHandler;
const Shell = imports.gi.Shell;
const Lang = imports.lang;

function StealMyFocus() {
    this._init();
    this.blacklist = ["Skype"];
}

StealMyFocus.prototype = {
    _init : function() {
        this._tracker = Shell.WindowTracker.get_default();
        this._handlerid = global.display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
    },

    _onWindowDemandsAttention: function(display, window) {
        for (var i = 0; i < this.blacklist.length; i++) {
            var name = this.blacklist[i].toLowerCase();
            if (window.title.toLowerCase().indexOf(name) != -1) {
                // app in blacklist, return and do nothing
                return;
            }
        }
        Main.activateWindow(window);
    },

    destroy: function () {
        global.display.disconnect(this._handlerid);
    }
}

let stealmyfocus;

function init() {
}

function enable() {
    stealmyfocus = new StealMyFocus();
}

function disable() {
    stealmyfocus.destroy();
}