Initial commit
authorJames Bunton <jamesbunton@delx.net.au>
Sun, 9 Jun 2019 15:58:59 +0000 (01:58 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sun, 9 Jun 2019 15:58:59 +0000 (01:58 +1000)
extension.js [new file with mode: 0644]
metadata.json [new file with mode: 0644]

diff --git a/extension.js b/extension.js
new file mode 100644 (file)
index 0000000..61890b7
--- /dev/null
@@ -0,0 +1,53 @@
+const {
+    windowAttentionHandler: defaultWindowAttentionHandler,
+    activateWindow
+} = imports.ui.main;
+
+const WHITELIST = [
+    "Emacs",
+    "Firefox"
+];
+
+const customWindowAttentionHandler = {
+    _onWindowDemandsAttention(display, window) {
+        if (WHITELIST.includes(window.wm_class)) {
+            activateWindow(window);
+        } else {
+            defaultWindowAttentionHandler._onWindowDemandsAttention(display, window);
+        }
+    }
+};
+
+function connect(obj) {
+    const handler = obj._onWindowDemandsAttention.bind(obj);
+    obj._windowDemandsAttentionId = global.display.connect('window-demands-attention', handler);
+    obj._windowMarkedUrgentId = global.display.connect('window-marked-urgent', handler);
+}
+
+function disconnect(obj) {
+    global.display.disconnect(obj._windowDemandsAttentionId);
+    global.display.disconnect(obj._windowMarkedUrgentId);
+}
+
+function init() {
+}
+
+function enable() {
+    log('Disconnecting default handler');
+    disconnect(defaultWindowAttentionHandler);
+
+    log('Connecting custom handler');
+    connect(customWindowAttentionHandler);
+
+    log('Enabled!');
+}
+
+function disable() {
+    log('Disconnecting custom handler');
+    disconnect(customWindowAttentionHandler);
+
+    log('Reconnecting default handler');
+    connect(defaultWindowAttentionHandler);
+
+    log('Disabled!');
+}
diff --git a/metadata.json b/metadata.json
new file mode 100644 (file)
index 0000000..896b074
--- /dev/null
@@ -0,0 +1 @@
+{"name": "Sometimes Steal My Focus", "description": "Let windows for some apps steal focus", "uuid": "sometimes_steal_my_focus@delx.net.au", "shell-version": ["3.32.2"]}
\ No newline at end of file