Skip to content

feat(image): add Linux freedesktop icon-theme lookup, ImageCache::themed_icon, and Image::is_not_found - #1979

Merged
Hona merged 1 commit into
devfrom
feat/21-freedesktop-themed-icons
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
feat/21-freedesktop-themed-icons

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #21

Implements full Linux Freedesktop Icon Theme Specification lookup in crates/rune-image/src/freedesktop.rs, exposes ImageCache::themed_icon, rune::image::themed_icon_rgba, and Image::is_not_found(), upgrades Linux .desktop resolution in app_icon / app_icon_scaled, and wires themed icon resolution with is_not_found() fallback into examples/launcher.

Outside answer followed

  • Freedesktop Icon Theme Specification (https://specifications.freedesktop.org/icon-theme-spec/latest/): index.theme ([Icon Theme] Inherits, Directories, ScaledDirectories; per-directory Size, Scale, Type = Fixed | Scalable | Threshold, MinSize, MaxSize, Threshold, Context, with spec defaults Scale=1, Type=Threshold, Threshold=2), DirectoryMatchesSize, DirectorySizeDistance, breadth-first Inherits ending at hicolor then pixmaps, and $HOME/.icons + $XDG_DATA_HOME/icons + $XDG_DATA_DIRS/icons.
  • Desktop theme settings & fallback-name order: reads GTK 4/3 settings.ini ([Settings] gtk-icon-theme-name), GTK 2 .gtkrc-2.0, and KDE kdeglobals ([Icons] Theme) respecting XDG_CURRENT_DESKTOP for KDE vs GTK precedence, falling back to Adwaita → hicolor. Fallback names are tried most-specific first across the theme chain (matching GTK 4 gtk_icon_theme_lookup_icon / GThemedIcon).

API & usage

let icon = cache.themed_icon(&["text-x-python", "text-plain"], None, 24.0, env.scale);
if icon.size().is_some() {
    el().size(24.0, 24.0).pixels_fit(icon.pixels(), SurfaceFit::Fit)
} else if icon.is_not_found() {
    fallback_badge() // distinct from corrupt-file decode errors (icon.error().is_some() && !icon.is_not_found())
}
  • ImageCache::themed_icon(&self, names: &[&str], theme: Option<&str>, size_pt: f32, scale: f32) -> Image
  • rune::image::themed_icon_rgba(names: &[&str], theme: Option<&str>, px: u32, scale: u32) -> Result<Option<(u32, u32, Vec<u8>)>, ImageError>
  • Image::is_not_found(&self) -> bool (backed by an internal flag alongside ImageError(pub String), keeping ImageError unchanged)

Key changes

  • crates/rune-image/src/freedesktop.rs: index.theme parser (rejecting path traversal), DirectoryMatchesSize / DirectorySizeDistance selection with downscale tie-breaking, BFS Inherits with cycle protection, GTK/KDE theme detection, bounded LRU ThemeCache (cap 64 themes and 4 MiB, I/O outside lock), and bounded regular-file/raster decoding.
  • crates/rune-image/src/app_icon.rs, crates/rune-image/src/lib.rs: upgraded Linux .desktop app_icon / app_icon_scaled to the full theme chain; added DecodeFailure so Image::is_not_found() separates missing icons/files from corrupt-file decode errors.
  • crates/rune-image/src/freedesktop_tests.rs, crates/rune-image/src/tests.rs: cross-platform fixture tests covering spec parsing, size/scale/threshold selection, BFS inheritance and cycles, multi-context fallback lists, GTK/KDE detection, PNG/SVG rasterization, is_not_found() vs corrupt files, and 64-theme/byte-cap LRU eviction.
  • examples/launcher/src/main.rs, examples/README.md, crates/rune/README.md, changelog/unreleased/2026-11-25-freedesktop-themed-icons.md: themed icons + is_not_found() monogram fallback and --scene themed-icons in launcher, docs, and changelog.

Verification

  • Windows: cargo test -p rune-image (74 unit + 8 doc), cargo test -p rune-image --no-default-features (67 unit + 8 doc), cargo check -p rune -p rune-kit -p launcher, cargo test -p rune --lib render::image_tests (8), el::pills (10), --test pixels_streaming (3), cargo test -p launcher (1), cargo check-wasm, cargo check-webgl, scripts/file-size.sh.
  • Linux (aarch64 headless): cargo test -p rune-image (73 unit + 8 doc).
  • macOS (arm64): cargo test -p rune-image (75 unit + 8 doc).
  • Not checked: live Linux desktop session with system-installed GTK/KDE themes and live window rendering; workspace-level check -p rune -p rune-kit -p launcher on Linux/macOS.

@Hona
Hona force-pushed the feat/21-freedesktop-themed-icons branch from 578bf23 to 3562f6f Compare November 24, 2026 16:03
@Hona
Hona merged commit 766e35f into dev Nov 24, 2026
@Hona
Hona deleted the feat/21-freedesktop-themed-icons branch November 24, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App icons off macOS: freedesktop icon-theme lookup and SVG rasterising

1 participant