Merge pull request #1837 from ghostty-org/titlebar-style

macos: macos-titlebar-style, remove titlebar-tabs option
This commit is contained in:
Mitchell Hashimoto
2024-06-07 13:15:14 -07:00
committed by GitHub
4 changed files with 47 additions and 30 deletions

View File

@ -296,12 +296,14 @@ class TerminalController: NSWindowController, NSWindowDelegate,
// Handle titlebar tabs config option. Something about what we do while setting up the // Handle titlebar tabs config option. Something about what we do while setting up the
// titlebar tabs interferes with the window restore process unless window.tabbingMode // titlebar tabs interferes with the window restore process unless window.tabbingMode
// is set to .preferred, so we set it, and switch back to automatic as soon as we can. // is set to .preferred, so we set it, and switch back to automatic as soon as we can.
if (ghostty.config.macosTitlebarTabs) { if (ghostty.config.macosTitlebarStyle == "tabs") {
window.tabbingMode = .preferred window.tabbingMode = .preferred
window.titlebarTabs = true window.titlebarTabs = true
DispatchQueue.main.async { DispatchQueue.main.async {
window.tabbingMode = .automatic window.tabbingMode = .automatic
} }
} else if (ghostty.config.macosTitlebarStyle == "transparent") {
window.transparentTabs = true
} }
if window.hasStyledTabs { if window.hasStyledTabs {

View File

@ -175,16 +175,15 @@ class TerminalWindow: NSWindow {
var hasStyledTabs: Bool { var hasStyledTabs: Bool {
// If we have titlebar tabs then we always style. // If we have titlebar tabs then we always style.
guard !titlebarTabs else { return true } guard !titlebarTabs else { return true }
// This should never happen, but if we don't have a theme set then // We style the tabs if they're transparent
// we just style the tabs. Either response here is probably okay. return transparentTabs
guard let windowTheme else { return true }
// We only style if the window theme is auto. Any other specific
// window theme type will always show up as that native theme.
return windowTheme == .auto
} }
// Set to true if the background color should bleed through the titlebar/tab bar.
// This only applies to non-titlebar tabs.
var transparentTabs: Bool = false
var hasVeryDarkBackground: Bool { var hasVeryDarkBackground: Bool {
backgroundColor.luminance < 0.05 backgroundColor.luminance < 0.05
} }

View File

@ -228,12 +228,14 @@ extension Ghostty {
return String(cString: ptr) return String(cString: ptr)
} }
var macosTitlebarTabs: Bool { var macosTitlebarStyle: String {
guard let config = self.config else { return false } let defaultValue = "transparent"
var v = false; guard let config = self.config else { return defaultValue }
let key = "macos-titlebar-tabs" var v: UnsafePointer<Int8>? = nil
_ = ghostty_config_get(config, &v, key, UInt(key.count)) let key = "macos-titlebar-style"
return v guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue }
guard let ptr = v else { return defaultValue }
return String(cString: ptr)
} }
var macosWindowShadow: Bool { var macosWindowShadow: Bool {

View File

@ -659,7 +659,7 @@ keybind: Keybinds = .{},
/// * `light` - Use the light theme regardless of system theme. /// * `light` - Use the light theme regardless of system theme.
/// * `dark` - Use the dark theme regardless of system theme. /// * `dark` - Use the dark theme regardless of system theme.
/// ///
/// On macOS, if `macos-titlebar-tabs` is set, the window theme will be /// On macOS, if `macos-titlebar-style` is "tabs", the window theme will be
/// automatically set based on the luminosity of the terminal background color. /// automatically set based on the luminosity of the terminal background color.
/// This only applies to terminal windows. This setting will still apply to /// This only applies to terminal windows. This setting will still apply to
/// non-terminal windows within Ghostty. /// non-terminal windows within Ghostty.
@ -955,23 +955,30 @@ keybind: Keybinds = .{},
/// ///
@"macos-non-native-fullscreen": NonNativeFullscreen = .false, @"macos-non-native-fullscreen": NonNativeFullscreen = .false,
/// If `true`, places the tab bar in the titlebar for tabbed windows. /// The style of the macOS titlebar. Available values are: "native",
/// "transparent", and "tabs".
/// ///
/// When this is true, the titlebar will also always appear even when /// The "native" style uses the native macOS titlebar with zero customization.
/// fullscreen (native fullscreen) with only one tab. This is not considered /// The titlebar will match your window theme (see `window-theme`).
/// a bug but if you'd like to improve this behavior then I'm open to it and
/// please contribute to the project.
/// ///
/// This option intercepts the native tab bar view from macOS and forces it to use /// The "transparent" style is the same as "native" but the titlebar will
/// different positioning. Because of this, it might be buggy or break entirely if /// be transparent and allow your window background color to come through.
/// macOS changes the way its native tab bar view is constructed or managed. /// This makes a more seamless window appearance but looks a little less
/// This has been tested on macOS 14. /// typical for a macOS application and may not work well with all themes.
/// ///
/// For macOS 13 users: saved window state will not restore tabs correctly /// The "tabs" style is a completely custom titlebar that integrates the
/// if this is enabled. macOS 14 does not have this issue. /// tab bar into the titlebar. This titlebar always matches the background
/// color of the terminal. There are some limitations to this style:
/// On macOS 13 and below, saved window state will not restore tabs correctly.
/// macOS 14 does not have this issue and any other macOS version has not
/// been tested.
/// ///
/// This option only applies to new windows when changed. /// The default value is "transparent". This is an opinionated choice
@"macos-titlebar-tabs": bool = false, /// but its one I think is the most aesthetically pleasing and works in
/// most cases.
///
/// Changing this option at runtime only applies to new windows.
@"macos-titlebar-style": MacTitlebarStyle = .transparent,
/// If `true`, the *Option* key will be treated as *Alt*. This makes terminal /// If `true`, the *Option* key will be treated as *Alt*. This makes terminal
/// sequences expecting *Alt* to work properly, but will break Unicode input /// sequences expecting *Alt* to work properly, but will break Unicode input
@ -3511,6 +3518,13 @@ pub const WindowColorspace = enum {
@"display-p3", @"display-p3",
}; };
/// See macos-titlebar-style
pub const MacTitlebarStyle = enum {
native,
transparent,
tabs,
};
/// See gtk-single-instance /// See gtk-single-instance
pub const GtkSingleInstance = enum { pub const GtkSingleInstance = enum {
desktop, desktop,