libcosmic updates

This commit is contained in:
Ashley Wulber 2024-10-16 20:36:46 -04:00 committed by Ashley Wulber
parent 9c62f19e4b
commit 0491c4baaa
91 changed files with 3550 additions and 2300 deletions

View file

@ -14,6 +14,7 @@ use cosmic_config::CosmicConfigEntry;
use cosmic_theme::Component;
use cosmic_theme::LayeredTheme;
use iced_futures::Subscription;
use iced_runtime::{Appearance, DefaultStyle};
use std::sync::{Arc, Mutex};
@ -273,3 +274,14 @@ impl LayeredTheme for Theme {
self.layer = layer;
}
}
impl DefaultStyle for Theme {
fn default_style(&self) -> Appearance {
let cosmic = self.cosmic();
Appearance {
icon_color: cosmic.bg_color().into(),
background_color: cosmic.bg_color().into(),
text_color: cosmic.on_bg_color().into(),
}
}
}

View file

@ -1,7 +1,7 @@
use ashpd::desktop::settings::{ColorScheme, Contrast};
use ashpd::desktop::Color;
use iced::futures::{self, select, FutureExt, SinkExt, StreamExt};
use iced_futures::subscription;
use iced_futures::{stream, subscription};
use tracing::error;
#[derive(Debug, Clone)]
@ -12,86 +12,92 @@ pub enum Desktop {
}
pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
subscription::channel(std::any::TypeId::of::<Desktop>(), 10, |mut tx| {
async move {
let mut attempts = 0;
loop {
let Ok(settings) = ashpd::desktop::settings::Settings::new().await else {
error!("Failed to create the settings proxy");
#[cfg(feature = "tokio")]
::tokio::time::sleep(::tokio::time::Duration::from_secs(2_u64.pow(attempts)))
.await;
#[cfg(not(feature = "tokio"))]
{
pending::<()>().await;
unreachable!();
}
attempts += 1;
continue;
};
match settings.color_scheme().await {
Ok(color_scheme) => {
let _ = tx.send(Desktop::ColorScheme(color_scheme)).await;
}
Err(err) => error!("Failed to get the color scheme {err:?}"),
};
match settings.contrast().await {
Ok(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();
if color_scheme_stream.is_none() {
error!("Failed to receive color scheme changes");
}
let mut contrast_stream = settings.receive_contrast_changed().await.ok();
if contrast_stream.is_none() {
error!("Failed to receive contrast changes");
}
iced_futures::Subscription::run_with_id(
std::any::TypeId::of::<Desktop>(),
stream::channel(10, |mut tx| {
async move {
let mut attempts = 0;
loop {
if color_scheme_stream.is_none() && contrast_stream.is_none() {
break;
let Ok(settings) = ashpd::desktop::settings::Settings::new().await else {
error!("Failed to create the settings proxy");
#[cfg(feature = "tokio")]
::tokio::time::sleep(::tokio::time::Duration::from_secs(
2_u64.pow(attempts),
))
.await;
#[cfg(not(feature = "tokio"))]
{
pending::<()>().await;
unreachable!();
}
attempts += 1;
continue;
};
match settings.color_scheme().await {
Ok(color_scheme) => {
let _ = tx.send(Desktop::ColorScheme(color_scheme)).await;
}
Err(err) => error!("Failed to get the color scheme {err:?}"),
};
match settings.contrast().await {
Ok(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();
if color_scheme_stream.is_none() {
error!("Failed to receive color scheme changes");
}
let next_color_scheme = async {
if let Some(s) = color_scheme_stream.as_mut() {
return s.next().await;
}
futures::future::pending().await
};
let next_contrast = async {
if let Some(s) = contrast_stream.as_mut() {
return s.next().await;
}
futures::future::pending().await
};
let mut contrast_stream = settings.receive_contrast_changed().await.ok();
if contrast_stream.is_none() {
error!("Failed to receive contrast changes");
}
select! {
s = next_color_scheme.fuse() => {
if let Some(s) = s {
_ = tx.send(Desktop::ColorScheme(s)).await;
} else {
color_scheme_stream = None;
loop {
if color_scheme_stream.is_none() && contrast_stream.is_none() {
break;
}
let next_color_scheme = async {
if let Some(s) = color_scheme_stream.as_mut() {
return s.next().await;
}
},
futures::future::pending().await
};
c = next_contrast.fuse() => {
if let Some(c) = c {
_ = tx.send(Desktop::Contrast(c)).await;
} else {
contrast_stream = None;
let next_contrast = async {
if let Some(s) = contrast_stream.as_mut() {
return s.next().await;
}
}
};
// Reset the attempts counter if we successfully received a change
attempts = 0;
futures::future::pending().await
};
select! {
s = next_color_scheme.fuse() => {
if let Some(s) = s {
_ = tx.send(Desktop::ColorScheme(s)).await;
} else {
color_scheme_stream = None;
}
},
c = next_contrast.fuse() => {
if let Some(c) = c {
_ = tx.send(Desktop::Contrast(c)).await;
} else {
contrast_stream = None;
}
}
};
// Reset the attempts counter if we successfully received a change
attempts = 0;
}
}
}
}
})
}),
)
}

View file

@ -8,17 +8,17 @@ use iced_core::{Background, Color};
use crate::{
theme::TRANSPARENT_COMPONENT,
widget::button::{Appearance, StyleSheet},
widget::button::{Catalog, Style},
};
#[derive(Default)]
pub enum Button {
AppletIcon,
Custom {
active: Box<dyn Fn(bool, &crate::Theme) -> Appearance>,
disabled: Box<dyn Fn(&crate::Theme) -> Appearance>,
hovered: Box<dyn Fn(bool, &crate::Theme) -> Appearance>,
pressed: Box<dyn Fn(bool, &crate::Theme) -> Appearance>,
active: Box<dyn Fn(bool, &crate::Theme) -> Style>,
disabled: Box<dyn Fn(&crate::Theme) -> Style>,
hovered: Box<dyn Fn(bool, &crate::Theme) -> Style>,
pressed: Box<dyn Fn(bool, &crate::Theme) -> Style>,
},
AppletMenu,
Destructive,
@ -44,10 +44,10 @@ pub fn appearance(
disabled: bool,
style: &Button,
color: impl Fn(&Component) -> (Color, Option<Color>, Option<Color>),
) -> Appearance {
) -> Style {
let cosmic = theme.cosmic();
let mut corner_radii = &cosmic.corner_radii.radius_xl;
let mut appearance = Appearance::new();
let mut appearance = Style::new();
match style {
Button::Standard
@ -163,10 +163,10 @@ pub fn appearance(
appearance
}
impl StyleSheet for crate::Theme {
type Style = Button;
impl Catalog for crate::Theme {
type Class = Button;
fn active(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance {
fn active(&self, focused: bool, selected: bool, style: &Self::Class) -> Style {
if let Button::Custom { active, .. } = style {
return active(focused, self);
}
@ -186,7 +186,7 @@ impl StyleSheet for crate::Theme {
})
}
fn disabled(&self, style: &Self::Style) -> Appearance {
fn disabled(&self, style: &Self::Class) -> Style {
if let Button::Custom { disabled, .. } = style {
return disabled(self);
}
@ -202,11 +202,11 @@ impl StyleSheet for crate::Theme {
})
}
fn drop_target(&self, style: &Self::Style) -> Appearance {
fn drop_target(&self, style: &Self::Class) -> Style {
self.active(false, false, style)
}
fn hovered(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance {
fn hovered(&self, focused: bool, selected: bool, style: &Self::Class) -> Style {
if let Button::Custom { hovered, .. } = style {
return hovered(focused, self);
}
@ -233,7 +233,7 @@ impl StyleSheet for crate::Theme {
)
}
fn pressed(&self, focused: bool, selected: bool, style: &Self::Style) -> Appearance {
fn pressed(&self, focused: bool, selected: bool, style: &Self::Class) -> Style {
if let Button::Custom { pressed, .. } = style {
return pressed(focused, self);
}

File diff suppressed because it is too large Load diff

View file

@ -10,8 +10,6 @@ mod dropdown;
pub mod iced;
#[doc(inline)]
pub use self::iced::Application;
#[doc(inline)]
pub use self::iced::Checkbox;
#[doc(inline)]
pub use self::iced::Container;