From 1240d363a00a82acb27602fc7be82cd62d6f36b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Sun, 1 Jul 2018 13:39:38 +0200 Subject: [PATCH] Only evaluate winprops on window creation Doesn't make sense to revaluate each time the window changes workspace. Also make it easier to control initial focus of scratch windows and removes side-effects from add_filter. --- notes.org | 3 +++ tiling.js | 56 +++++++++++++++++++++++++------------------------------ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/notes.org b/notes.org index 48d053d..06cebf2 100644 --- a/notes.org +++ b/notes.org @@ -8,6 +8,9 @@ 2. on screen "window-entered-monitor", actor isn't available 3. on display "window-created" is run, actor is available 4. focus is run if the new window should be focused +** Toggle "Always on visible workspace" (scratch windows) +- window-removed on workspace of window +- window-added on all workspaces * Keybinding system `Main.wm.addKeybinding` is used to register a named keybindable /action/ and it's handler. An numeric id is returned. (this is a thin wrapper around `[[https://developer.gnome.org/meta/stable/MetaDisplay.html#meta-display-add-keybinding][MetaDisplay.add_keybinding]]`) diff --git a/tiling.js b/tiling.js index abacf33..851c626 100644 --- a/tiling.js +++ b/tiling.js @@ -364,8 +364,7 @@ class Space extends Array { Scratch.makeScratch(meta_window); return; } - if(this.indexOf(meta_window) < 0 && add_filter(meta_window, true)) { - // Using add_handler is unreliable since it interacts with focus. + if(this.indexOf(meta_window) < 0 && add_filter(meta_window)) { this.addWindow(meta_window, this.length); this.cloneContainer.add_actor(meta_window.clone); } @@ -835,7 +834,7 @@ function disable () { /** Types of windows which never should be tiled. */ -function add_filter(meta_window, startup) { +function add_filter(meta_window) { let add = true; if (meta_window.window_type != Meta.WindowType.NORMAL) { @@ -849,33 +848,7 @@ function add_filter(meta_window, startup) { if (meta_window.is_on_all_workspaces()) { add = false; } - - let winprop = find_winprop(meta_window); - if (winprop) { - if (winprop.oneshot) { - // untested :) - winprops.splice(winprops.indexOf(winprop), 1); - } - if (winprop.float) { - // Let gnome-shell handle the placement - add = false; - } - if (winprop.scratch_layer) { - Scratch.makeScratch(meta_window); - add = false; - } - } - - // If we're focusing a scratch window make on top and return - let focus_window = global.display.focus_window; - if (Scratch.isScratchWindow(focus_window) && !startup) { - Scratch.makeScratch(meta_window); - add = false; - } - - // If the window is a scratch window make it always on top if (Scratch.isScratchWindow(meta_window)) { - meta_window.make_above(); add = false; } @@ -928,13 +901,34 @@ function add_handler(ws, metaWindow) { */ function insertWindow(metaWindow, {existing}) { - let space = spaces.spaceOfWindow(metaWindow); - let monitor = space.monitor; + if (!existing) { + let scratchIsFocused = Scratch.isScratchWindow(global.display.focus_window); + let addToScratch = scratchIsFocused; + + let winprop = find_winprop(metaWindow); + if (winprop) { + if (winprop.oneshot) { + winprops.splice(winprops.indexOf(winprop), 1); + } + if (winprop.scratch_layer) { + debug("#winprops", `Move ${metaWindow.title} to scratch`); + addToScratch = true; + } + } + + if (addToScratch) { + Scratch.makeScratch(metaWindow); + return; + } + } if (!add_filter(metaWindow)) { return; } + let space = spaces.spaceOfWindow(metaWindow); + let monitor = space.monitor; + // Don't add already added windows if (space.indexOf(metaWindow) != -1) { return;