Merge pull request #405 from mitchellh/goonz/fullscren-split-focus-fix

macos: fix split focus when toggling fullscreen
This commit is contained in:
Mitchell Hashimoto
2023-09-06 11:26:02 -07:00
committed by GitHub
2 changed files with 8 additions and 2 deletions

View File

@ -170,5 +170,11 @@ struct PrimaryView: View {
self.fullScreen.toggleFullscreen(window: window, nonNativeFullscreen: useNonNativeFullscreen) self.fullScreen.toggleFullscreen(window: window, nonNativeFullscreen: useNonNativeFullscreen)
// After toggling fullscreen we need to focus the terminal again. // After toggling fullscreen we need to focus the terminal again.
self.focused = true self.focused = true
// For some reason focus always gets moved to the first split when
// toggling fullscreen, so we set it back to the correct one.
if let focusedSurface {
Ghostty.moveFocus(to: focusedSurface)
}
} }
} }

View File

@ -502,11 +502,11 @@ extension Ghostty {
} }
} }
/// There is a bug I can't figure out where when changing the split state, the terminal view /// When changing the split state, or going full screen (native or non), the terminal view
/// will lose focus. There has to be some nice SwiftUI-native way to fix this but I can't /// will lose focus. There has to be some nice SwiftUI-native way to fix this but I can't
/// figure it out so we're going to do this hacky thing to bring focus back to the terminal /// figure it out so we're going to do this hacky thing to bring focus back to the terminal
/// that should have it. /// that should have it.
fileprivate static func moveFocus(to: SurfaceView, from: SurfaceView? = nil) { static func moveFocus(to: SurfaceView, from: SurfaceView? = nil) {
DispatchQueue.main.async { DispatchQueue.main.async {
// If the callback runs before the surface is attached to a view // If the callback runs before the surface is attached to a view
// then the window will be nil. We just reschedule in that case. // then the window will be nil. We just reschedule in that case.