mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: fullscreen mode can be changed at runtime
This commit is contained in:
@ -204,16 +204,45 @@ class TerminalController: BaseTerminalController
|
|||||||
// We need a window to fullscreen
|
// We need a window to fullscreen
|
||||||
guard let window = self.window else { return }
|
guard let window = self.window else { return }
|
||||||
|
|
||||||
// TODO: handle changing fullscreen modes at runtime
|
// If we have a previous fullscreen style initialized, we want to check if
|
||||||
// This is where we'd handle this.
|
// our mode changed. If it changed and we're in fullscreen, we exit so we can
|
||||||
|
// toggle it next time. If it changed and we're not in fullscreen we can just
|
||||||
// Initialize our style for the window. This may fail for various reasons so
|
// switch the handler.
|
||||||
// we also guard below.
|
let newStyle = mode.style(for: window)
|
||||||
if self.fullscreenStyle == nil {
|
old: if let oldStyle = self.fullscreenStyle {
|
||||||
self.fullscreenStyle = mode.style(for: window)
|
// If we're not fullscreen, we can nil it out so we get the new style
|
||||||
|
if !oldStyle.isFullscreen {
|
||||||
|
self.fullscreenStyle = nil
|
||||||
|
break old
|
||||||
}
|
}
|
||||||
guard let fullscreenStyle else { return }
|
|
||||||
|
|
||||||
|
assert(oldStyle.isFullscreen)
|
||||||
|
|
||||||
|
// We consider our mode changed if the types change (obvious) but
|
||||||
|
// also if its nil (not obvious) because nil means that the style has
|
||||||
|
// likely changed but we don't support it.
|
||||||
|
if newStyle == nil || type(of: newStyle) != type(of: oldStyle) {
|
||||||
|
// Our mode changed. Exit fullscreen (since we're toggling anyways)
|
||||||
|
// and then unset the style so that we replace it next time.
|
||||||
|
oldStyle.exit()
|
||||||
|
self.fullscreenStyle = nil
|
||||||
|
|
||||||
|
// Fix our focus
|
||||||
|
if let focusedSurface {
|
||||||
|
Ghostty.moveFocus(to: focusedSurface)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're done
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Style is the same.
|
||||||
|
} else {
|
||||||
|
// No old style, so set to our new style.
|
||||||
|
self.fullscreenStyle = newStyle
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let fullscreenStyle else { return }
|
||||||
if fullscreenStyle.isFullscreen {
|
if fullscreenStyle.isFullscreen {
|
||||||
fullscreenStyle.exit()
|
fullscreenStyle.exit()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1384,6 +1384,9 @@ keybind: Keybinds = .{},
|
|||||||
/// * `true` - Use non-native macOS fullscreen, hide the menu bar
|
/// * `true` - Use non-native macOS fullscreen, hide the menu bar
|
||||||
/// * `false` - Use native macOS fullscreen
|
/// * `false` - Use native macOS fullscreen
|
||||||
///
|
///
|
||||||
|
/// Changing this option at runtime works, but will only apply to the next
|
||||||
|
/// time the window is made fullscreen. If a window is already fullscreen,
|
||||||
|
/// it will retain the previous setting until fullscreen is exited.
|
||||||
@"macos-non-native-fullscreen": NonNativeFullscreen = .false,
|
@"macos-non-native-fullscreen": NonNativeFullscreen = .false,
|
||||||
|
|
||||||
/// The style of the macOS titlebar. Available values are: "native",
|
/// The style of the macOS titlebar. Available values are: "native",
|
||||||
|
Reference in New Issue
Block a user