add excludes to randomwallpaper

This commit is contained in:
LordMZTE 2022-03-25 11:48:35 +01:00
parent 1ae7ea66ed
commit a2dbcf89fa
2 changed files with 33 additions and 14 deletions

View file

@ -0,0 +1,22 @@
use anyhow::Context;
use std::path::Path;
use std::path::PathBuf;
pub struct Config {
pub paths: Vec<PathBuf>,
pub exclude: Vec<PathBuf>,
}
impl Config {
pub fn new() -> anyhow::Result<Self> {
Ok(Self {
paths: vec![
PathBuf::from("/usr/share/backgrounds"),
Path::new(&std::env::var("HOME").context("couldn't get home directory")?)
.join(".local/share/backgrounds"),
],
exclude: vec![PathBuf::from("/usr/share/backgrounds/xfce")],
})
}
}

View file

@ -1,30 +1,27 @@
use anyhow::Context;
use config::Config;
use rand::prelude::{IteratorRandom, SliceRandom};
use std::{
path::{Path, PathBuf},
process::Command,
};
use std::{path::Path, process::Command};
use walkdir::{DirEntry, WalkDir};
use xinerama::head_count;
mod config;
mod xinerama;
fn main() -> anyhow::Result<()> {
let paths = [
PathBuf::from("/usr/share/backgrounds"),
Path::new(&std::env::var("HOME").context("couldn't get home directory")?)
.join(".local/share/backgrounds"),
];
let config = Config::new()?;
let wallpapers = paths
let wallpapers = config
.paths
.into_iter()
.flat_map(dir_iter)
.flatten()
.filter(|d| {
d.path()
.extension()
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
.unwrap_or(false)
!config.exclude.iter().any(|e| d.path().starts_with(e))
&& d.path()
.extension()
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
.unwrap_or(false)
})
.map(DirEntry::into_path);