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>
This commit is contained in:
socksprox
2026-10-25 13:40:07 +01:00
parent ad63f2e960
commit 3740de5116
4 changed files with 58 additions and 1 deletions
+2
View File
@@ -2680,8 +2680,10 @@ dependencies = [
"horizon-theme",
"image",
"keyring",
"objc2-app-kit",
"oo7",
"pulldown-cmark",
"raw-window-handle",
"self-replace",
"serde",
"serde_json",
+4
View File
@@ -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"] }
+4
View File
@@ -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();
});
+48 -1
View File
@@ -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<Div> {
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::<NSView>().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::*;