diff --git a/app/src/main.rs b/app/src/main.rs index 3150a25..6abe37b 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -8,15 +8,13 @@ pub mod app; pub use app::{Message, SettingsApp}; - pub mod config; #[macro_use] pub mod localize; - -pub mod widget; - pub mod pages; +pub mod theme; +pub mod widget; use cosmic::{ iced::{wayland::actions::window::SctkWindowSettings, Application, Limits}, diff --git a/app/src/pages/desktop/wallpaper.rs b/app/src/pages/desktop/wallpaper.rs index ee618f0..bacce13 100644 --- a/app/src/pages/desktop/wallpaper.rs +++ b/app/src/pages/desktop/wallpaper.rs @@ -9,6 +9,7 @@ use cosmic::{ iced::widget::{column, container, horizontal_space, row, text}, iced::Length, iced_runtime::core::image::Handle as ImageHandle, + iced_widget::core::renderer::BorderRadius, theme, widget::{list_column, settings, toggler}, Element, @@ -57,7 +58,7 @@ impl Page { Message::SameBackground(value) => self.same_background = value, Message::Select(id) => { if let Some(path) = self.selection.paths.get(id) { - wallpaper::set(&mut self.config, Entry::new(Output::All, path.to_owned())); + wallpaper::set(&mut self.config, Entry::new(Output::All, path.clone())); self.selection.active = id; } } @@ -65,6 +66,20 @@ impl Page { Message::Update((config, selection)) => { self.config = config; self.selection = selection; + + if let Some(entry) = self + .config + .backgrounds + .iter() + .find(|b| b.output == Output::All) + { + self.same_background = true; + for (entity, path) in self.selection.paths.iter() { + if path == &entry.source { + self.selection.active = entity; + } + } + } } } } @@ -88,7 +103,9 @@ impl page::Page for Page { Some(Box::pin(async move { let config = wallpaper::config(); - let mut backgrounds = wallpaper::load_each_from_path("/usr/share/backgrounds".into()); + let mut backgrounds = + wallpaper::load_each_from_path("/usr/share/backgrounds/pop/".into()); + let mut update = Context::default(); let start = Instant::now(); @@ -142,19 +159,7 @@ pub fn settings() -> Section { let mut children = Vec::with_capacity(3); if let Some(image) = page.selection.handles.get(page.selection.active) { - let display_preview = row!( - horizontal_space(Length::Fill), - container( - cosmic::iced::widget::image(image.clone()).width(Length::Fixed(300.0)) - ) - .padding(4) - .style(theme::Container::Background), - horizontal_space(Length::Fill), - ) - .padding([0, 0, 8, 0]) - .into(); - - children.push(display_preview); + children.push(crate::widget::display_container(image.clone(), 300.0)); } children.push( diff --git a/app/src/theme.rs b/app/src/theme.rs new file mode 100644 index 0000000..1b93ffc --- /dev/null +++ b/app/src/theme.rs @@ -0,0 +1,15 @@ +// Copyright 2023 System76 +// SPDX-License-Identifier: GPL-3.0-only + +use cosmic::{iced_widget::core::renderer::BorderRadius, theme}; + +#[must_use] +pub fn display_container() -> cosmic::theme::Container { + theme::Container::custom(|_theme| cosmic::iced::widget::container::Appearance { + text_color: None, + background: Some(cosmic::iced::Background::Color(cosmic::iced::Color::WHITE)), + border_color: cosmic::iced::Color::WHITE, + border_radius: BorderRadius::from(4.0), + border_width: 3.0, + }) +} diff --git a/app/src/widget/mod.rs b/app/src/widget/mod.rs index 4461809..ca59bbf 100644 --- a/app/src/widget/mod.rs +++ b/app/src/widget/mod.rs @@ -2,12 +2,15 @@ // SPDX-License-Identifier: GPL-3.0-only use apply::Apply; -use cosmic::iced::{ - self, - widget::{button, column, container, horizontal_space, row, vertical_space, Button}, - Length, -}; use cosmic::widget::{divider, icon, list, settings, text}; +use cosmic::{ + iced::{ + self, + widget::{button, column, container, horizontal_space, row, vertical_space, Button}, + Length, + }, + iced_widget::core::image, +}; use cosmic::{theme, Element}; use cosmic_settings_page as page; @@ -131,3 +134,19 @@ pub fn unimplemented_page() -> Element<'static, Message> { .add(text("We haven't created that panel yet, and/or it is using a similar idea as current Pop! designs.")) .into() } + +#[must_use] +pub fn display_container<'a, Message: 'a>( + image: image::Handle, + width: f32, +) -> cosmic::Element<'a, Message> { + row!( + horizontal_space(Length::Fill), + container(cosmic::iced::widget::image(image).width(Length::Fixed(width))) + .padding(4) + .style(crate::theme::display_container()), + horizontal_space(Length::Fill), + ) + .padding([0, 0, 8, 0]) + .into() +} diff --git a/pages/desktop/src/wallpaper.rs b/pages/desktop/src/wallpaper.rs index bf615b8..1377bbf 100644 --- a/pages/desktop/src/wallpaper.rs +++ b/pages/desktop/src/wallpaper.rs @@ -28,6 +28,7 @@ pub fn set(config: &mut Config, entry: Entry) { entry.output.to_string(), entry.source.display() ); + if let Err(why) = config.set_entry(&context, entry) { tracing::error!(?why, "failed to set background"); }