chore: audit components
This commit is contained in:
@@ -13,9 +13,30 @@ use super::kde;
|
||||
use super::omarchy;
|
||||
use super::portal;
|
||||
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;
|
||||
|
||||
pub(crate) struct LinuxSource {
|
||||
backend: Backend,
|
||||
portal: Option<portal::io::PortalClient>,
|
||||
@@ -154,20 +175,20 @@ impl LinuxSource {
|
||||
variant,
|
||||
accent,
|
||||
palette: PartialPalette::default(),
|
||||
control_radius: Some(gpui::px(9.)),
|
||||
overlay_radius: Some(gpui::px(15.)),
|
||||
sm_radius: Some(gpui::px(6.)),
|
||||
control_height: Some(gpui::px(34.)),
|
||||
input_height: Some(gpui::px(34.)),
|
||||
menu_item_height: Some(gpui::px(32.)),
|
||||
switch_height: Some(gpui::px(26.)),
|
||||
switch_width: Some(gpui::px(46.)),
|
||||
switch_knob: Some(gpui::px(20.)),
|
||||
titlebar_height: Some(gpui::px(47.)),
|
||||
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(14.67)),
|
||||
.unwrap_or(gpui::px(ROOT_FONT_SIZE_PX)),
|
||||
),
|
||||
accessibility,
|
||||
window_background: None,
|
||||
@@ -237,41 +258,44 @@ impl ThemeSource for LinuxSource {
|
||||
|
||||
fn install_watchers(&mut self, async_cx: gpui::AsyncApp) {
|
||||
let signal = ReapplySignal::install(&async_cx);
|
||||
let file_signal = signal.sender();
|
||||
|
||||
if let Some(portal) = &self.portal {
|
||||
portal.spawn_watch(signal.sender());
|
||||
}
|
||||
|
||||
// Stored before any fallible step: an early return below
|
||||
// must not drop and cancel the reapply loop.
|
||||
self._signal = Some(signal);
|
||||
|
||||
match self.backend {
|
||||
Backend::Omarchy => {
|
||||
let Some(current) = omarchy::io::current_dir() else {
|
||||
return;
|
||||
};
|
||||
let reapply_signal = signal.sender();
|
||||
|
||||
let watcher = notify::recommended_watcher(
|
||||
move |event: std::result::Result<notify::Event, notify::Error>| match event {
|
||||
Ok(_) => ReapplySignal::poke(&reapply_signal),
|
||||
Err(error) => eprintln!("theme: omarchy watch error: {error}"),
|
||||
Ok(_) => ReapplySignal::poke(&file_signal),
|
||||
Err(error) => log::warn!("theme: omarchy watch error: {error}"),
|
||||
},
|
||||
);
|
||||
|
||||
match watcher {
|
||||
Ok(mut watcher) => {
|
||||
if let Err(error) = watcher.watch(¤t, RecursiveMode::NonRecursive) {
|
||||
eprintln!("theme: omarchy watch failed: {error}");
|
||||
log::warn!("theme: omarchy watch failed: {error}");
|
||||
return;
|
||||
}
|
||||
self.file_watcher = Some(watcher);
|
||||
}
|
||||
Err(error) => eprintln!("theme: omarchy watcher unavailable: {error}"),
|
||||
Err(error) => log::warn!("theme: omarchy watcher unavailable: {error}"),
|
||||
}
|
||||
}
|
||||
Backend::Kde => {
|
||||
let Some(config) = home_dir().map(|home| home.join(".config")) else {
|
||||
return;
|
||||
};
|
||||
let reapply_signal = signal.sender();
|
||||
|
||||
let watcher = notify::recommended_watcher(
|
||||
move |event: std::result::Result<notify::Event, notify::Error>| match event {
|
||||
@@ -279,27 +303,25 @@ impl ThemeSource for LinuxSource {
|
||||
if event.paths.iter().any(|path| {
|
||||
path.file_name().is_some_and(|name| name == "kdeglobals")
|
||||
}) {
|
||||
ReapplySignal::poke(&reapply_signal);
|
||||
ReapplySignal::poke(&file_signal);
|
||||
}
|
||||
}
|
||||
Err(error) => eprintln!("theme: kde watch error: {error}"),
|
||||
Err(error) => log::warn!("theme: kde watch error: {error}"),
|
||||
},
|
||||
);
|
||||
match watcher {
|
||||
Ok(mut watcher) => {
|
||||
if let Err(error) = watcher.watch(&config, RecursiveMode::NonRecursive) {
|
||||
eprintln!("theme: kde watch failed: {error}");
|
||||
log::warn!("theme: kde watch failed: {error}");
|
||||
return;
|
||||
}
|
||||
self.file_watcher = Some(watcher);
|
||||
}
|
||||
Err(error) => eprintln!("theme: kde watcher unavailable: {error}"),
|
||||
Err(error) => log::warn!("theme: kde watcher unavailable: {error}"),
|
||||
}
|
||||
}
|
||||
Backend::Portal | Backend::Fallback => {}
|
||||
}
|
||||
|
||||
self._signal = Some(signal);
|
||||
}
|
||||
|
||||
fn label(&self) -> &'static str {
|
||||
@@ -354,7 +376,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gnome_snapshot_states_the_libadwaita_metrics() {
|
||||
fn the_gnome_snapshot_labels_gnome_and_defaults_the_root_font() {
|
||||
let source = LinuxSource {
|
||||
backend: Backend::Portal,
|
||||
portal: None,
|
||||
@@ -369,17 +391,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(system.source, SourceKind::Gnome);
|
||||
assert_eq!(system.control_height, Some(gpui::px(34.)));
|
||||
assert_eq!(system.input_height, Some(gpui::px(34.)));
|
||||
assert_eq!(system.menu_item_height, Some(gpui::px(32.)));
|
||||
assert_eq!(system.control_radius, Some(gpui::px(9.)));
|
||||
assert_eq!(system.overlay_radius, Some(gpui::px(15.)));
|
||||
assert_eq!(system.sm_radius, Some(gpui::px(6.)));
|
||||
assert_eq!(system.switch_height, Some(gpui::px(26.)));
|
||||
assert_eq!(system.switch_width, Some(gpui::px(46.)));
|
||||
assert_eq!(system.switch_knob, Some(gpui::px(20.)));
|
||||
assert_eq!(system.titlebar_height, Some(gpui::px(47.)));
|
||||
// The default 11pt font when gsettings states none.
|
||||
assert_eq!(system.root_font_size, Some(gpui::px(14.67)));
|
||||
assert_eq!(system.root_font_size, Some(gpui::px(ROOT_FONT_SIZE_PX)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user