How the macOS TrayApp panel works (NSPanel)
masterThe macOS implementation of the transparent tray popup uses an NSPanel to mirror the Windows UX.
Key Technical Details:
- Window Style: Uses
.nonactivatingPanelstyle withlevel = .statusBarto ensure it stays topmost above normal applications without activating the app when interacting with it. - Transparency: Uses a transparent
CAMetalLayerviaTaoPopupSceneLayerfor rendering. - Input Handling:
- Outside Clicks: Uses a combination of
NSEvent.addGlobalMonitorForEvents(for clicks outside the app) and a local monitor (for clicks inside) to handle dismissal. - Keyboard: Overrides
canBecomeKeyWindow = trueto allow the panel to take key focus. Keyboard events (keyDown/keyUp) are forwarded using thedispatchNativeKeyEventwire format.
- Outside Clicks: Uses a combination of
- Rendering: Uses the Metal render path (Skia
DirectContextper host) rather than the EGL path used on other platforms.