From 0ab7ad1fe9ec4dec05bebc3aba0b6035d3460e29 Mon Sep 17 00:00:00 2001 From: Thibault Meyer Date: Fri, 17 May 2024 22:24:35 +0200 Subject: [PATCH] Detect Cinnamon Desktop (Linux) Signed-off-by: Thibault Meyer --- src/bingwallpaper/bingwallpaperchanger.rs | 49 +++++++++++++++-------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/bingwallpaper/bingwallpaperchanger.rs b/src/bingwallpaper/bingwallpaperchanger.rs index 24a74e3..11aca3c 100644 --- a/src/bingwallpaper/bingwallpaperchanger.rs +++ b/src/bingwallpaper/bingwallpaperchanger.rs @@ -1,3 +1,5 @@ +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] +use std::env; #[cfg(target_os = "windows")] use std::ffi::CString; #[cfg(target_os = "macos")] @@ -186,23 +188,38 @@ impl BingWallpaperChanger { /// Changes the wallpaper with the given picture on Linux. #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] fn change_wallpaper_linux(&self) { - let mut child = Command::new("gsettings") - .arg("set") - .arg("org.gnome.desktop.background") - .arg("picture-uri") - .arg(&self.configuration.target_filename) - .spawn() - .expect("Can't change wallpaper"); - child.wait().expect("Can't wait for child process"); + let session = env::var("DESKTOP_SESSION").unwrap(); + + if session.eq("cinnamon") { + // Cinnamon + let mut child = Command::new("gsettings") + .arg("set") + .arg("org.cinnamon.desktop.background") + .arg("picture-uri") + .arg(format!("file://{}", &self.configuration.target_filename)) + .spawn() + .expect("Can't change wallpaper"); + child.wait().expect("Can't wait for child process"); + } else { + // Gnome + let mut child = Command::new("gsettings") + .arg("set") + .arg("org.gnome.desktop.background") + .arg("picture-uri") + .arg(&self.configuration.target_filename) + .spawn() + .expect("Can't change wallpaper"); + child.wait().expect("Can't wait for child process"); - let mut child = Command::new("gsettings") - .arg("set") - .arg("org.gnome.desktop.background") - .arg("picture-uri-dark") - .arg(&self.configuration.target_filename) - .spawn() - .expect("Can't change wallpaper"); - child.wait().expect("Can't wait for child process"); + let mut child = Command::new("gsettings") + .arg("set") + .arg("org.gnome.desktop.background") + .arg("picture-uri-dark") + .arg(&self.configuration.target_filename) + .spawn() + .expect("Can't change wallpaper"); + child.wait().expect("Can't wait for child process"); + }; } /// Changes the wallpaper with the given picture on MacOS.