feat: get active wallpaper and show it in display_container widget
This commit is contained in:
parent
a4eee2186c
commit
a3802021b6
5 changed files with 62 additions and 24 deletions
|
|
@ -8,15 +8,13 @@
|
||||||
|
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub use app::{Message, SettingsApp};
|
pub use app::{Message, SettingsApp};
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod localize;
|
pub mod localize;
|
||||||
|
|
||||||
pub mod widget;
|
|
||||||
|
|
||||||
pub mod pages;
|
pub mod pages;
|
||||||
|
pub mod theme;
|
||||||
|
pub mod widget;
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{wayland::actions::window::SctkWindowSettings, Application, Limits},
|
iced::{wayland::actions::window::SctkWindowSettings, Application, Limits},
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use cosmic::{
|
||||||
iced::widget::{column, container, horizontal_space, row, text},
|
iced::widget::{column, container, horizontal_space, row, text},
|
||||||
iced::Length,
|
iced::Length,
|
||||||
iced_runtime::core::image::Handle as ImageHandle,
|
iced_runtime::core::image::Handle as ImageHandle,
|
||||||
|
iced_widget::core::renderer::BorderRadius,
|
||||||
theme,
|
theme,
|
||||||
widget::{list_column, settings, toggler},
|
widget::{list_column, settings, toggler},
|
||||||
Element,
|
Element,
|
||||||
|
|
@ -57,7 +58,7 @@ impl Page {
|
||||||
Message::SameBackground(value) => self.same_background = value,
|
Message::SameBackground(value) => self.same_background = value,
|
||||||
Message::Select(id) => {
|
Message::Select(id) => {
|
||||||
if let Some(path) = self.selection.paths.get(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;
|
self.selection.active = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,6 +66,20 @@ impl Page {
|
||||||
Message::Update((config, selection)) => {
|
Message::Update((config, selection)) => {
|
||||||
self.config = config;
|
self.config = config;
|
||||||
self.selection = selection;
|
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<crate::pages::Message> for Page {
|
||||||
Some(Box::pin(async move {
|
Some(Box::pin(async move {
|
||||||
let config = wallpaper::config();
|
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 mut update = Context::default();
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
@ -142,19 +159,7 @@ pub fn settings() -> Section<crate::pages::Message> {
|
||||||
let mut children = Vec::with_capacity(3);
|
let mut children = Vec::with_capacity(3);
|
||||||
|
|
||||||
if let Some(image) = page.selection.handles.get(page.selection.active) {
|
if let Some(image) = page.selection.handles.get(page.selection.active) {
|
||||||
let display_preview = row!(
|
children.push(crate::widget::display_container(image.clone(), 300.0));
|
||||||
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(
|
children.push(
|
||||||
|
|
|
||||||
15
app/src/theme.rs
Normal file
15
app/src/theme.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
|
// 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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -2,12 +2,15 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use apply::Apply;
|
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::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::{theme, Element};
|
||||||
use cosmic_settings_page as page;
|
use cosmic_settings_page as page;
|
||||||
|
|
||||||
|
|
@ -131,3 +134,19 @@ pub fn unimplemented_page<Message: 'static>() -> Element<'static, Message> {
|
||||||
.add(text("We haven't created that panel yet, and/or it is using a similar idea as current Pop! designs."))
|
.add(text("We haven't created that panel yet, and/or it is using a similar idea as current Pop! designs."))
|
||||||
.into()
|
.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()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ pub fn set(config: &mut Config, entry: Entry) {
|
||||||
entry.output.to_string(),
|
entry.output.to_string(),
|
||||||
entry.source.display()
|
entry.source.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(why) = config.set_entry(&context, entry) {
|
if let Err(why) = config.set_entry(&context, entry) {
|
||||||
tracing::error!(?why, "failed to set background");
|
tracing::error!(?why, "failed to set background");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue