Skip to content

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

Done

Description

@kitlangton

Apps that show other apps' icons (launchers, switchers, permission panels) need them off macOS too. On macOS, ImageCache already decodes ICNS.

Needed (Linux): a lookup from a desktop-file ID or icon name to an image through the freedesktop icon theme spec (the current theme, hicolor fallback, size and scale selection), plus SVG rasterising (e.g. resvg) at the requested size and scale, off the UI thread, through ImageCache. Windows: icons from an executable or AppUserModelID. Open question: does this belong in rune core (an image source) or in a small companion crate? Leaning core, as an image source behind a feature flag.

Activity

  1. ImBIOS commented on Oct 26, 2026

    @ImBIOS
    Contributor

    Double-checked on a stock Ubuntu 24.04 box (no Noto Symbols): the hicolor + SVG + pixmaps path from 6c9d971 is live and covered — ImageCache::app_icon → linux_icon → freedesktop::icon_file + resvg svg_rgba.

    What the issue text still asks for beyond that, and what I found probing the real theme dirs here:

    1. Current-theme lookup (missing): icon_file scans only icons/hicolor. The session theme here is Humanity/Adwaita territory; accessories-dictionary.svg ships only in Humanity/apps/48 (no hicolor copy), so it resolves to nothing today. Same for any theme-installed icon reachable only through Inherits (Humanity → Adwaita → hicolor). PR Linux: FreeSerif symbol fallback, session-theme icons, single-instance, GNOME toplevel fallback (fixes #2, #20, #21, #22) #29 (commit 35329d7) implements the theme-chain lookup in crates/rune/src/image.rs: read the XDG_CURRENT_DESKTOP theme, fall back Adwaita → Humanity → hicolor, follow Inherits breadth-first, match directories verbatim from each index.theme (Humanity's apps/48, @2 scaled sets), smallest covering bitmap → scalable SVG (resvg) → largest → pixmaps.
    2. Verification: temp-theme unit test (hicolor ladder incl. 48x48@2 = 96px), an Inherits-chain test, and a real-system probe — accessories-dictionary.svg resolves inside Humanity and rasterizes 96×96 with visible pixels through app_icon_rgba. cargo test -p rune --lib image:: green.
    3. Open question in the issue (core vs companion crate): the implementation lives in core behind no new flag (resvg + zbus already core deps). Say the word if it should sit behind a feature flag instead.
  2. wmfeht commented on Nov 22, 2026

    @wmfeht

    Strata (lgse/strata), a file manager on Rune, shows other apps' icons (Open With) and MIME-type icons, and hits these limits of ImageCache::app_icon on Linux at 67d73a5f:

    • The user's theme. As the 2026-10-26 comment found, freedesktop::icon_file (crates/rune-image/src/app_icon.rs:151-180) still scans icons/hicolor only (:159).
    • index.theme sizes. It reads a size from the directory name (48x48, @2), not the theme's Size, Type, Threshold, MinSize, MaxSize and Scale.
    • Lookup by name. It takes a .desktop path only, and looks in apps/ only, so a MIME icon name (text-x-python, in mimetypes/) or a list of fallback names (as GThemedIcon gives) can't be looked up.
    • Not found. A missing icon and a broken file both resolve to Image::error.
    • It lists every size directory again on each call.

    Headless, with XDG_DATA_HOME=$T/share:

    mkdir -p $T/share/icons/Fixture/48x48/apps $T/share/applications
    printf '[Icon Theme]
    Name=Fixture
    Inherits=hicolor
    Directories=48x48/apps
    
    [48x48/apps]
    Size=48
    Type=Fixed
    '   > $T/share/icons/Fixture/index.theme
    cp any-48px.png $T/share/icons/Fixture/48x48/apps/fixture-app.png
    printf '[Desktop Entry]
    Type=Application
    Name=Fixture
    Exec=true
    Icon=fixture-app
    '   > $T/share/applications/fixture.desktop

    ImageCache::new(waker).app_icon_scaled("$T/share/applications/fixture.desktop", 48.0, 1.0) fails with no icon for $T/share/applications/fixture.desktop, while the same PNG under icons/hicolor/48x48/apps is found. Nothing names a theme to look in.

    What would cover it: an image source taking the theme by name, ImageCache::themed_icon(names, theme, size_pt, scale), following the Icon Theme Specification, with "not found" apart from a decode error. Or, smaller: a way to run a path lookup on the cache's worker (cache.file_with(|| -> Option<PathBuf>, size_pt, scale)), so a crate doing the lookup needs no thread of its own.

  3. Hona commented on Nov 24, 2026

    @Hona
    Member

    Full Linux freedesktop icon-theme lookup, ImageCache::themed_icon, rune::image::themed_icon_rgba, and Image::is_not_found() are now on dev in #1979 (766e35f50).

    What was built

    • Freedesktop Icon Theme Specification lookup (crates/rune-image/src/freedesktop.rs): parses index.theme ([Icon Theme] Inherits, Directories, ScaledDirectories and per-directory Size, Scale, Type = Fixed | Scalable | Threshold, MinSize, MaxSize, Threshold, Context), selects icons with DirectoryMatchesSize and DirectorySizeDistance, walks Inherits breadth-first ending at hicolor then pixmaps, detects the current Linux desktop theme from GTK settings.ini / KDE kdeglobals (falling back to Adwaita → hicolor), and caches parsed theme indices in a bounded 64-theme / 4 MiB LRU cache.
    • Upgraded ImageCache::app_icon / app_icon_scaled on Linux: .desktop entries now resolve through the full active theme chain instead of scanning icons/hicolor only.
    • New API (additive, keeping ImageError(pub String) unchanged):
      • 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 (separates missing icons/files from corrupt-file decode errors)
    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()
    }

    Outside answer & design notes

    • Follows the Freedesktop Icon Theme Specification and GTK 4 gtk_icon_theme_lookup_icon / GThemedIcon fallback order (trying each name in names in order across the full theme chain so a specific icon in hicolor is not shadowed by a generic fallback in the active theme).
    • Instead of adding a generic worker closure (file_with), this implements the full spec directly on the existing ImageCache decoder worker. Windows executable/icon extraction is already supported in app_icon; if Windows AppUserModelID lookup or anything else in this API doesn't fit your use case, please comment or open a follow-up issue.

    Verification

    • Verified with fixture tests across Windows (cargo test -p rune-image 74 unit + 8 doc, --no-default-features 67 unit + 8 doc, rune image/pills/pixels_streaming tests, launcher test, check-wasm / check-webgl), headless Linux aarch64 (cargo test -p rune-image 73 unit + 8 doc), and macOS arm64 (cargo test -p rune-image 75 unit + 8 doc).
    • Not verified: a live Linux desktop session reading real host GTK/KDE themes in a rendered window, or workspace-wide check -p rune -p rune-kit -p launcher on Linux/macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions