//! The normalized snapshot a platform adapter produces. use gpui::{Hsla, Pixels}; use crate::ThemeVariant; /// Accessibility preferences read from the OS, forwarded into resolution. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct AccessibilityPreferences { pub high_contrast: bool, pub reduce_motion: bool, pub reduce_transparency: bool, } /// Which adapter produced a [`SystemTheme`]. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(not(any(target_os = "linux", target_os = "windows")), allow(dead_code))] pub enum SourceKind { #[default] Fallback, Macos, Omarchy, Kde, Gnome, Windows, } impl SourceKind { pub fn label(self) -> &'static str { match self { Self::Fallback => "neutral fallback", Self::Macos => "macOS (NSColor)", Self::Omarchy => "Omarchy (colors.toml)", Self::Kde => "KDE (kdeglobals)", Self::Gnome => "GNOME (portal)", Self::Windows => "Windows 11 (UISettings)", } } /// Overlay scrollbars hide while idle on macOS, GNOME, and Omarchy. /// /// Windows and KDE keep theirs drawn. pub fn scrollbar_autohide(self) -> bool { matches!(self, Self::Macos | Self::Omarchy | Self::Gnome) } } /// A partial palette with optional colors. #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct PartialPalette { pub background: Option, pub foreground: Option, pub surface: Option, pub surface_foreground: Option, pub primary_foreground: Option, pub accent_foreground: Option, pub secondary: Option, pub secondary_foreground: Option, pub muted: Option, /// No platform states a hover wash, presets override it. pub muted_hover: Option, pub muted_foreground: Option, pub destructive: Option, /// No platform states severity colors, presets override them. pub success: Option, pub warning: Option, pub info: Option, pub border: Option, pub input: Option, pub ring: Option, pub selection: Option, /// No platform states a scrim color; preset and user files override it. pub overlay: Option, /// No platform states a scrollbar thumb color; presets override it. pub scrollbar_thumb: Option, } /// A normalized snapshot of the running system's theme. #[derive(Clone, Copy, Debug, PartialEq)] pub struct SystemTheme { pub variant: ThemeVariant, pub accent: Option, pub palette: PartialPalette, /// The platform's stated control corner radius, if it has one. pub control_radius: Option, /// The platform's stated text-field height, if it has one. pub input_height: Option, /// The platform's native titlebar height, if it states one. pub titlebar_height: Option, /// The platform's native root font size, if it has one. pub root_font_size: Option, pub accessibility: AccessibilityPreferences, pub source: SourceKind, } impl SystemTheme { pub fn fallback(variant: ThemeVariant) -> Self { Self { variant, accent: None, palette: PartialPalette::default(), control_radius: None, input_height: None, titlebar_height: None, root_font_size: None, accessibility: AccessibilityPreferences::default(), source: SourceKind::Fallback, } } }