Skip to content

Commit

Permalink
Detect Cinnamon Desktop (Linux)
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Meyer <meyer.thibault@gmail.com>
  • Loading branch information
thibaultmeyer committed May 18, 2024
1 parent 86c2794 commit 0ab7ad1
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/bingwallpaper/bingwallpaperchanger.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0ab7ad1

Please sign in to comment.