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)
// Add liquid glass behind terminal content
if #available(macOS 26.0, *), derivedConfig.backgroundGlassStyle != "off" {
if #available(macOS 26.0, *), derivedConfig.macosBackgroundStyle != .blur {
setupGlassLayer()
}
if let appDelegate = NSApp.delegate as? AppDelegate {
} else if let appDelegate = NSApp.delegate as? AppDelegate {
ghostty_set_window_background_blur(
appDelegate.ghostty.app,
Unmanaged.passUnretained(self).toOpaque())
@ -576,7 +574,7 @@ class TerminalWindow: NSWindow {
}
// MARK: Glass
@available(macOS 26.0, *)
private func setupGlassLayer() {
guard let contentView = contentView else { return }
@ -591,18 +589,18 @@ class TerminalWindow: NSWindow {
let effectView = NSGlassEffectView()
// Map Ghostty config to NSGlassEffectView style
let glassStyle = derivedConfig.backgroundGlassStyle
switch glassStyle {
case "regular":
let backgroundStyle = derivedConfig.macosBackgroundStyle
switch backgroundStyle {
case .regularGlass:
effectView.style = NSGlassEffectView.Style.regular
case "clear":
case .clearGlass:
effectView.style = NSGlassEffectView.Style.clear
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
}
effectView.cornerRadius = 18
effectView.cornerRadius = derivedConfig.windowCornerRadius
effectView.tintColor = preferredBackgroundColor
effectView.frame = windowContentView.bounds
@ -627,14 +625,16 @@ class TerminalWindow: NSWindow {
let backgroundColor: NSColor
let backgroundOpacity: Double
let macosWindowButtons: Ghostty.MacOSWindowButtons
let backgroundGlassStyle: String
let macosBackgroundStyle: Ghostty.MacBackgroundStyle
let windowCornerRadius: CGFloat
init() {
self.title = nil
self.backgroundColor = NSColor.windowBackgroundColor
self.backgroundOpacity = 1
self.macosWindowButtons = .visible
self.backgroundGlassStyle = "off"
self.macosBackgroundStyle = .blur
self.windowCornerRadius = 16
}
init(_ config: Ghostty.Config) {
@ -642,7 +642,17 @@ class TerminalWindow: NSWindow {
self.backgroundColor = NSColor(config.backgroundColor)
self.backgroundOpacity = config.backgroundOpacity
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
}
var backgroundGlassStyle: String {
let defaultValue = "off"
var macosBackgroundStyle: MacBackgroundStyle {
let defaultValue = MacBackgroundStyle.blur
guard let config = self.config else { return defaultValue }
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 let ptr = v else { return defaultValue }
return String(cString: ptr)
let str = String(cString: ptr)
return MacBackgroundStyle(rawValue: str) ?? defaultValue
}
var macosTitlebarStyle: String {
let defaultValue = "transparent"
guard let config = self.config else { return defaultValue }

View File

@ -56,7 +56,7 @@ extension Ghostty {
case app
case zig_run
}
/// Returns the mechanism that launched the app. This is based on an env var so
/// its up to the env var being set in the correct circumstance.
static var launchSource: LaunchSource {
@ -65,7 +65,7 @@ extension Ghostty {
// source. If its unset we assume we're in a CLI environment.
return .cli
}
// If the env var is set but its unknown then we default back to the app.
return LaunchSource(rawValue: envValue) ?? .app
}
@ -76,17 +76,17 @@ extension Ghostty {
extension Ghostty {
class AllocatedString {
private let cString: ghostty_string_s
init(_ c: ghostty_string_s) {
self.cString = c
}
var string: String {
guard let ptr = cString.ptr else { return "" }
let data = Data(bytes: ptr, count: Int(cString.len))
return String(data: data, encoding: .utf8) ?? ""
}
deinit {
ghostty_string_free(cString)
}
@ -352,6 +352,13 @@ extension Ghostty {
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 AutoUpdateChannel: String {
case tip

View File

@ -950,24 +950,6 @@ palette: Palette = .{},
/// doing so.
@"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.
/// 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.
@ -3124,6 +3106,28 @@ keybind: Keybinds = .{},
/// Available since: 1.2.0
@"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.
///
/// This makes it so that resource management can be done on a per-surface
@ -7708,6 +7712,13 @@ pub const MacShortcuts = enum {
ask,
};
/// See macos-background-style
pub const MacBackgroundStyle = enum {
blur,
@"regular-glass",
@"clear-glass",
};
/// See gtk-single-instance
pub const GtkSingleInstance = enum {
false,
@ -8401,13 +8412,6 @@ pub const BackgroundBlur = union(enum) {
}
};
/// See background-glass-style
pub const BackgroundGlassStyle = enum {
off,
regular,
clear,
};
/// See window-decoration
pub const WindowDecoration = enum(c_int) {
auto,