From ab4dd2b7dba117a33a15d8d62a73df90a9c223e8 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Thu, 17 Oct 2024 20:43:14 +0900 Subject: [PATCH] fix: the accent-color --- src/main.rs | 8 +++----- src/settings.rs | 27 +++++++++++++++++---------- src/settings/config.rs | 6 +++--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index bf7c58e..ea7ef1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,11 +114,9 @@ async fn async_watch>(path: P) -> notify::Result<()> { &signal_context, "org.freedesktop.appearance".to_string(), "accent-color".to_string(), - AccentColor { - color: config.get_accent_color(), - } - .try_into() - .unwrap(), + AccentColor::new(config.get_accent_color()) + .try_into() + .unwrap(), ) .await; } diff --git a/src/settings.rs b/src/settings.rs index c509639..f38706f 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -22,9 +22,20 @@ pub static SETTING_CONFIG: Lazy>> = Lazy::new(|| Arc::new(Mutex::new(SettingsConfig::config_from_file()))); #[derive(DeserializeDict, SerializeDict, Clone, Copy, PartialEq, Type, OwnedValue, Value)] -#[zvariant(signature = "dict")] pub struct AccentColor { - pub color: (f64, f64, f64), + red: f64, + green: f64, + blue: f64, +} + +impl AccentColor { + pub fn new(rgb: [f64; 3]) -> Self { + Self { + red: rgb[0], + green: rgb[1], + blue: rgb[2], + } + } } #[derive(Debug)] @@ -46,10 +57,9 @@ impl SettingsBackend { return Ok(OwnedValue::from(config.get_color_scheme())); } if key == ACCENT_COLOR { - return Ok(OwnedValue::try_from(AccentColor { - color: config.get_accent_color(), - }) - .unwrap()); + return Ok(AccentColor::new(config.get_accent_color()) + .try_into() + .unwrap()); } Err(zbus::fdo::Error::Failed("No such namespace".to_string())) } @@ -63,10 +73,7 @@ impl SettingsBackend { output.insert(COLOR_SCHEME.to_string(), config.get_color_scheme().into()); output.insert( ACCENT_COLOR.to_string(), - OwnedValue::try_from(AccentColor { - color: config.get_accent_color(), - }) - .unwrap(), + OwnedValue::try_from(AccentColor::new(config.get_accent_color())).unwrap(), ); Ok(output.into()) } diff --git a/src/settings/config.rs b/src/settings/config.rs index 148006d..24fdfb4 100644 --- a/src/settings/config.rs +++ b/src/settings/config.rs @@ -21,7 +21,7 @@ impl SettingsConfig { _ => unreachable!(), } } - pub fn get_accent_color(&self) -> (f64, f64, f64) { + pub fn get_accent_color(&self) -> [f64; 3] { let color = csscolorparser::parse(&self.accent_color) .map(|color| color.to_rgba8()) .unwrap_or( @@ -29,11 +29,11 @@ impl SettingsConfig { .unwrap() .to_rgba8(), ); - ( + [ color[0] as f64 / 256.0, color[1] as f64 / 256.0, color[2] as f64 / 256.0, - ) + ] } }