From f7b9cf0ee49b08294997186f01e5c017d54727f6 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Tue, 13 Jan 2026 22:30:54 +0000 Subject: [PATCH 1/2] When moving focus to tile with multiple windows, choose top of stack --- src/extension.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index eee13a9..15509cf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -617,6 +617,7 @@ export default class TilingShellExtension extends Extension { let bestWindow: Meta.Window | undefined; let bestWindowDistance = -1; + let bestWindowStackIndex = -1; const focusWindowRect = focus_window.get_frame_rect(); const focusWindowCenter = { @@ -629,6 +630,9 @@ export default class TilingShellExtension extends Extension { ); const onlyTiledWindows = Settings.ENABLE_DIRECTIONAL_FOCUS_TILED_ONLY; + const stackingOrder = + global.display.sort_windows_by_stacking(windowList); + windowList .filter((win) => { if (win === focus_window || win.minimized) return false; @@ -663,14 +667,17 @@ export default class TilingShellExtension extends Extension { focusWindowCenter, ); + const winStackIndex = stackingOrder.indexOf(win); + if ( !bestWindow || euclideanDistance < bestWindowDistance || (euclideanDistance === bestWindowDistance && - bestWindow.get_frame_rect().y > winRect.y) + winStackIndex > bestWindowStackIndex) ) { bestWindow = win; bestWindowDistance = euclideanDistance; + bestWindowStackIndex = winStackIndex; } }); From 582cda18acfc880f2531bd0bd0ae6e28f6fee3c0 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Mon, 19 Jan 2026 18:47:31 +0000 Subject: [PATCH 2/2] Avoid `indexOf` --- src/extension.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 15509cf..a816aa1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -633,8 +633,9 @@ export default class TilingShellExtension extends Extension { const stackingOrder = global.display.sort_windows_by_stacking(windowList); - windowList - .filter((win) => { + stackingOrder + .map((win, winStackIndex) => ({ win, winStackIndex })) + .filter(({ win }) => { if (win === focus_window || win.minimized) return false; if ( onlyTiledWindows && @@ -655,7 +656,7 @@ export default class TilingShellExtension extends Extension { } return false; }) - .forEach((win) => { + .forEach(({ win, winStackIndex }) => { const winRect = win.get_frame_rect(); const winCenter = { x: winRect.x + winRect.width / 2, @@ -667,8 +668,6 @@ export default class TilingShellExtension extends Extension { focusWindowCenter, ); - const winStackIndex = stackingOrder.indexOf(win); - if ( !bestWindow || euclideanDistance < bestWindowDistance ||