feat: add set as wallpaper functionality

Add ability to set current image as desktop wallpaper with keyboard
shortcut 'W' and icon button in Properties panel.

Supports COSMIC, GNOME, KDE, XFCE, and tiling window managers via
automatic detection and fallback mechanism.

Implementation uses wallpaper crate with custom COSMIC config file
integration and gsettings/feh fallbacks.
This commit is contained in:
wfx 2026-01-15 20:37:14 +01:00
parent ca7661fa3e
commit 220a886acc
12 changed files with 399 additions and 24 deletions

View file

@ -110,3 +110,35 @@ impl DocumentContent {
}
}
}
/// Set an image file as desktop wallpaper.
///
/// This function attempts multiple methods in order:
/// 1. COSMIC Desktop (direct config file modification)
/// 2. wallpaper crate (KDE, XFCE, Windows, macOS)
/// 3. gsettings (GNOME)
/// 4. feh (tiling window managers)
///
/// The operation is performed asynchronously and logs success/failure.
pub fn set_as_wallpaper(path: &Path) {
// Canonicalize to absolute path
let abs_path = match path.canonicalize() {
Ok(p) => p,
Err(e) => {
log::error!("Failed to canonicalize path {}: {}", path.display(), e);
return;
}
};
// Convert to string
let path_str = match abs_path.to_str() {
Some(s) => s.to_string(),
None => {
log::error!("Invalid UTF-8 in path: {}", abs_path.display());
return;
}
};
// Delegate to utils with concrete string type
utils::set_as_wallpaper(&path_str);
}