| Crates.io | freedesktop-icon |
| lib.rs | freedesktop-icon |
| version | 0.0.3 |
| created_at | 2025-09-23 03:54:19.133113+00 |
| updated_at | 2025-09-23 03:54:19.133113+00 |
| description | Rust implementations of the freedesktop standards |
| homepage | https://github.com/javif89/freedesktop |
| repository | https://github.com/javif89/freedesktop |
| max_upload_size | |
| id | 1850976 |
| size | 21,070 |
A Rust implementation of the freedesktop Icon Theme Specification for finding and loading desktop icons on Linux systems.
/usr/share/pixmaps when icons aren't found in themesAdd to your Cargo.toml:
[dependencies]
freedesktop-icon = "0.0.3"
use freedesktop_icon::{IconTheme, get_icon};
// Get the current system icon theme
let theme = IconTheme::current();
println!("Current theme: {}", theme.name());
// Find an icon using the convenience function
if let Some(path) = get_icon("firefox") {
println!("Firefox icon: {}", path.display());
}
// Or search within a specific theme
let theme = IconTheme::from_name("Adwaita").unwrap();
if let Some(path) = theme.get("folder") {
println!("Folder icon: {}", path.display());
}
The library follows the freedesktop specification for icon lookup:
/usr/share/pixmaps and other pixmap locations.svg) - Vector graphics (preferred).png) - Raster graphics.xpm) - Legacy X11 pixmapsuse freedesktop_icon::IconTheme;
// Load a specific theme
if let Some(theme) = IconTheme::from_name("Papirus") {
println!("Theme path: {}", theme.path().display());
println!("Default size: {:?}", theme.default_size());
// Get inheritance chain
for parent in theme.inherits() {
println!("Inherits from: {}", parent);
}
// Find icon directories for a specific size
for dir in theme.icon_dirs(48, 1) {
println!("48x48 icon directory: {}", dir.display());
}
}
use freedesktop_icon::Pixmap;
// Search for icons in pixmap directories only
if let Some(path) = Pixmap::get("application-icon") {
println!("Found pixmap: {}", path.display());
}
The library respects XDG Base Directory specifications:
$XDG_DATA_DIRS/icons (typically /usr/share/icons)$XDG_DATA_HOME/icons (typically ~/.local/share/icons)$XDG_CONFIG_HOME$XDG_DATA_DIRS/pixmapsThe 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.iniFalls back to hicolor if no theme is configured.
LazyLockThis crate is part of the freedesktop workspace. You can use it standalone or as part of the main crate:
# Standalone
freedesktop-icon = "0.0.3"
# Or as part of the main freedesktop crate
freedesktop = { version = "0.0.3", features = ["icon"] }
freedesktop-core - XDG base directories and desktop environment detectionfreedesktop-apps - Desktop entry parsing and application discoveryMIT - see LICENSE for details.