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]]
|
[[package]]
|
||||||
name = "moongreet"
|
name = "moongreet"
|
||||||
version = "0.5.0"
|
version = "0.5.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gdk-pixbuf",
|
"gdk-pixbuf",
|
||||||
"gdk4",
|
"gdk4",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "moongreet"
|
name = "moongreet"
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "A greetd greeter for Wayland with GTK4 and Layer Shell"
|
description = "A greetd greeter for Wayland with GTK4 and Layer Shell"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/dev/moonarch/moongreet">
|
<gresource prefix="/dev/moonarch/moongreet">
|
||||||
<file>style.css</file>
|
<file>style.css</file>
|
||||||
<file>wallpaper.jpg</file>
|
|
||||||
<file>default-avatar.svg</file>
|
<file>default-avatar.svg</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 366 KiB |
@ -6,7 +6,6 @@ use std::fs;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
const MOONARCH_WALLPAPER: &str = "/usr/share/moonarch/wallpaper.jpg";
|
const MOONARCH_WALLPAPER: &str = "/usr/share/moonarch/wallpaper.jpg";
|
||||||
const GRESOURCE_PREFIX: &str = "/dev/moonarch/moongreet";
|
|
||||||
|
|
||||||
/// Default config search path: system-wide config.
|
/// Default config search path: system-wide config.
|
||||||
fn default_config_paths() -> Vec<PathBuf> {
|
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.
|
/// Resolve the wallpaper path using the fallback hierarchy.
|
||||||
///
|
///
|
||||||
/// Priority: config background_path > Moonarch system default > gresource fallback.
|
/// Priority: config background_path > Moonarch system default > None (GTK background color).
|
||||||
pub fn resolve_background_path(config: &Config) -> PathBuf {
|
pub fn resolve_background_path(config: &Config) -> Option<PathBuf> {
|
||||||
resolve_background_path_with(config, Path::new(MOONARCH_WALLPAPER))
|
resolve_background_path_with(config, Path::new(MOONARCH_WALLPAPER))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve with configurable moonarch wallpaper path (for testing).
|
/// 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
|
// User-configured path
|
||||||
if let Some(ref bg) = config.background_path {
|
if let Some(ref bg) = config.background_path {
|
||||||
let path = PathBuf::from(bg);
|
let path = PathBuf::from(bg);
|
||||||
if path.is_file() {
|
if path.is_file() {
|
||||||
log::debug!("Wallpaper: using config path {}", path.display());
|
log::debug!("Wallpaper: using config path {}", path.display());
|
||||||
return path;
|
return Some(path);
|
||||||
}
|
}
|
||||||
log::debug!("Wallpaper: config path {} not found, trying fallbacks", path.display());
|
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
|
// Moonarch ecosystem default
|
||||||
if moonarch_wallpaper.is_file() {
|
if moonarch_wallpaper.is_file() {
|
||||||
log::debug!("Wallpaper: using moonarch default {}", moonarch_wallpaper.display());
|
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: no wallpaper found, using GTK background color");
|
||||||
log::debug!("Wallpaper: using GResource fallback");
|
None
|
||||||
PathBuf::from(format!("{GRESOURCE_PREFIX}/wallpaper.jpg"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -218,7 +216,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_background_path_with(&config, Path::new("/nonexistent")),
|
resolve_background_path_with(&config, Path::new("/nonexistent")),
|
||||||
wallpaper
|
Some(wallpaper)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +227,7 @@ mod tests {
|
|||||||
..Config::default()
|
..Config::default()
|
||||||
};
|
};
|
||||||
let result = resolve_background_path_with(&config, Path::new("/nonexistent"));
|
let result = resolve_background_path_with(&config, Path::new("/nonexistent"));
|
||||||
assert!(result.to_str().unwrap().contains("moongreet"));
|
assert!(result.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -240,14 +238,14 @@ mod tests {
|
|||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resolve_background_path_with(&config, &moonarch_wp),
|
resolve_background_path_with(&config, &moonarch_wp),
|
||||||
moonarch_wp
|
Some(moonarch_wp)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_uses_gresource_fallback_as_last_resort() {
|
fn resolve_returns_none_when_no_wallpaper_found() {
|
||||||
let config = Config::default();
|
let config = Config::default();
|
||||||
let result = resolve_background_path_with(&config, Path::new("/nonexistent"));
|
let result = resolve_background_path_with(&config, Path::new("/nonexistent"));
|
||||||
assert!(result.to_str().unwrap().contains("wallpaper.jpg"));
|
assert!(result.is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,26 +95,8 @@ fn is_valid_username(name: &str) -> bool {
|
|||||||
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '.' || c == '-' || c == '@')
|
.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> {
|
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)
|
if let Ok(meta) = std::fs::metadata(bg_path)
|
||||||
&& meta.len() > MAX_WALLPAPER_FILE_SIZE
|
&& meta.len() > MAX_WALLPAPER_FILE_SIZE
|
||||||
{
|
{
|
||||||
@ -132,7 +114,6 @@ pub fn load_background_texture(bg_path: &Path) -> Option<gdk::Texture> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- GPU blur via GskBlurNode -------------------------------------------------
|
// -- GPU blur via GskBlurNode -------------------------------------------------
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@ -51,15 +51,11 @@ fn activate(app: >k::Application) {
|
|||||||
|
|
||||||
// Load config and resolve wallpaper
|
// Load config and resolve wallpaper
|
||||||
let config = config::load_config(None);
|
let config = config::load_config(None);
|
||||||
let bg_path = config::resolve_background_path(&config);
|
let bg_texture = config::resolve_background_path(&config)
|
||||||
log::debug!("Background path: {}", bg_path.display());
|
.and_then(|path| {
|
||||||
|
log::debug!("Background path: {}", path.display());
|
||||||
// Load background texture once — shared across all windows
|
greeter::load_background_texture(&path)
|
||||||
// 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 use_layer_shell = std::env::var("MOONGREET_NO_LAYER_SHELL").is_err();
|
let use_layer_shell = std::env::var("MOONGREET_NO_LAYER_SHELL").is_err();
|
||||||
log::debug!("Layer shell: {use_layer_shell}");
|
log::debug!("Layer shell: {use_layer_shell}");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user