From 4d9c75ca7169dbdb240c59dcd38b9b21b5afda78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Hedin=20Br=C3=B8nner?= Date: Sat, 17 Feb 2018 19:05:29 +0100 Subject: [PATCH] Sort the stack by distance and then mru O(`max`*`space.length`) ~ O(`space.length`) for finitely wide screens. Doesn't seem like there's a large performance penalty to decide ties between equidistant windows using the mru, instead of deciding ties by sorting on left/right. --- tiling.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/tiling.js b/tiling.js index 6f9ba61..f3c4a14 100644 --- a/tiling.js +++ b/tiling.js @@ -345,6 +345,7 @@ function move_to(space, meta_window, { x, y, delay, transition, let frame = meta_window.get_frame_rect(); propogate_forward(space, index + 1, x + frame.width + window_gap); propogate_backward(space, index - 1, x - window_gap); + fixStack(space, index); } const DIRECTION = { @@ -512,6 +513,31 @@ function focus_handler(meta_window, user_data) { ensure_viewport(space, meta_window); } +/** + We need to stack windows in mru order, since mutter picks from the + stack, not the mru, when auto choosing focus after closing a window. + */ +function fixStack(space, around) { + let topLeft = space.topOfLeftStack(); + let topRight = space.topOfRightStack(); + + let left = topLeft !== null ? space.indexOf(topLeft) : 0; + let right = topRight !== null ? space.indexOf(topRight) : space.length - 1; + + let max = Math.max(Math.abs(around - left), Math.abs(around - right)); + + let mru = global.display.get_tab_list(Meta.TabList.NORMAL, + space.workspace); + + for (let i=max; i >= 0; i--) { + let leftWindow = space[around - i]; + let rightWindow = space[around + i]; + mru.filter(w => w === leftWindow || w === rightWindow) + .reverse() + .forEach(w => w && w.raise()); + } +} + // Place window's left edge at x function propogate_forward(space, n, x, gap) { if (n < 0 || n >= space.length) { @@ -526,13 +552,6 @@ function propogate_forward(space, n, x, gap) { stackWindow(space, i, DIRECTION.Right); } StackOverlay.rightOverlay.setTarget(meta_window); - - // Set stack levels in the correct order, as the the "highest" window - // will have priority when handing out focus - let selected = space.selectedIndex(); - for (let i=n; i > selected; i--) { - space[i].raise(); - } return; } meta_window._isStacked = false; @@ -563,11 +582,6 @@ function propogate_backward(space, n, x, gap) { stackWindow(space, i, DIRECTION.Left); } StackOverlay.leftOverlay.setTarget(meta_window); - - let selected = space.selectedIndex(); - for (let i=n; i <= selected; i++) { - space[i].raise(); - } return; } meta_window._isStacked = false;