summaryrefslogtreecommitdiff
path: root/src/icon.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/icon.rs')
-rw-r--r--src/icon.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/icon.rs b/src/icon.rs
index 4dae1a9..1173629 100644
--- a/src/icon.rs
+++ b/src/icon.rs
@@ -17,6 +17,34 @@ impl IconCache {
.or_insert_with(|| resolve_icon(app_id, bar_height))
.as_ref()
}
+
+ /// Get a tray icon by name, preferring the given SNI IconThemePath.
+ pub fn get_tray_icon(
+ &mut self,
+ name: &str,
+ theme_path: &str,
+ bar_height: u32,
+ ) -> Option<&cairo::ImageSurface> {
+ if name.is_empty() {
+ return None;
+ }
+ self.map
+ .entry(format!("{theme_path}:{name}"))
+ .or_insert_with(|| resolve_tray_icon(name, theme_path, bar_height))
+ .as_ref()
+ }
+}
+
+fn resolve_tray_icon(name: &str, theme_path: &str, bar_height: u32) -> Option<cairo::ImageSurface> {
+ if !theme_path.is_empty() {
+ let path = PathBuf::from(theme_path).join(format!("{name}.png"));
+ if let Ok(mut file) = std::fs::File::open(path)
+ && let Ok(surface) = cairo::ImageSurface::create_from_png(&mut file)
+ {
+ return Some(surface);
+ }
+ }
+ resolve_icon(name, bar_height)
}
fn resolve_icon(app_id: &str, bar_height: u32) -> Option<cairo::ImageSurface> {