From efc9d3957f18ada746206a22fe7719f6846a5a60 Mon Sep 17 00:00:00 2001 From: Haze Booth Date: Thu, 6 Jun 2024 23:37:00 -0400 Subject: [PATCH] feat: add `macos-title-bar-luminance-check` this paves the road for disabling the custom colored titleBar on macOS --- macos/Sources/Features/Terminal/TerminalController.swift | 2 ++ macos/Sources/Features/Terminal/TerminalWindow.swift | 4 +++- macos/Sources/Ghostty/Ghostty.Config.swift | 8 ++++++++ src/config/Config.zig | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index b0c2df1ca..abefb2ce6 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -265,6 +265,8 @@ class TerminalController: NSWindowController, NSWindowDelegate, if let windowTheme = ghostty.config.windowTheme { window.windowTheme = .init(rawValue: windowTheme) } + + window.titleBarLuminanceCheck = ghostty.config.titleBarLuminanceCheck // 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 diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index ce6f25e1e..a4a76f1a5 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -151,7 +151,7 @@ class TerminalWindow: NSWindow { if let titlebarContainer = contentView?.superview?.subviews.first(where: { $0.className == "NSTitlebarContainerView" }), let effectView = titlebarContainer.descendants(withClassName: "NSVisualEffectView").first { - effectView.isHidden = titlebarTabs || !titlebarTabs && !hasVeryDarkBackground + effectView.isHidden = titlebarTabs || !titlebarTabs && !hasVeryDarkBackground && !titleBarLuminanceCheck } effectViewIsHidden = true @@ -188,6 +188,8 @@ class TerminalWindow: NSWindow { var hasVeryDarkBackground: Bool { backgroundColor.luminance < 0.05 } + + var titleBarLuminanceCheck: Bool private var newTabButtonImageLayer: VibrantLayer? = nil diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index 2f455e578..8e3044b27 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -236,6 +236,14 @@ extension Ghostty { return v } + var titleBarLuminanceCheck: Bool { + guard let config = self.config else { return false } + var v = false; + let key = "macos-title-bar-luminance-check" + _ = ghostty_config_get(config, &v, key, UInt(key.count)) + return v + } + var backgroundColor: Color { var rgb: UInt32 = 0 let bg_key = "background" diff --git a/src/config/Config.zig b/src/config/Config.zig index cf38788cb..6f8ea49b2 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -976,6 +976,10 @@ keybind: Keybinds = .{}, /// This option only applies to new windows when changed. @"macos-titlebar-tabs": bool = false, +/// If `true`, check the luminance of the background and show the custom effect +/// (custom colored titlebars) )if the luminance is too low. +@"macos-title-bar-luminance-check": bool = true, + /// 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 on macOS if you use them via the *Alt* key. You may set this to