Skip to content

Commit

Permalink
feat: wallpaper changing + current wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Yag000 committed Aug 30, 2023
1 parent 8012854 commit d6b3b68
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod cli;
pub mod configuration;
pub mod wallpaper;
52 changes: 52 additions & 0 deletions src/wallpaper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::process::Command;

use crate::configuration::Settings;

/// Gets the current wallpaper. It assumes that the user is only using feh to set the wallpaper.
/// TODO: allow user to choose other wallpaper getter
///
///
/// The .fehbg file is a shell script that is run when the user logs in. It is used to set the
/// wallpaper. It uses the following format:
/// ```
/// #!/bin/sh
/// feh --no-fehbg --bg-fill /path/to/wallpaper
/// ```
/// This function parses the .fehbg file and returns the path to the current wallpaper.
///
/// # Panics
///
/// Panics if the file $HOME/.fehbg does not exist.
///
pub fn get_current_wallpaper() -> String {
let feh_raw = std::fs::read_to_string("~/.fehbg").expect("failed to open .fehbg file");

feh_raw
.lines()
.nth(1)
.expect("failed to parse .fehbg file, it should contain at least 2 lines")
.split(' ')
.last()
.expect(
"failed to parse .fehbg file, the last line should contain the path to the wallpaper",
)
.to_string()
}

pub fn update_wallpaper(settings: &Settings, path: &str) {
// TODO: allow user to choose other wallpaper setter
Command::new("feh")
.arg("--bg-fill")
.arg(path)
.output()
.expect("failed to call feh");

// Updates the betterlockscreen wallpaper
if settings.betterlockscreen {
Command::new("betterlockscreen")
.arg("-u")
.arg(path)
.output()
.expect("failed to call betterlockscreen");
}
}

0 comments on commit d6b3b68

Please sign in to comment.