Skip to content

Commit

Permalink
Restart swww-deamon after every wallpaper set.
Browse files Browse the repository at this point in the history
Temporary solution until LGFae/swww#326 is resolved.
  • Loading branch information
xDMPx committed Aug 8, 2024
1 parent 2baa4f3 commit 2e231dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
33 changes: 24 additions & 9 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub fn init() {
pub fn set_wallpaper(wallpaper: &std::path::Path) -> Result<(), std::io::Error> {
if is_running_under_wayland() {
set_wallpaper_wayland(wallpaper)?;
std::thread::sleep(std::time::Duration::from_secs(10));
kill_swww_daemon()?;
swww_daemon_init()?;
} else {
set_wallpaper_x11(wallpaper)?;
}
Expand Down Expand Up @@ -44,6 +47,12 @@ pub fn kill() -> Result<(), std::io::Error> {
));
}

kill_swww_daemon()?;

Ok(())
}

fn kill_swww_daemon() -> Result<(), std::io::Error> {
let output = std::process::Command::new("pkill")
.arg("-o")
.arg("swww-daemon")
Expand All @@ -67,16 +76,22 @@ fn swww_init() -> Result<(), std::io::Error> {
.output()?;

if !output.status.success() {
std::process::Command::new("swww-daemon")
.spawn()
.map(|mut child| {
child
.try_wait()
.map_err(|child_error| eprintln!("{:?}", child_error))
.ok()
})?;
swww_daemon_init()?;
}
std::thread::sleep(std::time::Duration::from_secs(1));

Ok(())
}

fn swww_daemon_init() -> Result<(), std::io::Error> {
std::process::Command::new("swww-daemon")
.spawn()
.map(|mut child| {
child
.try_wait()
.map_err(|child_error| eprintln!("{:?}", child_error))
.ok()
})?;
std::thread::sleep(std::time::Duration::from_secs(2));

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::os::windows::ffi::OsStrExt;

pub fn init() {}

pub fn set_wallpaper(wallpaper: &std::path::Path) {
set_wallpaper_windows(wallpaper);
pub fn set_wallpaper(wallpaper: &std::path::Path) -> Result<(), std::io::Error> {
set_wallpaper_windows(wallpaper)
}

pub fn is_running() -> bool {
Expand Down

0 comments on commit 2e231dd

Please sign in to comment.