From d03dc78cd66d255bd73d0ef6d9547425db09cfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Hedin=20Br=C3=B8nner?= Date: Mon, 2 Jul 2018 13:11:16 +0200 Subject: [PATCH] Always select a neighbour when closing selectedWindow Only look at the neighbours of the closed window when selecting a new window. Also raise the window on ensure, this way the stacking order works like an mru for selectedWindow. --- tiling.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tiling.js b/tiling.js index 4ada18e..2303928 100644 --- a/tiling.js +++ b/tiling.js @@ -232,24 +232,35 @@ class Space extends Array { let index = this.indexOf(metaWindow); if (index === -1) return false; + + let selected = this.selectedWindow; + if (selected === metaWindow) { + // Select a new window using the stack ordering; + let windows = this.getWindows(); + let i = windows.indexOf(metaWindow); + let neighbours = [windows[i - 1], windows[i + 1]].filter(w => w); + let stack = global.display.sort_windows_by_stacking(neighbours); + selected = stack[stack.length - 1]; + } + let column = this[index]; let row = column.indexOf(metaWindow); column.splice(row, 1); if (column.length === 0) this.splice(index, 1); - if (this.selectedWindow === metaWindow) { - // Select a new window using the stack ordering; - let stack = global.display.sort_windows_by_stacking(this.getWindows()); - this.selectedWindow = stack[stack.length - 1]; - } - this.cloneContainer.remove_actor(metaWindow.clone); Tweener.removeTweens(this.selection); this.selection.width = 0; this.visible = this.visible.filter(w => w !== metaWindow); + + this.layout(); this.emit('window-removed', metaWindow, index, row); + if (selected) + ensureViewport(selected, this, true); + else + this.selectedWindow = null; return true; } @@ -987,22 +998,14 @@ function remove_handler(workspace, meta_window) { // window has already received the `focus` signal at this point. // Not sure if we can check directly if _this_ window had focus when closed. - let space = spaces.spaceOf(workspace); - if (!space.removeWindow(meta_window)) - return; - space.layout(); - if (!meta_window.get_compositor_private()) signals.disconnect(meta_window); - // (could be an empty workspace) - if (space.selectedWindow) { - // Force a new ensure, since the focus_handler is run before - // window-removed - ensureViewport(space.selectedWindow, space, true); - } + let space = spaces.spaceOf(workspace); + space.removeWindow(meta_window); } + /** Handle windows entering workspaces. */ @@ -1200,6 +1203,7 @@ function ensureViewport(meta_window, space, force) { }); updateSelection(space); + selected.raise(); space.emit('select'); }