diff --git a/lib/background.rs b/lib/background.rs index 11749e9a3e9c7dc855a1938bc9991eaeb26df94f..7a973acf1d4df9a3f11c6817e0c98a0a7d28e305 100644 --- a/lib/background.rs +++ b/lib/background.rs @@ -41,7 +41,11 @@ pub fn process_image_url(image_url: String) -> MBGResult<()> { pub fn set_wallpaper(path: &str) { debug!("Setting background"); - let out = Command::new("feh").arg("--bg-fill").arg(path).output(); + let config = Config::get_props(); + let out = Command::new("sh") + .arg("-c") + .arg(config.set_command.replace(r"{}", path)) + .output(); if let Err(set_error) = out { error!("Can't set background: {}", set_error.to_string()); } diff --git a/lib/config/mod.rs b/lib/config/mod.rs index 97279bbf3f47556c2b39577a2dc99bcd47924ab7..92f185c27ba04494600b1a0dd75e3105ec26874a 100644 --- a/lib/config/mod.rs +++ b/lib/config/mod.rs @@ -12,6 +12,8 @@ pub mod logger; pub struct Config { #[serde(default)] pub blender: Vec<u8>, + #[serde(default = "set_command_default")] + pub set_command: String, #[serde(default = "reset_command_default")] pub reset_command: String, #[serde(default)] @@ -24,6 +26,10 @@ pub fn reset_command_default() -> String { String::from("nitrogen --restore") } +pub fn set_command_default() -> String { + String::from(r#"nitrogen --set-auto "{}""#) +} + impl Config { fn new() -> Self { Config { diff --git a/lib/img_processors/mod.rs b/lib/img_processors/mod.rs index 0cedda44fd780b8dd8b114649cb0cffc27db86b5..2ff7106518dbf1c6641dc3a86a62145baa9b088c 100644 --- a/lib/img_processors/mod.rs +++ b/lib/img_processors/mod.rs @@ -6,8 +6,8 @@ use crate::config::Config; use crate::display::get_max_resolution; use crate::result::MBGResult; use rayon::prelude::*; -use std::collections::HashMap; use std::collections::hash_map::RandomState; +use std::collections::HashMap; pub mod blur; pub mod border; @@ -86,20 +86,20 @@ pub fn process_image(img_bytes: Vec<u8>) -> MBGResult<DynamicImage> { let (screen_height, screen_width) = get_max_resolution()?; debug!("Maximum resolution: {}x{}", screen_width, screen_height); let image = image::load_from_memory(img_bytes.as_slice())?; - let layers_conf = - conf.processors - .iter() - .fold(HashMap::<usize, Vec<ProcessorParams>>::new(), |mut acc, x| { - let new_processors = if let Some(current) = acc.get(&x.layer) { - let mut mutable = current.clone(); - mutable.push(x.clone()); - mutable - } else { - vec![x.clone()] - }; - acc.insert(x.layer, new_processors); - acc - }); + let layers_conf = conf.processors.iter().fold( + HashMap::<usize, Vec<ProcessorParams>>::new(), + |mut acc, x| { + let new_processors = if let Some(current) = acc.get(&x.layer) { + let mut mutable = current.clone(); + mutable.push(x.clone()); + mutable + } else { + vec![x.clone()] + }; + acc.insert(x.layer, new_processors); + acc + }, + ); let processed_layers = layers_conf .par_iter() .map(|(layer, processors)| { diff --git a/lib/result.rs b/lib/result.rs index d18543aa4ba4898ebe74d1421fe7f332da271078..25af0a9b85f1671ab06879eb482ea890bde5ed1c 100644 --- a/lib/result.rs +++ b/lib/result.rs @@ -54,4 +54,4 @@ impl From<image::error::ImageError> for MBGError { fn from(err: image::error::ImageError) -> Self { MBGError::ImageError(err.to_string()) } -} \ No newline at end of file +}