Skip to content

Commit

Permalink
finish xfce read
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyTurtleDev committed Feb 15, 2024
1 parent 855d222 commit 5a6b313
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 26 deletions.
4 changes: 4 additions & 0 deletions more-wallpapers/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ pub enum WallpaperError {

#[error("{0:?} {1}")]
IOError(String, io::Error),

#[cfg(target_os = "linux")]
#[error("Unknow XFCE wallpaper mode {0:?}")]
UnknownMode(String),
}

pub(crate) trait Context<V> {
Expand Down
89 changes: 63 additions & 26 deletions more-wallpapers/src/linux/xfce.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,78 @@
use crate::{error::CommandError, load_env_var, Environment, WallpaperBuilder, WallpaperError};
use crate::Screen;
use super::check_command_error;
use std::process::Command;
use crate::{error::CommandError, load_env_var, Environment, Mode, Screen, WallpaperBuilder, WallpaperError};
use std::{collections::HashMap, process::Command};

fn load_property(property: &str) -> Result<String, WallpaperError> {
fn load_property(property: &str) -> Result<String, WallpaperError> {
let mut command = Command::new("xfconf-query");
command.args(["--channel", "xfce4-desktop", "p"]);
command.arg(property);
let output = check_command_error(command.output(), "xfconf-query")?;
let output = String::from_utf8(output).unwrap();
Ok(output)
command.args(["--channel", "xfce4-desktop", "p"]);
command.arg(property);
let output = check_command_error(command.output(), "xfconf-query")?;
let output = String::from_utf8(output).unwrap();
Ok(output)
}


pub(crate) fn get_screens() -> Result<Vec<Screen>, WallpaperError> {
let mut command = Command::new("xfconf-query");
command.args(["--channel", "xfce4-desktop", "--list"]);
let output = check_command_error(command.output(), "xfconf-query")?;
let output = String::from_utf8(output).unwrap();
let mut current_screen_wallpaper = None;
let mut current_screen_mode = None;
for line in output.lines() {
if line.starts_with("/backdrop/") {
// the outpult looks like the following:
//
// /backdrop/screen0/monitor0/image-style
// /backdrop/screen0/monitor0/last-image
// /backdrop/screen0/monitor0/last-single-image
// /backdrop/screen0/monitorVirtual-1/workspace0/color-style
// /backdrop/screen0/monitorVirtual-1/workspace0/image-style
// /backdrop/screen0/monitorVirtual-1/workspace0/last-image
// /backdrop/screen0/monitorVirtual-1/workspace1/color-style
// /backdrop/screen0/monitorVirtual-1/workspace1/image-style
// /backdrop/screen0/monitorVirtual-1/workspace1/last-image
let mut screens: HashMap<String, Screen> = Default::default();
for line in output.lines().filter_map(|s| s.strip_prefix("/backdrop/")) {
let mut split = line.split('/');
let first = split.next();
let second = split.next();
let third = split.next();
if split.next().is_some() {
//to long -> wrong key
break;
}
if line.ends_with("/image-style"){
let value = load_property(line)?;
current_screen_mode.is_some panic
current_screen_mode = Some(("screenname_TODO".to_owned(), value));

let (Some(first), Some(second)) = (first, second) else {
//to short -> wrong key
break;
};
let (screen_name, key_type, active) = if let Some(third) = third {
// if name exist out of two part, the screen is active.
// Otherwise it is default for new workspaces
(format!("{}/{}", first, second), third, true)
} else {
(first.to_owned(), second, false)
};
if !(key_type == "last_image" || key_type == "image_style") {
// wrong key
break;
}
if line.ends_with("/last-image"){
let value = load_property(line)?;
current_screen_mode.unwrap() = "screenname_TODO";
current_screen_wallpaper.is_some panic
current_screen_wallpaper = Some(("screenname_TODO".to_owned(), value));
let value = load_property(line)?;
let screen = screens.entry(screen_name.clone()).or_insert_with(|| Screen {
name: screen_name,
wallpaper: None,
mode: None,
active,
});
if key_type == "last_image" {
screen.wallpaper = Some(value.into());
} else {
let mode = match value.as_str() {
"0" => None, //single color background is used instead of a image
"1" => Some(Mode::Center),
"2" => Some(Mode::Tile),
"3" => Some(Mode::Stretch),
"4" => Some(Mode::Fit),
"5" => Some(Mode::Crop),
_ => return Err(WallpaperError::UnknownMode(value)),
};
screen.mode = mode;
}
}
todo!()
}
Ok(screens.into_values().collect())
}

0 comments on commit 5a6b313

Please sign in to comment.