From 2b3432b95749cae25e59f8607520dd3a77d6b586 Mon Sep 17 00:00:00 2001 From: rickythefox Date: Mon, 16 May 2022 15:08:43 +0200 Subject: [PATCH] Fix swapping with two windows visible for two-pane layout (#1241) --- Amethyst/Managers/WindowManager.swift | 4 ++++ .../Managers/WindowTransitionCoordinator.swift | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Amethyst/Managers/WindowManager.swift b/Amethyst/Managers/WindowManager.swift index 70a9e49a..d2a24b1f 100644 --- a/Amethyst/Managers/WindowManager.swift +++ b/Amethyst/Managers/WindowManager.swift @@ -670,6 +670,10 @@ extension WindowManager: WindowTransitionTarget { return windows.isWindowFloating(window) } + func currentLayout() -> Layout? { + return focusedScreenManager()?.currentLayout + } + func activeWindows(on screen: Screen) -> [Window] { return windows.activeWindows(onScreen: screen).filter { window in return window.shouldBeManaged() && !self.windows.isWindowFloating(window) diff --git a/Amethyst/Managers/WindowTransitionCoordinator.swift b/Amethyst/Managers/WindowTransitionCoordinator.swift index 9f1815b7..7ffaa61a 100644 --- a/Amethyst/Managers/WindowTransitionCoordinator.swift +++ b/Amethyst/Managers/WindowTransitionCoordinator.swift @@ -26,6 +26,7 @@ protocol WindowTransitionTarget: class { func executeTransition(_ transition: WindowTransition) func isWindowFloating(_ window: Window) -> Bool + func currentLayout() -> Layout? func screen(at index: Int) -> Screen? func activeWindows(on screen: Screen) -> [Window] func nextScreenIndexClockwise(from screen: Screen) -> Int @@ -49,13 +50,16 @@ class WindowTransitionCoordinator { return } - // if there are 2 windows, we can always swap. Just make sure we don't swap focusedWindow with itself. - switch windows.count { - case 1: + if windows.count == 1 { return - case 2: + } else if windows.count == 2 || target?.currentLayout()?.layoutKey == TwoPaneLayout.layoutKey { + // Swap the two visible windows, keep focus on the main window if it already was there target?.executeTransition(.switchWindows(focusedWindow, windows[1 - focusedIndex])) - default: + if focusedWindow == windows[0] { + windows[1 - focusedIndex].focus() + } + } else { + // Swap focused window with main window target?.executeTransition(.switchWindows(focusedWindow, windows[0])) } }