fix(wallpaper): get current slideshow image from cosmic-bg state
This commit is contained in:
parent
1b4bfb619b
commit
39d0c6f7cf
5 changed files with 52 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1142,6 +1142,7 @@ dependencies = [
|
|||
"async-channel",
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"cosmic-bg-config",
|
||||
"cosmic-comp-config",
|
||||
"cosmic-panel-config",
|
||||
"cosmic-randr-shell",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ rust-version = "1.65.0"
|
|||
apply = "0.3.0"
|
||||
async-channel = "2.1.1"
|
||||
color-eyre = "0.6.2"
|
||||
cosmic-bg-config = { workspace = true }
|
||||
cosmic-randr-shell = { workspace = true }
|
||||
cosmic-settings-wallpaper = { path = "../pages/wallpapers" }
|
||||
cosmic-settings-page = { path = "../page" }
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
|
||||
use cosmic_bg_config::Source;
|
||||
use cosmic_settings_wallpaper as wallpaper;
|
||||
use std::collections::VecDeque;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
|
@ -16,6 +17,7 @@ const RECENT_FOLDERS: &str = "recent-folders";
|
|||
#[derive(Debug, Default)]
|
||||
pub struct Config {
|
||||
context: Option<cosmic_config::Config>,
|
||||
state: Option<cosmic_config::Config>,
|
||||
pub(super) current_folder: Option<PathBuf>,
|
||||
custom_colors: Vec<wallpaper::Color>,
|
||||
custom_images: Vec<PathBuf>,
|
||||
|
|
@ -34,6 +36,15 @@ impl Config {
|
|||
}
|
||||
};
|
||||
|
||||
let state = match cosmic_config::Config::new_state("com.system76.CosmicBackground", VERSION)
|
||||
{
|
||||
Ok(state) => state,
|
||||
Err(why) => {
|
||||
tracing::warn!(?why, "failed to get state");
|
||||
return Self::default();
|
||||
}
|
||||
};
|
||||
|
||||
// Get the active background folder from cosmic-config.
|
||||
if let Ok(path) = context.get::<Option<PathBuf>>(CURRENT_FOLDER) {
|
||||
// Set current folder if it exists.
|
||||
|
|
@ -82,6 +93,7 @@ impl Config {
|
|||
}
|
||||
|
||||
config.context = Some(context);
|
||||
config.state = Some(state);
|
||||
|
||||
config
|
||||
}
|
||||
|
|
@ -151,6 +163,24 @@ impl Config {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn current_image(&self, output: &str) -> Option<Source> {
|
||||
let mut wallpapers = self
|
||||
.state
|
||||
.as_ref()?
|
||||
.get::<Vec<(String, Source)>>("wallpapers")
|
||||
.ok()?
|
||||
.into_iter();
|
||||
|
||||
let wallpaper = if output == "all" {
|
||||
wallpapers.next()
|
||||
} else {
|
||||
wallpapers.find(|(name, _path)| name == output)
|
||||
};
|
||||
|
||||
wallpaper.map(|(_name, path)| path)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn custom_images(&self) -> &[PathBuf] {
|
||||
&self.custom_images
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ use cosmic::{
|
|||
widget::{color_picker::ColorPickerUpdate, ColorPickerModel},
|
||||
Element,
|
||||
};
|
||||
use cosmic_bg_config::Source;
|
||||
use cosmic_settings_page::Section;
|
||||
use cosmic_settings_page::{self as page, section};
|
||||
use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode};
|
||||
|
|
@ -321,10 +322,13 @@ impl Page {
|
|||
|
||||
Choice::Slideshow => self
|
||||
.config_output()
|
||||
.and_then(|output| {
|
||||
let path = wallpaper::current_image(output).ok()?;
|
||||
let id = self.wallpaper_id_from_path(&path)?;
|
||||
Some(&self.selection.display_images[id])
|
||||
.and_then(|output| match self.config.current_image(output)? {
|
||||
Source::Path(path) => {
|
||||
let id = self.wallpaper_id_from_path(&path)?;
|
||||
Some(&self.selection.display_images[id])
|
||||
}
|
||||
|
||||
Source::Color(_color) => None,
|
||||
})
|
||||
.or(self.selection.display_images.values().next()),
|
||||
|
||||
|
|
@ -770,16 +774,20 @@ impl Page {
|
|||
self.cache_display_image();
|
||||
} else {
|
||||
if let Some(output) = self.config_output() {
|
||||
if let Ok(path) = wallpaper::current_image(output) {
|
||||
if let Some(entity) = self.wallpaper_id_from_path(&path) {
|
||||
if let Some(entry) =
|
||||
self.config_wallpaper_entry(output.to_owned(), path)
|
||||
{
|
||||
self.select_wallpaper(&entry, entity, false);
|
||||
self.config_apply();
|
||||
return Command::none();
|
||||
match self.config.current_image(output) {
|
||||
Some(Source::Path(path)) => {
|
||||
if let Some(entity) = self.wallpaper_id_from_path(&path) {
|
||||
if let Some(entry) =
|
||||
self.config_wallpaper_entry(output.to_owned(), path)
|
||||
{
|
||||
self.select_wallpaper(&entry, entity, false);
|
||||
self.config_apply();
|
||||
return Command::none();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@ pub const DEFAULT_COLORS: &[Color] = &[
|
|||
}),
|
||||
];
|
||||
|
||||
pub fn current_image(output: &str) -> Result<PathBuf, cosmic_config::Error> {
|
||||
cosmic_bg_config::context()?.current_image(output)
|
||||
}
|
||||
|
||||
pub async fn config() -> (Config, HashMap<String, (String, (u32, u32))>) {
|
||||
let mut displays = HashMap::new();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue