macos: add padded-notch option for macos-non-native-fullscreen

Finishes #378
Supercedes #4159

This adds a new enum value for `macos-non-native-fullscreen`:
`padded-notch`. This value will add padding to the top of the window to
account for the notch on applicable devices while still hiding the
menu.

This value is preferred over "visible-menu" by some people because for
screens without a notch, the window will take up the full height.

The plan in the future is that we may color the padded area when a notch
is present. In this commit it appears as transparent.
This commit is contained in:
Mitchell Hashimoto
2025-02-13 20:25:03 -08:00
parent 52a5069dec
commit ac7aa757bd
8 changed files with 28 additions and 2 deletions

View File

@ -412,6 +412,7 @@ typedef enum {
GHOSTTY_FULLSCREEN_NATIVE, GHOSTTY_FULLSCREEN_NATIVE,
GHOSTTY_FULLSCREEN_NON_NATIVE, GHOSTTY_FULLSCREEN_NON_NATIVE,
GHOSTTY_FULLSCREEN_NON_NATIVE_VISIBLE_MENU, GHOSTTY_FULLSCREEN_NON_NATIVE_VISIBLE_MENU,
GHOSTTY_FULLSCREEN_NON_NATIVE_PADDED_NOTCH,
} ghostty_action_fullscreen_e; } ghostty_action_fullscreen_e;
// apprt.action.SecureInput // apprt.action.SecureInput

View File

@ -86,7 +86,7 @@ class TerminalManager {
// fullscreen for the logic later in this method. // fullscreen for the logic later in this method.
c.toggleFullscreen(mode: .native) c.toggleFullscreen(mode: .native)
case .nonNative, .nonNativeVisibleMenu: case .nonNative, .nonNativeVisibleMenu, .nonNativePaddedNotch:
// If we're non-native then we have to do it on a later loop // If we're non-native then we have to do it on a later loop
// so that the content view is setup. // so that the content view is setup.
DispatchQueue.main.async { DispatchQueue.main.async {

View File

@ -13,6 +13,9 @@ extension FullscreenMode {
case GHOSTTY_FULLSCREEN_NON_NATIVE_VISIBLE_MENU: case GHOSTTY_FULLSCREEN_NON_NATIVE_VISIBLE_MENU:
.nonNativeVisibleMenu .nonNativeVisibleMenu
case GHOSTTY_FULLSCREEN_NON_NATIVE_PADDED_NOTCH:
.nonNativePaddedNotch
default: default:
nil nil
} }

View File

@ -216,6 +216,8 @@ extension Ghostty {
.nonNative .nonNative
case "visible-menu": case "visible-menu":
.nonNativeVisibleMenu .nonNativeVisibleMenu
case "padded-notch":
.nonNativePaddedNotch
default: default:
defaultValue defaultValue
} }

View File

@ -6,6 +6,7 @@ enum FullscreenMode {
case native case native
case nonNative case nonNative
case nonNativeVisibleMenu case nonNativeVisibleMenu
case nonNativePaddedNotch
/// Initializes the fullscreen style implementation for the mode. This will not toggle any /// Initializes the fullscreen style implementation for the mode. This will not toggle any
/// fullscreen properties. This may fail if the window isn't configured properly for a given /// fullscreen properties. This may fail if the window isn't configured properly for a given
@ -20,6 +21,9 @@ enum FullscreenMode {
case .nonNativeVisibleMenu: case .nonNativeVisibleMenu:
return NonNativeFullscreenVisibleMenu(window) return NonNativeFullscreenVisibleMenu(window)
case .nonNativePaddedNotch:
return NonNativeFullscreenPaddedNotch(window)
} }
} }
} }
@ -141,6 +145,7 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
struct Properties { struct Properties {
var hideMenu: Bool = true var hideMenu: Bool = true
var paddedNotch: Bool = false
} }
private var savedState: SavedState? private var savedState: SavedState?
@ -278,6 +283,9 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
// put an #available check, but it was in a bug fix release so I think // put an #available check, but it was in a bug fix release so I think
// if a bug is reported to Ghostty we can just advise the user to // if a bug is reported to Ghostty we can just advise the user to
// update. // update.
} else if (properties.paddedNotch) {
// We are hiding the menu, we may need to avoid the notch.
frame.size.height -= screen.safeAreaInsets.top
} }
return frame return frame
@ -349,3 +357,7 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
class NonNativeFullscreenVisibleMenu: NonNativeFullscreen { class NonNativeFullscreenVisibleMenu: NonNativeFullscreen {
override var properties: Properties { Properties(hideMenu: false) } override var properties: Properties { Properties(hideMenu: false) }
} }
class NonNativeFullscreenPaddedNotch: NonNativeFullscreen {
override var properties: Properties { Properties(paddedNotch: true) }
}

View File

@ -4201,6 +4201,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.false => .native, .false => .native,
.true => .macos_non_native, .true => .macos_non_native,
.@"visible-menu" => .macos_non_native_visible_menu, .@"visible-menu" => .macos_non_native_visible_menu,
.@"padded-notch" => .macos_non_native_padded_notch,
}, },
), ),

View File

@ -385,6 +385,7 @@ pub const Fullscreen = enum(c_int) {
/// window. This is much faster to enter and exit than the native mode. /// window. This is much faster to enter and exit than the native mode.
macos_non_native, macos_non_native,
macos_non_native_visible_menu, macos_non_native_visible_menu,
macos_non_native_padded_notch,
}; };
pub const SecureInput = enum(c_int) { pub const SecureInput = enum(c_int) {

View File

@ -1819,9 +1819,14 @@ keybind: Keybinds = .{},
/// ///
/// Allowable values are: /// Allowable values are:
/// ///
/// * `visible-menu` - Use non-native macOS fullscreen, keep the menu bar visible
/// * `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
/// * `visible-menu` - Use non-native macOS fullscreen, keep the menu bar
/// visible
/// * `padded-notch` - Use non-native macOS fullscreen, hide the menu bar,
/// but ensure the window is not obscured by the notch on applicable
/// devices. The area around the notch will remain transparent currently,
/// but in the future we may fill it with the window background color.
/// ///
/// Changing this option at runtime works, but will only apply to the next /// 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, /// time the window is made fullscreen. If a window is already fullscreen,
@ -4095,6 +4100,7 @@ pub const NonNativeFullscreen = enum(c_int) {
false, false,
true, true,
@"visible-menu", @"visible-menu",
@"padded-notch",
}; };
/// Valid values for macos-option-as-alt. /// Valid values for macos-option-as-alt.