From 3740de5116dbf9322e39d18c3ce0777d087d0401 Mon Sep 17 00:00:00 2001 From: socksprox Date: Sun, 25 Oct 2026 13:40:07 +0100 Subject: [PATCH] Launcher: pin the macOS title bar to the chosen appearance The launcher's Appearance setting darkened the page but not the window's native chrome: NSWindow keeps the system appearance, so a launcher set to Dark still drew a light title bar on a light desktop. apply_appearance (titlebar.rs) pins the NSWindow's appearance to the choice at startup and when the setting changes; System clears the pin so the chrome follows the computer again. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- launcher/Cargo.lock | 2 ++ launcher/Cargo.toml | 4 ++++ launcher/src/main.rs | 4 ++++ launcher/src/titlebar.rs | 49 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index 5155420e0..922a92f2f 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -2680,8 +2680,10 @@ dependencies = [ "horizon-theme", "image", "keyring", + "objc2-app-kit", "oo7", "pulldown-cmark", + "raw-window-handle", "self-replace", "serde", "serde_json", diff --git a/launcher/Cargo.toml b/launcher/Cargo.toml index a402d0e28..570e2bd75 100644 --- a/launcher/Cargo.toml +++ b/launcher/Cargo.toml @@ -48,6 +48,10 @@ oo7 = { version = "0.5", default-features = false, features = ["async-std", "nat futures-lite = "2" [target.'cfg(target_os = "macos")'.dependencies] keyring = { version = "3", features = ["apple-native"] } +# Painting the window's title bar dark or light (titlebar::apply_appearance): crates already in +# the lockfile through gpui and wgpu. +objc2-app-kit = { version = "0.3", default-features = false, features = ["NSAppearance", "NSView", "NSWindow"] } +raw-window-handle = "0.6" [target.'cfg(target_os = "windows")'.dependencies] keyring = { version = "3", features = ["windows-native"] } diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 0bcbc4011..ebde171e5 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -265,6 +265,9 @@ impl Launcher { { settings.selected = installed.first().cloned(); } + // Pin the window's chrome (macOS title bar) to the choice before the theme reads + // `window.appearance()`, so both draw the same look. + titlebar::apply_appearance(window, settings.appearance); let mut this = Self { theme: Theme::for_appearance(settings.appearance, window.appearance()), page: Page::from_env(), @@ -2482,6 +2485,7 @@ impl Launcher { let _ = this.update(cx, |this, cx| { this.settings.appearance = choice; this.settings.save(); + titlebar::apply_appearance(window, choice); this.theme = Theme::for_appearance(choice, window.appearance()); cx.notify(); }); diff --git a/launcher/src/titlebar.rs b/launcher/src/titlebar.rs index 3c2a78ea4..2e6445091 100644 --- a/launcher/src/titlebar.rs +++ b/launcher/src/titlebar.rs @@ -1,6 +1,8 @@ -//! Custom Windows chrome. Other platforms keep their native window decorations. +//! Custom Windows chrome. Other platforms keep their native window decorations; on macOS, +//! `apply_appearance` repaints that chrome (the title bar) to match the chosen look. use crate::theme::Theme; use gpui::{Div, TitlebarOptions, Window}; +use horizon_launcher::backend::Appearance; /// Whether the launcher draws its own title bar (`render`) rather than the system. pub const DRAWN: bool = cfg!(target_os = "windows"); @@ -18,6 +20,51 @@ pub fn render(_theme: &Theme, _window: &Window) -> Option
{ None } +/// macOS keeps the window's appearance on the system setting, so a launcher set to Dark still +/// draws a light title bar on a light desktop. Pin the NSWindow's appearance to the choice +/// instead (`System` clears the pin, handing the chrome back to the system), honouring the same +/// `HORIZON_LAUNCHER_APPEARANCE` override the theme does. Other platforms' chrome already +/// follows the setting (ours is drawn, Windows and Linux follow the system either way). +#[cfg(target_os = "macos")] +pub fn apply_appearance(window: &Window, choice: Appearance) { + use objc2_app_kit::{ + NSAppearance, NSAppearanceCustomization, NSAppearanceName, NSAppearanceNameAqua, + NSAppearanceNameDarkAqua, NSView, + }; + use raw_window_handle::{HasWindowHandle, RawWindowHandle}; + + // Reading AppKit's name constants is unsafe to rustc only (`use of extern static`). + let name: Option<&'static NSAppearanceName> = unsafe { + match std::env::var("HORIZON_LAUNCHER_APPEARANCE").as_deref() { + Ok("light") => Some(NSAppearanceNameAqua), + Ok("dark") => Some(NSAppearanceNameDarkAqua), + _ => match choice { + Appearance::Dark => Some(NSAppearanceNameDarkAqua), + Appearance::Light => Some(NSAppearanceNameAqua), + Appearance::System => None, + }, + } + }; + // The trait, not `Window::window_handle` (which is gpui's own `AnyWindowHandle`). + let Ok(handle) = HasWindowHandle::window_handle(window) else { + return; + }; + let RawWindowHandle::AppKit(appkit) = handle.as_raw() else { + return; + }; + // The handle is the window's content view; its `window` is the NSWindow itself. Both outlive + // this call. + let view = unsafe { appkit.ns_view.cast::().as_ref() }; + let Some(native) = view.window() else { + return; + }; + let appearance = name.and_then(NSAppearance::appearanceNamed); + native.setAppearance(appearance.as_deref()); +} + +#[cfg(not(target_os = "macos"))] +pub fn apply_appearance(_: &Window, _: Appearance) {} + #[cfg(target_os = "windows")] mod windows { use super::*;