Fixed bug related to JS ordering causing wallpaper to select incorrect screen

This commit is contained in:
Benjamyn Love 2024-12-05 16:25:54 +11:00
parent 77824176f6
commit 8200a1f764
4 changed files with 34 additions and 7 deletions

View File

@ -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<MonitorType>,
pub monitors: Vec<Monitor>,
}
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::<i64>()
.expect("Failed to parse int in motitor config"),
));
}
}
//

View File

@ -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();

View File

@ -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
}

View File

@ -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);