Skip to content

Commit

Permalink
finish xfce (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyTurtleDev committed Feb 19, 2024
1 parent f440ac3 commit 19821ec
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions more-wallpapers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -212,6 +213,7 @@ impl Environment {
#[cfg(feature = "fallback")]
Self::Windows => false,
Self::X11 => true,
Self::Xfce => true,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion more-wallpapers/src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ fn get_environment() -> Result<Environment, WallpaperError> {
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})"))),
Expand All @@ -45,6 +48,7 @@ pub(crate) fn get_builder() -> Result<WallpaperBuilder, WallpaperError> {
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")]
Expand All @@ -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")]
Expand Down
26 changes: 25 additions & 1 deletion more-wallpapers/src/linux/xfce.rs
Original file line number Diff line number Diff line change
@@ -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<String, WallpaperError> {
let mut command = Command::new("xfconf-query");
Expand Down Expand Up @@ -76,3 +76,27 @@ pub(crate) fn get_screens() -> Result<Vec<Screen>, WallpaperError> {
}
Ok(screens.into_values().collect())
}

pub(crate) fn set_screens(screens: Vec<Screen>) -> Result<(), WallpaperError> {
fn set_key<P: AsRef<OsStr>>(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(())
}

0 comments on commit 19821ec

Please sign in to comment.