From 8200a1f76468074ce6e93619d5c54b6641c2565b Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Thu, 5 Dec 2024 16:25:54 +1100 Subject: [PATCH] Fixed bug related to JS ordering causing wallpaper to select incorrect screen --- src/config.rs | 33 +++++++++++++++++++++++++++++---- src/handlers/feh.rs | 2 +- src/handlers/plasma.rs | 5 +++-- src/main.rs | 1 + 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index a2fc3da..605442d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,14 +4,35 @@ use core::fmt; use crate::enums::*; use untildify; +#[derive(Debug, Clone)] +pub struct Monitor { + pub ratio: MonitorType, + pub index: i64, +} + +impl Monitor { + pub fn new(monitor_type: MonitorType, index: i64) -> Monitor { + Monitor { + ratio: monitor_type, + index: index, + } + } +} + +impl fmt::Display for Monitor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + #[derive(Debug, Clone)] pub struct Monitors { - pub monitors: Vec, + pub monitors: Vec, } impl Monitors { - fn add(&mut self, mon_type: MonitorType) { - self.monitors.push(mon_type); + fn add(&mut self, monitor: Monitor) { + self.monitors.push(monitor); } } @@ -97,7 +118,11 @@ impl Config { for key in mon.keys() { let monitor = mon.get(key).unwrap().as_ref().unwrap(); // Add monitor type to Monitors vector - monitors.add(MonitorType::new(monitor.to_string())); + monitors.add(Monitor::new( + MonitorType::new(monitor.to_string()), + key.parse::() + .expect("Failed to parse int in motitor config"), + )); } } // diff --git a/src/handlers/feh.rs b/src/handlers/feh.rs index 9ede4d2..1e84dc9 100644 --- a/src/handlers/feh.rs +++ b/src/handlers/feh.rs @@ -7,7 +7,7 @@ pub fn change_wallpapers(wallpapers: &Wallpapers) { command.arg("--no-fehbg").arg("--bg-fill"); for monitor in wallpapers.config.monitors.monitors.iter() { - command.arg(wallpapers.random_selection(monitor).to_string()); + command.arg(wallpapers.random_selection(&monitor.ratio).to_string()); } let result = command.output(); diff --git a/src/handlers/plasma.rs b/src/handlers/plasma.rs index 362a25f..3edc322 100644 --- a/src/handlers/plasma.rs +++ b/src/handlers/plasma.rs @@ -39,10 +39,11 @@ pub fn generate_js(wallpapers: &Wallpapers) -> String { allDesktops[{0}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General'); allDesktops[{0}].writeConfig('Image', 'file://{1}'); ", - count, - wallpapers.random_selection(monitor) + monitor.index, + wallpapers.random_selection(&monitor.ratio) ); javascript.push_str(&boilerplate); } + println!("{}", javascript); javascript } diff --git a/src/main.rs b/src/main.rs index 75e8ce5..891c566 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ fn main() { // Check the configured Wallpaper engine and run the change_wallpapers() method from the respective handlers let wallpaper_engine = config.wallpaper_engine; + // println!("{:?}", &wallpapers); match wallpaper_engine { WallpaperHandler::Plasma => { handlers::plasma::change_wallpapers(&wallpapers);