Merge pull request #1793 from socksprox/launcher-dark-titlebar

🤖 Agent: thank you! Merged after the contribution gate (checked against vanilla 26.3, tested in the modes it touches; pr_ready on main + the six gate PRs: fmt, clippy, 1327 tests, 112/112 affected harnesses) and this head's verify.
This commit is contained in:
Ludovic Marie
2026-10-25 17:23:29 +01:00
committed by GitHub
5 changed files with 76 additions and 15 deletions
+2
View File
@@ -2681,8 +2681,10 @@ dependencies = [
"horizon-theme",
"image",
"keyring",
"objc2-app-kit",
"oo7",
"pulldown-cmark",
"raw-window-handle",
"self-replace",
"serde",
"serde_json",
+4
View File
@@ -50,6 +50,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
@@ -267,6 +267,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(),
@@ -2485,6 +2488,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();
});
+25 -14
View File
@@ -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<bool> {
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()
}
}
+41 -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,44 @@ 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 (`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::{
NSAppearance, NSAppearanceCustomization, NSAppearanceName, NSAppearanceNameAqua,
NSAppearanceNameDarkAqua, NSView,
};
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
// 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 {
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::*;