wip: support desktop portal color-scheme, and accent variables
This commit is contained in:
parent
c390b2614d
commit
06b46f455b
6 changed files with 107 additions and 34 deletions
|
|
@ -112,8 +112,8 @@ pub fn system_dark() -> Theme {
|
|||
}
|
||||
|
||||
pub fn system_light() -> Theme {
|
||||
let Ok(helper) = crate::cosmic_theme::Theme::dark_config() else {
|
||||
return Theme::dark();
|
||||
let Ok(helper) = crate::cosmic_theme::Theme::light_config() else {
|
||||
return Theme::light();
|
||||
};
|
||||
|
||||
let t = crate::cosmic_theme::Theme::get_entry(&helper).unwrap_or_else(|(errors, theme)| {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use ashpd::desktop::settings::{ColorScheme, Contrast};
|
||||
use ashpd::desktop::Color;
|
||||
use iced::futures::{self, select, FutureExt, SinkExt, StreamExt};
|
||||
use iced::Subscription;
|
||||
use iced_futures::subscription;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Desktop {
|
||||
|
|
@ -15,12 +17,56 @@ pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
|||
async move {
|
||||
let Ok(settings) = ashpd::desktop::settings::Settings::new().await else {
|
||||
// wait forever
|
||||
error!("Failed to create the settings proxy");
|
||||
futures::future::pending::<()>().await;
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
match settings.color_scheme().await {
|
||||
Ok(color_scheme) => {
|
||||
dbg!(color_scheme);
|
||||
let _ = tx.send(Desktop::ColorScheme(color_scheme)).await;
|
||||
}
|
||||
Err(err) => error!("Failed to get the color scheme {err:?}"),
|
||||
};
|
||||
// match settings
|
||||
// .read::<ashpd::zvariant::OwnedValue>("org.freedesktop.appearance", "accent-color")
|
||||
// .await
|
||||
// {
|
||||
// Ok(accent_color) => {
|
||||
// dbg!(&accent_color);
|
||||
// // let _ = tx.send(Desktop::Accent(accent_color)).await;
|
||||
// }
|
||||
// Err(err) => error!("Failed to get the accent color {err:?}"),
|
||||
// };
|
||||
match settings.contrast().await {
|
||||
Ok(contrast) => {
|
||||
dbg!(contrast);
|
||||
let _ = tx.send(Desktop::Contrast(contrast)).await;
|
||||
}
|
||||
Err(err) => error!("Failed to get the contrast {err:?}"),
|
||||
};
|
||||
|
||||
let mut color_scheme_stream = settings.receive_color_scheme_changed().await.ok();
|
||||
let mut accent_stream = settings.receive_accent_color_changed().await.ok();
|
||||
if color_scheme_stream.is_none() {
|
||||
error!("Failed to receive color scheme changes");
|
||||
}
|
||||
// Item type is wrong in this version
|
||||
// updating requires updating to zbus 4
|
||||
let mut accent_stream = settings
|
||||
.receive_setting_changed_with_args::<Color>(
|
||||
"org.freedesktop.appearance",
|
||||
"accent-color",
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
if accent_stream.is_none() {
|
||||
error!("Failed to receive accent color changes");
|
||||
}
|
||||
let mut contrast_stream = settings.receive_contrast_changed().await.ok();
|
||||
if contrast_stream.is_none() {
|
||||
error!("Failed to receive contrast changes");
|
||||
}
|
||||
|
||||
loop {
|
||||
let next_color_scheme = async {
|
||||
|
|
@ -29,18 +75,12 @@ pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
|||
}
|
||||
futures::future::pending().await
|
||||
};
|
||||
let next_accent = async {
|
||||
if let Some(s) = accent_stream.as_mut() {
|
||||
// Item type is wrong in this version
|
||||
// updating requires updating to zbus 4
|
||||
return if s.next().await.is_some() {
|
||||
settings.accent_color().await.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
futures::future::pending().await
|
||||
};
|
||||
// let next_accent = async {
|
||||
// if let Some(s) = accent_stream.as_mut() {
|
||||
// return s.next().await.and_then(std::result::Result::ok);
|
||||
// }
|
||||
// futures::future::pending().await
|
||||
// };
|
||||
let next_contrast = async {
|
||||
if let Some(s) = contrast_stream.as_mut() {
|
||||
return s.next().await;
|
||||
|
|
@ -56,13 +96,14 @@ pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
|||
color_scheme_stream = None;
|
||||
}
|
||||
},
|
||||
a = next_accent.fuse() => {
|
||||
if let Some(a) = a {
|
||||
_ = tx.send(Desktop::Accent(a)).await;
|
||||
} else {
|
||||
accent_stream = None;
|
||||
}
|
||||
},
|
||||
// a = next_accent.fuse() => {
|
||||
// dbg!(a);
|
||||
// if let Some(a) = a {
|
||||
// _ = tx.send(Desktop::Accent(a)).await;
|
||||
// } else {
|
||||
// accent_stream = None;
|
||||
// }
|
||||
// },
|
||||
c = next_contrast.fuse() => {
|
||||
if let Some(c) = c {
|
||||
_ = tx.send(Desktop::Contrast(c)).await;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue