refactor: remove embedded wallpaper from binary (v0.5.2)
Wallpaper is installed by moonarch to /usr/share/moonarch/wallpaper.jpg. Embedding a 374K JPEG in the binary was redundant. Without a wallpaper file, GTK background color (Catppuccin Mocha base) shows through and wallpaper-only windows on secondary monitors are skipped.
This commit is contained in:
parent
9a89da8b13
commit
b06b02faac
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -569,7 +569,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "moongreet"
|
||||
version = "0.5.0"
|
||||
version = "0.5.2"
|
||||
dependencies = [
|
||||
"gdk-pixbuf",
|
||||
"gdk4",
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
<gresources>
|
||||
<gresource prefix="/dev/moonarch/moongreet">
|
||||
<file>style.css</file>
|
||||
<file>wallpaper.jpg</file>
|
||||
<file>default-avatar.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 366 KiB |
@ -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<PathBuf> {
|
||||
@ -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<PathBuf> {
|
||||
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<PathBuf> {
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<gdk::Texture> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main.rs
14
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}");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user