diff --git a/Cargo.lock b/Cargo.lock index bf7038c..75dd62e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -569,7 +569,7 @@ dependencies = [ [[package]] name = "moongreet" -version = "0.5.0" +version = "0.5.2" dependencies = [ "gdk-pixbuf", "gdk4", diff --git a/Cargo.toml b/Cargo.toml index e305c7a..0dc0f79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "moongreet" -version = "0.5.1" +version = "0.5.2" edition = "2024" description = "A greetd greeter for Wayland with GTK4 and Layer Shell" license = "MIT" diff --git a/resources/resources.gresource.xml b/resources/resources.gresource.xml index cb938c4..46067e6 100644 --- a/resources/resources.gresource.xml +++ b/resources/resources.gresource.xml @@ -2,7 +2,6 @@ style.css - wallpaper.jpg default-avatar.svg diff --git a/resources/wallpaper.jpg b/resources/wallpaper.jpg deleted file mode 100644 index 86371cd..0000000 Binary files a/resources/wallpaper.jpg and /dev/null differ diff --git a/src/config.rs b/src/config.rs index 735000c..4bf6f18 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,6 @@ use std::fs; use std::path::{Path, PathBuf}; const MOONARCH_WALLPAPER: &str = "/usr/share/moonarch/wallpaper.jpg"; -const GRESOURCE_PREFIX: &str = "/dev/moonarch/moongreet"; /// Default config search path: system-wide config. fn default_config_paths() -> Vec { @@ -84,19 +83,19 @@ pub fn load_config(config_paths: Option<&[PathBuf]>) -> Config { /// Resolve the wallpaper path using the fallback hierarchy. /// -/// Priority: config background_path > Moonarch system default > gresource fallback. -pub fn resolve_background_path(config: &Config) -> PathBuf { +/// Priority: config background_path > Moonarch system default > None (GTK background color). +pub fn resolve_background_path(config: &Config) -> Option { resolve_background_path_with(config, Path::new(MOONARCH_WALLPAPER)) } /// Resolve with configurable moonarch wallpaper path (for testing). -pub fn resolve_background_path_with(config: &Config, moonarch_wallpaper: &Path) -> PathBuf { +pub fn resolve_background_path_with(config: &Config, moonarch_wallpaper: &Path) -> Option { // User-configured path if let Some(ref bg) = config.background_path { let path = PathBuf::from(bg); if path.is_file() { log::debug!("Wallpaper: using config path {}", path.display()); - return path; + return Some(path); } log::debug!("Wallpaper: config path {} not found, trying fallbacks", path.display()); } @@ -104,12 +103,11 @@ pub fn resolve_background_path_with(config: &Config, moonarch_wallpaper: &Path) // Moonarch ecosystem default if moonarch_wallpaper.is_file() { log::debug!("Wallpaper: using moonarch default {}", moonarch_wallpaper.display()); - return moonarch_wallpaper.to_path_buf(); + return Some(moonarch_wallpaper.to_path_buf()); } - // GResource fallback path (loaded from compiled resources at runtime) - log::debug!("Wallpaper: using GResource fallback"); - PathBuf::from(format!("{GRESOURCE_PREFIX}/wallpaper.jpg")) + log::debug!("Wallpaper: no wallpaper found, using GTK background color"); + None } #[cfg(test)] @@ -218,7 +216,7 @@ mod tests { }; assert_eq!( resolve_background_path_with(&config, Path::new("/nonexistent")), - wallpaper + Some(wallpaper) ); } @@ -229,7 +227,7 @@ mod tests { ..Config::default() }; let result = resolve_background_path_with(&config, Path::new("/nonexistent")); - assert!(result.to_str().unwrap().contains("moongreet")); + assert!(result.is_none()); } #[test] @@ -240,14 +238,14 @@ mod tests { let config = Config::default(); assert_eq!( resolve_background_path_with(&config, &moonarch_wp), - moonarch_wp + Some(moonarch_wp) ); } #[test] - fn resolve_uses_gresource_fallback_as_last_resort() { + fn resolve_returns_none_when_no_wallpaper_found() { let config = Config::default(); let result = resolve_background_path_with(&config, Path::new("/nonexistent")); - assert!(result.to_str().unwrap().contains("wallpaper.jpg")); + assert!(result.is_none()); } } diff --git a/src/greeter.rs b/src/greeter.rs index a3e8d6b..e4b35bf 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -95,42 +95,23 @@ fn is_valid_username(name: &str) -> bool { .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '.' || c == '-' || c == '@') } -/// Load background texture from GResource or filesystem. +/// Load background texture from filesystem. pub fn load_background_texture(bg_path: &Path) -> Option { - let path_str = bg_path.to_str()?; - if bg_path.starts_with("/dev/moonarch/moongreet") { - match gio::resources_lookup_data(path_str, gio::ResourceLookupFlags::NONE) { - Ok(bytes) => match gdk::Texture::from_bytes(&bytes) { - Ok(texture) => Some(texture), - Err(e) => { - log::debug!("GResource texture decode error: {e}"); - log::warn!("Failed to decode background texture from GResource {path_str}"); - None - } - }, - Err(e) => { - log::debug!("GResource lookup error: {e}"); - log::warn!("Failed to load background texture from GResource {path_str}"); - None - } - } - } else { - if let Ok(meta) = std::fs::metadata(bg_path) - && meta.len() > MAX_WALLPAPER_FILE_SIZE - { - log::warn!( - "Wallpaper file too large ({} bytes), skipping: {}", - meta.len(), bg_path.display() - ); - return None; - } - match gdk::Texture::from_filename(bg_path) { - Ok(texture) => Some(texture), - Err(e) => { - log::debug!("Wallpaper load error: {e}"); - log::warn!("Failed to load background texture from {}", bg_path.display()); - None - } + if let Ok(meta) = std::fs::metadata(bg_path) + && meta.len() > MAX_WALLPAPER_FILE_SIZE + { + log::warn!( + "Wallpaper file too large ({} bytes), skipping: {}", + meta.len(), bg_path.display() + ); + return None; + } + match gdk::Texture::from_filename(bg_path) { + Ok(texture) => Some(texture), + Err(e) => { + log::debug!("Wallpaper load error: {e}"); + log::warn!("Failed to load background texture from {}", bg_path.display()); + None } } } diff --git a/src/main.rs b/src/main.rs index 7ceb185..dc44f60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,15 +51,11 @@ fn activate(app: >k::Application) { // Load config and resolve wallpaper let config = config::load_config(None); - let bg_path = config::resolve_background_path(&config); - log::debug!("Background path: {}", bg_path.display()); - - // Load background texture once — shared across all windows - // Blur is applied on the GPU via GskBlurNode at widget realization time. - let bg_texture = greeter::load_background_texture(&bg_path); - if bg_texture.is_none() { - log::error!("Failed to load background texture — greeter will start without wallpaper"); - } + let bg_texture = config::resolve_background_path(&config) + .and_then(|path| { + log::debug!("Background path: {}", path.display()); + greeter::load_background_texture(&path) + }); let use_layer_shell = std::env::var("MOONGREET_NO_LAYER_SHELL").is_err(); log::debug!("Layer shell: {use_layer_shell}");