From 19821ec68ebe7c83238150d21c342bd911475f20 Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Mon, 19 Feb 2024 17:54:41 +0100 Subject: [PATCH] finish xfce (untested) --- more-wallpapers/src/lib.rs | 2 ++ more-wallpapers/src/linux/mod.rs | 7 ++++++- more-wallpapers/src/linux/xfce.rs | 26 +++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/more-wallpapers/src/lib.rs b/more-wallpapers/src/lib.rs index be931d3..7d06332 100644 --- a/more-wallpapers/src/lib.rs +++ b/more-wallpapers/src/lib.rs @@ -197,6 +197,7 @@ pub enum Environment { #[cfg(feature = "fallback")] Windows, X11, + Xfce, } impl Environment { ///return true, if the current environment does support various wallpaper on each screen @@ -212,6 +213,7 @@ impl Environment { #[cfg(feature = "fallback")] Self::Windows => false, Self::X11 => true, + Self::Xfce => true, } } } diff --git a/more-wallpapers/src/linux/mod.rs b/more-wallpapers/src/linux/mod.rs index 9ae0615..f535d0a 100644 --- a/more-wallpapers/src/linux/mod.rs +++ b/more-wallpapers/src/linux/mod.rs @@ -26,12 +26,15 @@ fn get_environment() -> Result { if desktop.as_str() == "kde" { return Ok(Environment::Kde); } + if desktop.as_str() == "xfce" { + return Ok(Environment::Xfce); + } let sessinon_type = load_env_var("XDG_SESSION_TYPE")?.to_lowercase(); match sessinon_type.as_str() { "x11" => Ok(Environment::X11), #[cfg(feature = "fallback")] "wayland" => match desktop.as_str() { - "budgie:gnome" | "deepin" | "gnome" | "lxde" | "mate" | "xfce" => Ok(Environment::LinuxFallback), + "budgie:gnome" | "deepin" | "gnome" | "lxde" | "mate" => Ok(Environment::LinuxFallback), _ => Err(WallpaperError::Unsuported(format!("{desktop} ({sessinon_type})"))), }, _ => Err(WallpaperError::Unsuported(format!("{desktop} ({sessinon_type})"))), @@ -45,6 +48,7 @@ pub(crate) fn get_builder() -> Result { Environment::Kde => kde::get_screens()?, Environment::Sway => sway::get_screens()?, Environment::X11 => x11::get_screens()?, + Environment::Xfce => xfce::get_screens()?, #[cfg(feature = "fallback")] Environment::LinuxFallback => wallpaper_crate::get_screens(), #[cfg(feature = "fallback")] @@ -61,6 +65,7 @@ pub(crate) fn set_screens_from_builder(builder: WallpaperBuilder) -> Result<(), Environment::Kde => kde::set_screens(builder.screens)?, Environment::Sway => sway::set_screens(builder.screens)?, Environment::X11 => x11::set_screens(builder.screens)?, + Environment::Xfce => xfce::set_screens(builder.screens)?, #[cfg(feature = "fallback")] Environment::LinuxFallback => wallpaper_crate::set_screens(builder.screens)?, #[cfg(feature = "fallback")] diff --git a/more-wallpapers/src/linux/xfce.rs b/more-wallpapers/src/linux/xfce.rs index cb2dfcb..e952cec 100644 --- a/more-wallpapers/src/linux/xfce.rs +++ b/more-wallpapers/src/linux/xfce.rs @@ -1,6 +1,6 @@ use super::check_command_error; use crate::{error::CommandError, load_env_var, Environment, Mode, Screen, WallpaperBuilder, WallpaperError}; -use std::{collections::HashMap, process::Command}; +use std::{collections::HashMap, ffi::OsStr, process::Command}; fn load_property(property: &str) -> Result { let mut command = Command::new("xfconf-query"); @@ -76,3 +76,27 @@ pub(crate) fn get_screens() -> Result, WallpaperError> { } Ok(screens.into_values().collect()) } + +pub(crate) fn set_screens(screens: Vec) -> Result<(), WallpaperError> { + fn set_key>(key: String, property: P) -> Result<(), WallpaperError> { + let mut command = Command::new("xfconf-query"); + command.args(["--channel", "xfce4-desktop", "--set"]).arg(key).arg(property); + check_command_error(command.output(), "xfconf-query")?; + Ok(()) + } + + for screen in screens { + let key = format!("/backdrop/{}/last_image", screen.name); + set_key(key, &screen.wallpaper.unwrap())?; + let mode: u8 = match screen.mode.unwrap() { + Mode::Center => 1, + Mode::Tile => 2, + Mode::Stretch => 3, + Mode::Fit => 4, + Mode::Crop => 5, + }; + let key = format!("/backdrop/{}/image_style", screen.name); + set_key(key, format!("{mode}"))?; + } + Ok(()) +}