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",
|
"async-channel",
|
||||||
"clap",
|
"clap",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
|
"cosmic-bg-config",
|
||||||
"cosmic-comp-config",
|
"cosmic-comp-config",
|
||||||
"cosmic-panel-config",
|
"cosmic-panel-config",
|
||||||
"cosmic-randr-shell",
|
"cosmic-randr-shell",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ rust-version = "1.65.0"
|
||||||
apply = "0.3.0"
|
apply = "0.3.0"
|
||||||
async-channel = "2.1.1"
|
async-channel = "2.1.1"
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
|
cosmic-bg-config = { workspace = true }
|
||||||
cosmic-randr-shell = { workspace = true }
|
cosmic-randr-shell = { workspace = true }
|
||||||
cosmic-settings-wallpaper = { path = "../pages/wallpapers" }
|
cosmic-settings-wallpaper = { path = "../pages/wallpapers" }
|
||||||
cosmic-settings-page = { path = "../page" }
|
cosmic-settings-page = { path = "../page" }
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
|
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
|
||||||
|
use cosmic_bg_config::Source;
|
||||||
use cosmic_settings_wallpaper as wallpaper;
|
use cosmic_settings_wallpaper as wallpaper;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
@ -16,6 +17,7 @@ const RECENT_FOLDERS: &str = "recent-folders";
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
context: Option<cosmic_config::Config>,
|
context: Option<cosmic_config::Config>,
|
||||||
|
state: Option<cosmic_config::Config>,
|
||||||
pub(super) current_folder: Option<PathBuf>,
|
pub(super) current_folder: Option<PathBuf>,
|
||||||
custom_colors: Vec<wallpaper::Color>,
|
custom_colors: Vec<wallpaper::Color>,
|
||||||
custom_images: Vec<PathBuf>,
|
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.
|
// Get the active background folder from cosmic-config.
|
||||||
if let Ok(path) = context.get::<Option<PathBuf>>(CURRENT_FOLDER) {
|
if let Ok(path) = context.get::<Option<PathBuf>>(CURRENT_FOLDER) {
|
||||||
// Set current folder if it exists.
|
// Set current folder if it exists.
|
||||||
|
|
@ -82,6 +93,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
config.context = Some(context);
|
config.context = Some(context);
|
||||||
|
config.state = Some(state);
|
||||||
|
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
@ -151,6 +163,24 @@ impl Config {
|
||||||
Ok(())
|
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]
|
#[must_use]
|
||||||
pub fn custom_images(&self) -> &[PathBuf] {
|
pub fn custom_images(&self) -> &[PathBuf] {
|
||||||
&self.custom_images
|
&self.custom_images
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ use cosmic::{
|
||||||
widget::{color_picker::ColorPickerUpdate, ColorPickerModel},
|
widget::{color_picker::ColorPickerUpdate, ColorPickerModel},
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
|
use cosmic_bg_config::Source;
|
||||||
use cosmic_settings_page::Section;
|
use cosmic_settings_page::Section;
|
||||||
use cosmic_settings_page::{self as page, section};
|
use cosmic_settings_page::{self as page, section};
|
||||||
use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode};
|
use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode};
|
||||||
|
|
@ -321,10 +322,13 @@ impl Page {
|
||||||
|
|
||||||
Choice::Slideshow => self
|
Choice::Slideshow => self
|
||||||
.config_output()
|
.config_output()
|
||||||
.and_then(|output| {
|
.and_then(|output| match self.config.current_image(output)? {
|
||||||
let path = wallpaper::current_image(output).ok()?;
|
Source::Path(path) => {
|
||||||
let id = self.wallpaper_id_from_path(&path)?;
|
let id = self.wallpaper_id_from_path(&path)?;
|
||||||
Some(&self.selection.display_images[id])
|
Some(&self.selection.display_images[id])
|
||||||
|
}
|
||||||
|
|
||||||
|
Source::Color(_color) => None,
|
||||||
})
|
})
|
||||||
.or(self.selection.display_images.values().next()),
|
.or(self.selection.display_images.values().next()),
|
||||||
|
|
||||||
|
|
@ -770,16 +774,20 @@ impl Page {
|
||||||
self.cache_display_image();
|
self.cache_display_image();
|
||||||
} else {
|
} else {
|
||||||
if let Some(output) = self.config_output() {
|
if let Some(output) = self.config_output() {
|
||||||
if let Ok(path) = wallpaper::current_image(output) {
|
match self.config.current_image(output) {
|
||||||
if let Some(entity) = self.wallpaper_id_from_path(&path) {
|
Some(Source::Path(path)) => {
|
||||||
if let Some(entry) =
|
if let Some(entity) = self.wallpaper_id_from_path(&path) {
|
||||||
self.config_wallpaper_entry(output.to_owned(), path)
|
if let Some(entry) =
|
||||||
{
|
self.config_wallpaper_entry(output.to_owned(), path)
|
||||||
self.select_wallpaper(&entry, entity, false);
|
{
|
||||||
self.config_apply();
|
self.select_wallpaper(&entry, entity, false);
|
||||||
return Command::none();
|
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))>) {
|
pub async fn config() -> (Config, HashMap<String, (String, (u32, u32))>) {
|
||||||
let mut displays = HashMap::new();
|
let mut displays = HashMap::new();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue