Unify theme sizing and spacing on Base UI metrics
- Read only mode, accent, accessibility, and native window material from the OS. - Replace platform palettes, metrics, type ramps, borders, and elevations with unified tokens. - Align controls, overlays, and data rows with Base UI sizing.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//! Linux adapter selection: Omarchy → KDE → portal (GNOME/generic) →
|
||||
//! fallback, per the plan's detection cascade. Omarchy and KDE palettes come
|
||||
//! from their files; the portal supplements mode, accent, and the
|
||||
//! accessibility flags; `gsettings` covers sessions without a portal.
|
||||
//! fallback, per the plan's detection cascade. Omarchy and KDE state the mode
|
||||
//! and accent; the portal supplements both with the accessibility flags;
|
||||
//! `gsettings` covers sessions without a portal.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use gpui::{Hsla, Pixels};
|
||||
use gpui::Hsla;
|
||||
use notify::{RecursiveMode, Watcher};
|
||||
|
||||
use super::ThemeSource;
|
||||
@@ -16,26 +16,7 @@ use super::signal::ReapplySignal;
|
||||
|
||||
use crate::ThemeVariant;
|
||||
|
||||
use crate::system::{PartialPalette, SourceKind, SystemTheme};
|
||||
|
||||
/// libadwaita's control corner radius, in px at 100% scaling.
|
||||
const CONTROL_RADIUS_PX: f32 = 9.0;
|
||||
/// libadwaita's popover corner radius.
|
||||
const OVERLAY_RADIUS_PX: f32 = 15.0;
|
||||
/// The checkbox indicator's corner radius.
|
||||
const SM_RADIUS_PX: f32 = 6.0;
|
||||
/// libadwaita's standard control and text-field height.
|
||||
const CONTROL_HEIGHT_PX: f32 = 34.0;
|
||||
/// The GTK menu row height.
|
||||
const MENU_ITEM_HEIGHT_PX: f32 = 32.0;
|
||||
/// The GTK switch: a 46x26 track with a 20px knob.
|
||||
const SWITCH_HEIGHT_PX: f32 = 26.0;
|
||||
const SWITCH_WIDTH_PX: f32 = 46.0;
|
||||
const SWITCH_KNOB_PX: f32 = 20.0;
|
||||
/// GNOME's headerbar height, in px at 100% scaling.
|
||||
const TITLEBAR_HEIGHT_PX: f32 = 47.0;
|
||||
/// The default 11pt interface font, in px.
|
||||
const ROOT_FONT_SIZE_PX: f32 = 14.67;
|
||||
use crate::system::{SourceKind, SystemTheme};
|
||||
|
||||
pub(crate) struct LinuxSource {
|
||||
backend: Backend,
|
||||
@@ -87,7 +68,6 @@ fn detect(home: &Path, portal_reachable: bool, gsettings_reachable: bool) -> Bac
|
||||
struct GSettingsSnapshot {
|
||||
variant: Option<ThemeVariant>,
|
||||
accent: Option<Hsla>,
|
||||
root_font_size: Option<Pixels>,
|
||||
}
|
||||
|
||||
fn gsettings_value(args: &[&str]) -> Option<String> {
|
||||
@@ -129,22 +109,10 @@ fn read_gsettings() -> Option<GSettingsSnapshot> {
|
||||
let accent = gsettings_value(&["get", "org.gnome.desktop.interface", "accent-color"])
|
||||
.and_then(|value| accent_rgb(value.trim().trim_matches('\'')));
|
||||
|
||||
let root_font_size = gsettings_value(&["get", "org.gnome.desktop.interface", "font-name"])
|
||||
.and_then(|value| font_root_px(value.trim().trim_matches('\'')));
|
||||
|
||||
if variant.is_none() && accent.is_none() && root_font_size.is_none() {
|
||||
if variant.is_none() && accent.is_none() {
|
||||
return None;
|
||||
}
|
||||
Some(GSettingsSnapshot {
|
||||
variant,
|
||||
accent,
|
||||
root_font_size,
|
||||
})
|
||||
}
|
||||
|
||||
fn font_root_px(name: &str) -> Option<Pixels> {
|
||||
let points = name.split_whitespace().last()?.parse::<f32>().ok()?;
|
||||
(points > 0.0).then(|| gpui::px(points * 96.0 / 72.0))
|
||||
Some(GSettingsSnapshot { variant, accent })
|
||||
}
|
||||
|
||||
pub(crate) fn platform_source() -> Box<dyn ThemeSource> {
|
||||
@@ -174,22 +142,6 @@ impl LinuxSource {
|
||||
SystemTheme {
|
||||
variant,
|
||||
accent,
|
||||
palette: PartialPalette::default(),
|
||||
control_radius: Some(gpui::px(CONTROL_RADIUS_PX)),
|
||||
overlay_radius: Some(gpui::px(OVERLAY_RADIUS_PX)),
|
||||
sm_radius: Some(gpui::px(SM_RADIUS_PX)),
|
||||
control_height: Some(gpui::px(CONTROL_HEIGHT_PX)),
|
||||
input_height: Some(gpui::px(CONTROL_HEIGHT_PX)),
|
||||
menu_item_height: Some(gpui::px(MENU_ITEM_HEIGHT_PX)),
|
||||
switch_height: Some(gpui::px(SWITCH_HEIGHT_PX)),
|
||||
switch_width: Some(gpui::px(SWITCH_WIDTH_PX)),
|
||||
switch_knob: Some(gpui::px(SWITCH_KNOB_PX)),
|
||||
titlebar_height: Some(gpui::px(TITLEBAR_HEIGHT_PX)),
|
||||
root_font_size: Some(
|
||||
self.gsettings
|
||||
.and_then(|gsettings| gsettings.root_font_size)
|
||||
.unwrap_or(gpui::px(ROOT_FONT_SIZE_PX)),
|
||||
),
|
||||
accessibility,
|
||||
window_background: None,
|
||||
source: SourceKind::Gnome,
|
||||
@@ -358,25 +310,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gsettings_font_name_states_the_root_font_size() {
|
||||
assert_eq!(
|
||||
font_root_px("Adwaita Sans 11"),
|
||||
Some(gpui::px(11.0 * 96.0 / 72.0))
|
||||
);
|
||||
assert_eq!(
|
||||
font_root_px("Noto Sans 10"),
|
||||
Some(gpui::px(10.0 * 96.0 / 72.0))
|
||||
);
|
||||
assert_eq!(
|
||||
font_root_px("Cantarell Bold 12.5"),
|
||||
Some(gpui::px(12.5 * 96.0 / 72.0))
|
||||
);
|
||||
assert_eq!(font_root_px("Adwaita Sans"), None);
|
||||
assert_eq!(font_root_px("Sans 0"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gnome_snapshot_labels_gnome_and_defaults_the_root_font() {
|
||||
fn the_gnome_snapshot_labels_gnome() {
|
||||
let source = LinuxSource {
|
||||
backend: Backend::Portal,
|
||||
portal: None,
|
||||
@@ -391,7 +325,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(system.source, SourceKind::Gnome);
|
||||
// The default 11pt font when gsettings states none.
|
||||
assert_eq!(system.root_font_size, Some(gpui::px(ROOT_FONT_SIZE_PX)));
|
||||
assert_eq!(system.variant, ThemeVariant::Light);
|
||||
assert_eq!(system.accent, None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user