Merge branch 'master' into wallhaven

This commit is contained in:
Benjamyn Love 2024-12-05 16:27:17 +11:00
commit 812d3f9d0c
3 changed files with 33 additions and 7 deletions

View File

@ -4,14 +4,35 @@ use core::fmt;
use crate::enums::*; use crate::enums::*;
use untildify; 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)] #[derive(Debug, Clone)]
pub struct Monitors { pub struct Monitors {
pub monitors: Vec<MonitorType>, pub monitors: Vec<Monitor>,
} }
impl Monitors { impl Monitors {
fn add(&mut self, mon_type: MonitorType) { fn add(&mut self, monitor: Monitor) {
self.monitors.push(mon_type); self.monitors.push(monitor);
} }
} }
@ -99,7 +120,11 @@ impl Config {
for key in mon.keys() { for key in mon.keys() {
let monitor = mon.get(key).unwrap().as_ref().unwrap(); let monitor = mon.get(key).unwrap().as_ref().unwrap();
// Add monitor type to Monitors vector // 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"); command.arg("--no-fehbg").arg("--bg-fill");
for monitor in wallpapers.config.monitors.monitors.iter() { 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(); 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}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General');
allDesktops[{0}].writeConfig('Image', 'file://{1}'); allDesktops[{0}].writeConfig('Image', 'file://{1}');
", ",
count, monitor.index,
wallpapers.random_selection(monitor) wallpapers.random_selection(&monitor.ratio)
); );
javascript.push_str(&boilerplate); javascript.push_str(&boilerplate);
} }
println!("{}", javascript);
javascript javascript
} }