refactor: migrate background glass effect to new macos-background-style config

pull/8801/head
Justy Null 2025-09-20 11:44:04 -07:00 committed by Mitchell Hashimoto
parent a02364cbef
commit d40af61960
4 changed files with 70 additions and 49 deletions

View File

@ -480,11 +480,9 @@ class TerminalWindow: NSWindow {
backgroundColor = .white.withAlphaComponent(0.001) backgroundColor = .white.withAlphaComponent(0.001)
// Add liquid glass behind terminal content // Add liquid glass behind terminal content
if #available(macOS 26.0, *), derivedConfig.backgroundGlassStyle != "off" { if #available(macOS 26.0, *), derivedConfig.macosBackgroundStyle != .blur {
setupGlassLayer() setupGlassLayer()
} } else if let appDelegate = NSApp.delegate as? AppDelegate {
if let appDelegate = NSApp.delegate as? AppDelegate {
ghostty_set_window_background_blur( ghostty_set_window_background_blur(
appDelegate.ghostty.app, appDelegate.ghostty.app,
Unmanaged.passUnretained(self).toOpaque()) Unmanaged.passUnretained(self).toOpaque())
@ -591,18 +589,18 @@ class TerminalWindow: NSWindow {
let effectView = NSGlassEffectView() let effectView = NSGlassEffectView()
// Map Ghostty config to NSGlassEffectView style // Map Ghostty config to NSGlassEffectView style
let glassStyle = derivedConfig.backgroundGlassStyle let backgroundStyle = derivedConfig.macosBackgroundStyle
switch glassStyle { switch backgroundStyle {
case "regular": case .regularGlass:
effectView.style = NSGlassEffectView.Style.regular effectView.style = NSGlassEffectView.Style.regular
case "clear": case .clearGlass:
effectView.style = NSGlassEffectView.Style.clear effectView.style = NSGlassEffectView.Style.clear
default: default:
// Should not reach here since we check for "off" before calling setupGlassLayer() // Should not reach here since we check for "default" before calling setupGlassLayer()
return return
} }
effectView.cornerRadius = 18 effectView.cornerRadius = derivedConfig.windowCornerRadius
effectView.tintColor = preferredBackgroundColor effectView.tintColor = preferredBackgroundColor
effectView.frame = windowContentView.bounds effectView.frame = windowContentView.bounds
@ -627,14 +625,16 @@ class TerminalWindow: NSWindow {
let backgroundColor: NSColor let backgroundColor: NSColor
let backgroundOpacity: Double let backgroundOpacity: Double
let macosWindowButtons: Ghostty.MacOSWindowButtons let macosWindowButtons: Ghostty.MacOSWindowButtons
let backgroundGlassStyle: String let macosBackgroundStyle: Ghostty.MacBackgroundStyle
let windowCornerRadius: CGFloat
init() { init() {
self.title = nil self.title = nil
self.backgroundColor = NSColor.windowBackgroundColor self.backgroundColor = NSColor.windowBackgroundColor
self.backgroundOpacity = 1 self.backgroundOpacity = 1
self.macosWindowButtons = .visible self.macosWindowButtons = .visible
self.backgroundGlassStyle = "off" self.macosBackgroundStyle = .blur
self.windowCornerRadius = 16
} }
init(_ config: Ghostty.Config) { init(_ config: Ghostty.Config) {
@ -642,7 +642,17 @@ class TerminalWindow: NSWindow {
self.backgroundColor = NSColor(config.backgroundColor) self.backgroundColor = NSColor(config.backgroundColor)
self.backgroundOpacity = config.backgroundOpacity self.backgroundOpacity = config.backgroundOpacity
self.macosWindowButtons = config.macosWindowButtons self.macosWindowButtons = config.macosWindowButtons
self.backgroundGlassStyle = config.backgroundGlassStyle self.macosBackgroundStyle = config.macosBackgroundStyle
// Set corner radius based on macos-titlebar-style
// Native, transparent, and hidden styles use 16pt radius
// Tabs style uses 20pt radius
switch config.macosTitlebarStyle {
case "tabs":
self.windowCornerRadius = 20
default:
self.windowCornerRadius = 16
}
} }
} }
} }

View File

@ -261,17 +261,17 @@ extension Ghostty {
return MacOSWindowButtons(rawValue: str) ?? defaultValue return MacOSWindowButtons(rawValue: str) ?? defaultValue
} }
var backgroundGlassStyle: String { var macosBackgroundStyle: MacBackgroundStyle {
let defaultValue = "off" let defaultValue = MacBackgroundStyle.blur
guard let config = self.config else { return defaultValue } guard let config = self.config else { return defaultValue }
var v: UnsafePointer<Int8>? = nil var v: UnsafePointer<Int8>? = nil
let key = "background-glass-style" let key = "macos-background-style"
guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue } guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue }
guard let ptr = v else { return defaultValue } guard let ptr = v else { return defaultValue }
return String(cString: ptr) let str = String(cString: ptr)
return MacBackgroundStyle(rawValue: str) ?? defaultValue
} }
var macosTitlebarStyle: String { var macosTitlebarStyle: String {
let defaultValue = "transparent" let defaultValue = "transparent"
guard let config = self.config else { return defaultValue } guard let config = self.config else { return defaultValue }

View File

@ -352,6 +352,13 @@ extension Ghostty {
case hidden case hidden
} }
/// Enum for the macos-background-style config option
enum MacBackgroundStyle: String {
case blur
case regularGlass = "regular-glass"
case clearGlass = "clear-glass"
}
/// Enum for auto-update-channel config option /// Enum for auto-update-channel config option
enum AutoUpdateChannel: String { enum AutoUpdateChannel: String {
case tip case tip

View File

@ -950,24 +950,6 @@ palette: Palette = .{},
/// doing so. /// doing so.
@"background-blur": BackgroundBlur = .false, @"background-blur": BackgroundBlur = .false,
/// The style of the glass effect when `background-opacity` is less than 1
/// and the terminal is using a modern glass effect (macOS 26.0+ only).
///
/// Valid values are:
///
/// * `off` - No glass effect
/// * `regular` - Standard glass effect with some opacity
/// * `clear` - Highly transparent glass effect
///
/// This setting only takes effect on macOS 26.0+ when transparency is enabled
/// (`background-opacity` < 1). On older macOS versions or when transparency
/// is disabled, this setting has no effect.
///
/// The default value is `off`.
///
/// Available since: 1.2.2
@"background-glass-style": BackgroundGlassStyle = .off,
/// The opacity level (opposite of transparency) of an unfocused split. /// The opacity level (opposite of transparency) of an unfocused split.
/// Unfocused splits by default are slightly faded out to make it easier to see /// Unfocused splits by default are slightly faded out to make it easier to see
/// which split is focused. To disable this feature, set this value to 1. /// which split is focused. To disable this feature, set this value to 1.
@ -3124,6 +3106,28 @@ keybind: Keybinds = .{},
/// Available since: 1.2.0 /// Available since: 1.2.0
@"macos-shortcuts": MacShortcuts = .ask, @"macos-shortcuts": MacShortcuts = .ask,
/// The background style for macOS windows when `background-opacity` is less than 1.
/// This controls the visual effect applied behind the terminal background.
///
/// Valid values are:
///
/// * `blur` - Uses the standard background behavior. The `background-blur`
/// configuration will control whether blur is applied (available on all macOS versions)
/// * `regular-glass` - Standard glass effect with some opacity (macOS 26.0+ only)
/// * `clear-glass` - Highly transparent glass effect (macOS 26.0+ only)
///
/// The `blur` option does not force any blur effect - it simply respects the
/// `background-blur` configuration. The glass options override `background-blur`
/// and apply their own visual effects.
///
/// On macOS versions prior to 26.0, only `blur` has an effect. The glass
/// options will fall back to `blur` behavior on older versions.
///
/// The default value is `blur`.
///
/// Available since: 1.2.2
@"macos-background-style": MacBackgroundStyle = .blur,
/// Put every surface (tab, split, window) into a dedicated Linux cgroup. /// Put every surface (tab, split, window) into a dedicated Linux cgroup.
/// ///
/// This makes it so that resource management can be done on a per-surface /// This makes it so that resource management can be done on a per-surface
@ -7708,6 +7712,13 @@ pub const MacShortcuts = enum {
ask, ask,
}; };
/// See macos-background-style
pub const MacBackgroundStyle = enum {
blur,
@"regular-glass",
@"clear-glass",
};
/// See gtk-single-instance /// See gtk-single-instance
pub const GtkSingleInstance = enum { pub const GtkSingleInstance = enum {
false, false,
@ -8401,13 +8412,6 @@ pub const BackgroundBlur = union(enum) {
} }
}; };
/// See background-glass-style
pub const BackgroundGlassStyle = enum {
off,
regular,
clear,
};
/// See window-decoration /// See window-decoration
pub const WindowDecoration = enum(c_int) { pub const WindowDecoration = enum(c_int) {
auto, auto,