Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions freedesktop-icon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ impl IconTheme {
// Pixmaps are a last resort
Pixmap::get(icon_name)
}

/// Get an icon by name following the freedesktop icon theme specification
/// Searches through the current theme and inherited themes for the icon
pub fn get_with_size(&self, icon_name: &str, size: u32) -> Option<PathBuf> {
let scale: u8 = 1;

if let Some(path) = &self.get_through_inheritance(icon_name, size, scale) {
return Some(path.to_owned());
}

// Pixmaps are a last resort
Pixmap::get(icon_name)
}
}

impl IconTheme {
Expand Down Expand Up @@ -276,3 +289,14 @@ impl Pixmap {
pub fn get_icon(name: &str) -> Option<PathBuf> {
CURRENT_ICON_THEME.get(name)
}

/// Convenience function that will:
/// Get the current icon theme from IconTheme::current()
/// Call theme.get_with_size() which will get the icon for
/// the the supplied size and default scale.
/// IconTheme::current() will be cached using LazyLock
/// so multiple calls to this function do not incurr
/// a performance penalty
pub fn get_icon_with_size(name: &str, size: u32) -> Option<PathBuf> {
CURRENT_ICON_THEME.get_with_size(name, size)
}