summaryrefslogtreecommitdiff
path: root/src/icon.rs
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-07-29 09:10:42 +0200
committercashmere <cashmere@autistici.org>2026-07-29 09:10:42 +0200
commit5b77a6d8f19500eee21a497ce84db538ded05c00 (patch)
tree13e72121a7835fd0fed34f709b6e277e624a56dc /src/icon.rs
parente2f5e1267cc30b73202c85aacfaee0cd6b18193c (diff)
downloadi3bar-mango-5b77a6d8f19500eee21a497ce84db538ded05c00.tar.gz
add collapsible SNI system tray, rename project to i3bar-mango
Tray: the bar acts as org.kde.StatusNotifierWatcher plus host (zbus), rendering items on the right edge with icon/name; [tray] config toggles expanded, show_icon, show_name, show_description. Clicks map to Activate/SecondaryActivate/ContextMenu. Rename: package, binary, config dir, layer-shell namespace and DBus names are now i3bar-mango; mango is the default feature and the first WM provider tried.
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> {