From: James Bunton Date: Sun, 9 Jun 2019 15:58:59 +0000 (+1000) Subject: Initial commit X-Git-Url: https://code.delx.au/sometimes-steal-my-focus/commitdiff_plain/2376f0e13a91f6d3a74b36307acc7bf7c7efe63c Initial commit --- 2376f0e13a91f6d3a74b36307acc7bf7c7efe63c diff --git a/extension.js b/extension.js new file mode 100644 index 0000000..61890b7 --- /dev/null +++ b/extension.js @@ -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 index 0000000..896b074 --- /dev/null +++ b/metadata.json @@ -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