Skip to content

Commit

Permalink
fix: the accent-color
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 17, 2024
1 parent ebefecd commit ab4dd2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ async fn async_watch<P: AsRef<Path>>(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;
}
Expand Down
27 changes: 17 additions & 10 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@ pub static SETTING_CONFIG: Lazy<Arc<Mutex<SettingsConfig>>> =
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)]
Expand All @@ -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()))
}
Expand All @@ -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())
}
Expand Down
6 changes: 3 additions & 3 deletions src/settings/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ 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(
csscolorparser::parse(DEFAULT_ACCENT_COLLOR)
.unwrap()
.to_rgba8(),
);
(
[
color[0] as f64 / 256.0,
color[1] as f64 / 256.0,
color[2] as f64 / 256.0,
)
]
}
}

Expand Down

0 comments on commit ab4dd2b

Please sign in to comment.