freedesktop-icon
A Rust implementation of the freedesktop Icon Theme Specification for finding and loading desktop icons on Linux systems.
Features
- Icon theme support - Load and parse icon themes following the freedesktop specification
- Icon lookup - Find icons by name with proper inheritance chain traversal
- Pixmap fallback - Automatic fallback to
/usr/share/pixmapswhen icons aren't found in themes - Performance optimized - Cached theme loading and lazy inheritance evaluation
- XDG compliance - Respects XDG base directories and user overrides
Quick Start
Add to your Cargo.toml:
[]
= "0.0.3"
Basic Usage
use ;
// Get the current system icon theme
let theme = current;
println!;
// Find an icon using the convenience function
if let Some = get_icon
// Or search within a specific theme
let theme = from_name.unwrap;
if let Some = theme.get
Icon Lookup Process
The library follows the freedesktop specification for icon lookup:
- Current theme - Search in the active icon theme
- Inherited themes - Recursively search parent themes
- Hicolor fallback - Search in the default hicolor theme
- Pixmap directories - Finally check
/usr/share/pixmapsand other pixmap locations
Supported Formats
- SVG (
.svg) - Vector graphics (preferred) - PNG (
.png) - Raster graphics - XPM (
.xpm) - Legacy X11 pixmaps
Advanced Usage
Working with Specific Themes
use IconTheme;
// Load a specific theme
if let Some = from_name
Direct Pixmap Search
use Pixmap;
// Search for icons in pixmap directories only
if let Some = get
XDG Integration
The library respects XDG Base Directory specifications:
- Icon themes:
$XDG_DATA_DIRS/icons(typically/usr/share/icons) - User themes:
$XDG_DATA_HOME/icons(typically~/.local/share/icons) - Theme config: Reads from GTK settings in
$XDG_CONFIG_HOME - Pixmap fallback:
$XDG_DATA_DIRS/pixmaps
Theme Detection
The current theme is detected from GTK configuration files in this order:
$XDG_CONFIG_HOME/gtk-4.0/settings.ini$XDG_CONFIG_HOME/gtk-3.0/settings.ini$HOME/.config/gtk-4.0/settings.ini$HOME/.config/gtk-3.0/settings.ini
Falls back to hicolor if no theme is configured.
Performance Notes
- Theme caching: Parsed theme configurations are cached for performance
- Lazy loading: Inherited themes are only loaded when needed during icon search
- Early exit: Search stops as soon as an icon is found in any theme
- Static optimization: The current theme is cached globally using
LazyLock
Integration
This crate is part of the freedesktop workspace. You can use it standalone or as part of the main crate:
# Standalone
= "0.0.3"
# Or as part of the main freedesktop crate
= { = "0.0.3", = ["icon"] }
Related Crates
freedesktop-core- XDG base directories and desktop environment detectionfreedesktop-apps- Desktop entry parsing and application discovery
License
MIT - see LICENSE for details.