From b7e8786e6b658e704164698933ffccfaa8e48bb0 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 23 Aug 2026 16:22:30 +0545 Subject: [PATCH] refactor(systray): rely on fabric stock icon handling Upstream fabric now resolves tray icons correctly, so the local pixbuf fallback patch is gone. The patch keeps only config-based item hiding by wrapping do_update_properties. --- pyproject.toml | 2 +- .../panel/components/enhanced_system_tray.py | 68 +++---------------- uv.lock | 4 +- 3 files changed, 12 insertions(+), 62 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1d60140..9feaa58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,4 +106,4 @@ known-first-party = ["services", "utils", "shared", "window"] "examples/**" = ["INP001", "D101", "D102", "D103"] [tool.uv.sources] -fabric = { git = "https://github.com/Fabric-Development/fabric.git", tag = "v0.0.2" } +fabric = { git = "https://github.com/Fabric-Development/fabric.git" } diff --git a/src/window/panel/components/enhanced_system_tray.py b/src/window/panel/components/enhanced_system_tray.py index ebf04de..eebb7cd 100644 --- a/src/window/panel/components/enhanced_system_tray.py +++ b/src/window/panel/components/enhanced_system_tray.py @@ -1,8 +1,7 @@ import weakref -from pathlib import Path from fabric.system_tray.widgets import SystemTrayItem -from fabric.utils import GdkPixbuf, GLib, logger +from fabric.utils import logger from services.config import get_config, on_config_change @@ -27,62 +26,6 @@ def should_hide(item) -> bool: return False -def patched_do_update_properties(self, *_): - # Determine the icon name to use - item = self._item - icon_name = item.icon_name - attention_icon_name = item.attention_icon_name - - # Log item info for user debugging - logger.info( - f"[SysTray] Item: title='{getattr(item, 'title', '')}', identifier='{getattr(item, 'identifier', '')}'" - ) - - # Visibility check - is_hidden = should_hide(item) - self.set_visible(not is_hidden) - - if is_hidden: - return - - if item.status == "NeedsAttention" and attention_icon_name: - preferred_icon_name = attention_icon_name - else: - preferred_icon_name = icon_name - - # 1. Try the standard fabric/GTK implementation first - pixbuf = item.get_preferred_icon_pixbuf(self._icon_size) - - # 2. If standard lookup fails, try your specific absolute path logic - if pixbuf is None and preferred_icon_name: - path = Path(preferred_icon_name) - if path.is_absolute() and path.exists(): - try: - target_size = self._icon_size if self._icon_size else 24 - pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( - str(path), - target_size, - target_size, - True, # Preserve aspect ratio - ) - except GLib.GError: - pixbuf = None - - # Apply the resulting pixbuf or the fallback "missing" icon - if pixbuf: - self._image.set_from_pixbuf(pixbuf) - else: - self._image.set_from_icon_name("image-missing", self._icon_size) - - tooltip = item.tooltip - self.set_tooltip_markup( - tooltip.description - or tooltip.title - or (item.title.title() if item.title else None) - or "Unknown" - ) - - def apply_enhanced_system_tray(): # Patch __init__ to track instances original_init = SystemTrayItem.__init__ @@ -93,7 +36,14 @@ def apply_enhanced_system_tray(): SystemTrayItem.__init__ = patched_init - # Replace the method on the class so all tray items use this logic + # Wrap the stock implementation so fabric keeps handling icons, + # while we enforce the configured visibility rules + original_do_update_properties = SystemTrayItem.do_update_properties + + def patched_do_update_properties(self, *_): + original_do_update_properties(self) + self.set_visible(not should_hide(self._item)) + SystemTrayItem.do_update_properties = patched_do_update_properties # Setup hot-reload listener diff --git a/uv.lock b/uv.lock index 5f15a6b..de88e81 100644 --- a/uv.lock +++ b/uv.lock @@ -136,7 +136,7 @@ wheels = [ [[package]] name = "fabric" version = "0.0.2" -source = { git = "https://github.com/Fabric-Development/fabric.git?tag=v0.0.2#85cacf660b1a324525a4dd9b512521e55ef7f89b" } +source = { git = "https://github.com/Fabric-Development/fabric.git#75471c13456e504d20120cab7b1e4a660e2a108d" } dependencies = [ { name = "click" }, { name = "loguru" }, @@ -268,7 +268,7 @@ dev = [ [package.metadata] requires-dist = [ - { name = "fabric", git = "https://github.com/Fabric-Development/fabric.git?tag=v0.0.2" }, + { name = "fabric", git = "https://github.com/Fabric-Development/fabric.git" }, { name = "keyring", specifier = "==25.7.0" }, { name = "keyrings-alt", specifier = "==5.0.2" }, { name = "psutil", specifier = "==7.2.2" },