From 3740de5116dbf9322e39d18c3ce0777d087d0401 Mon Sep 17 00:00:00 2001 From: socksprox Date: Sun, 25 Oct 2026 13:40:07 +0100 Subject: [PATCH 1/2] 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::*; From 98bebd26bdc33efaa4483ac5d5cbb07250fc1345 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:14:48 +0100 Subject: [PATCH 2/2] Launcher: one place reads the pinned appearance (theme::pinned_dark) The title bar and the theme both resolved HORIZON_LAUNCHER_APPEARANCE and the Settings choice; titlebar::apply_appearance now uses the theme's helper. Co-Authored-By: Claude Opus 5.5 --- launcher/src/theme.rs | 39 +++++++++++++++++++++++++-------------- launcher/src/titlebar.rs | 21 +++++++-------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/launcher/src/theme.rs b/launcher/src/theme.rs index 60b796709..9d495a598 100644 --- a/launcher/src/theme.rs +++ b/launcher/src/theme.rs @@ -74,22 +74,33 @@ fn c(hex: u32) -> Hsla { rgb(hex).into() } +/// Whether the launcher is pinned dark (`Some(true)`) or light, or follows the system (`None`): +/// `HORIZON_LAUNCHER_APPEARANCE=light` or `dark` (for screenshots and tests), else the player's +/// choice in Settings. +pub fn pinned_dark(choice: Appearance) -> Option { + match std::env::var("HORIZON_LAUNCHER_APPEARANCE").as_deref() { + Ok("light") => Some(false), + Ok("dark") => Some(true), + _ => match choice { + Appearance::Dark => Some(true), + Appearance::Light => Some(false), + Appearance::System => None, + }, + } +} + impl Theme { - /// The player's choice in Settings (dark unless they picked another), the system's when they - /// asked to follow it. `HORIZON_LAUNCHER_APPEARANCE=light` or `dark` overrides both (for - /// screenshots and tests). + /// The pinned look (`pinned_dark`: dark unless the player picked another), the system's when + /// they asked to follow it. pub fn for_appearance(choice: Appearance, system: WindowAppearance) -> Self { - match std::env::var("HORIZON_LAUNCHER_APPEARANCE").as_deref() { - Ok("light") => return Self::light(), - Ok("dark") => return Self::dark(), - _ => {} - } - match (choice, system) { - (Appearance::Light, _) => Self::light(), - (Appearance::System, WindowAppearance::Light | WindowAppearance::VibrantLight) => { - Self::light() - } - _ => Self::dark(), + let system_dark = !matches!( + system, + WindowAppearance::Light | WindowAppearance::VibrantLight + ); + if pinned_dark(choice).unwrap_or(system_dark) { + Self::dark() + } else { + Self::light() } } diff --git a/launcher/src/titlebar.rs b/launcher/src/titlebar.rs index 2e6445091..a023f7d7d 100644 --- a/launcher/src/titlebar.rs +++ b/launcher/src/titlebar.rs @@ -22,9 +22,8 @@ pub fn render(_theme: &Theme, _window: &Window) -> Option
{ /// 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). +/// instead (`theme::pinned_dark`: `System` clears the pin, handing the chrome back to the +/// system). Elsewhere the chrome is ours (Windows) or the system's (Linux). #[cfg(target_os = "macos")] pub fn apply_appearance(window: &Window, choice: Appearance) { use objc2_app_kit::{ @@ -33,17 +32,11 @@ pub fn apply_appearance(window: &Window, choice: Appearance) { }; 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, - }, - } + // AppKit's name constants are extern statics: reading them is `unsafe` to rustc only. + let name: Option<&'static NSAppearanceName> = match crate::theme::pinned_dark(choice) { + Some(true) => Some(unsafe { NSAppearanceNameDarkAqua }), + Some(false) => Some(unsafe { NSAppearanceNameAqua }), + None => None, }; // The trait, not `Window::window_handle` (which is gpui's own `AnyWindowHandle`). let Ok(handle) = HasWindowHandle::window_handle(window) else {