mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-22 09:29:24 +01:00
A new System Tray widget has been added to komorebi-bar, bringing native Windows system tray functionality directly into the bar. Special thanks to the Zebar project and its contributors for developing the systray-util crate library that makes Windows system tray integration possible. The widget intercepts system tray icon data by creating a hidden "spy" window that mimics the Windows taskbar. When applications use the Shell_NotifyIcon API to manage their tray icons, the widget receives the same broadcast messages, allowing it to monitor all system tray activity while forwarding messages to the real taskbar to avoid disruption. Users can configure which icons to hide using flexible rules. A plain string matches by exe name (case-insensitive). A structured object can match on exe, tooltip, and/or GUID fields using AND logic. Each field supports matching strategies from komorebi's window rules (Equals, StartsWith, EndsWith, Contains, Regex, and their negated variants), allowing precise filtering even when multiple icons share the same exe and GUID. An info button opens a floating panel listing all icons with their properties and copy buttons, making it easy to identify which values to use in filter rules. The widget fully supports mouse interactions including left-click, right-click, middle-click, and double-click actions on tray icons. Double-click support uses the LeftDoubleClick action from systray-util 0.2.0, which sends WM_LBUTTONDBLCLK and NIN_SELECT messages. It handles right-aligned placement correctly by adjusting the rendering order and toggle button arrow directions to maintain consistent visual appearance regardless of which panel the widget is placed in. Some system tray icons register a click callback but never actually respond to click messages, effectively becoming "zombie" icons from an interaction standpoint. The widget includes fallback commands for known problematic icons that override the native click action with a direct shell command (e.g. opening Windows Security or volume settings). The implementation uses a background thread with its own tokio runtime to handle the async systray events, communicating with the UI thread through crossbeam channels. Icon images are cached efficiently using hash-based keys that update when icons change. Rapid icon updates are deduplicated to prevent UI freezing, and image conversion (RgbaImage to ColorImage) is performed on the background thread to keep the UI responsive. The widget automatically detects and removes stale icons whose owning process has exited, using the Win32 IsWindow API on a configurable interval. A manual refresh button is also available for immediate cleanup. A shortcuts button can be configured to toggle komorebi-shortcuts by killing the process if running or starting it otherwise. The refresh, info, and shortcuts buttons can each be placed in the main visible area or in the overflow section.