Skip to content

Commit

Permalink
Fix swapping with two windows visible for two-pane layout (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickythefox authored May 16, 2022
1 parent 6984243 commit 2b3432b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Amethyst/Managers/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ extension WindowManager: WindowTransitionTarget {
return windows.isWindowFloating(window)
}

func currentLayout() -> Layout<Application.Window>? {
return focusedScreenManager()?.currentLayout
}

func activeWindows(on screen: Screen) -> [Window] {
return windows.activeWindows(onScreen: screen).filter { window in
return window.shouldBeManaged() && !self.windows.isWindowFloating(window)
Expand Down
14 changes: 9 additions & 5 deletions Amethyst/Managers/WindowTransitionCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protocol WindowTransitionTarget: class {
func executeTransition(_ transition: WindowTransition<Window>)

func isWindowFloating(_ window: Window) -> Bool
func currentLayout() -> Layout<Application.Window>?
func screen(at index: Int) -> Screen?
func activeWindows(on screen: Screen) -> [Window]
func nextScreenIndexClockwise(from screen: Screen) -> Int
Expand All @@ -49,13 +50,16 @@ class WindowTransitionCoordinator<Target: WindowTransitionTarget> {
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<Window>.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]))
}
}
Expand Down

0 comments on commit 2b3432b

Please sign in to comment.