Skip to content

Fix macOS tray icon appearance on multi-monitor#359

Merged
kdroidFilter merged 1 commit intomasterfrom
fix/macos-tray-multimonitor-appearance
Feb 3, 2026
Merged

Fix macOS tray icon appearance on multi-monitor#359
kdroidFilter merged 1 commit intomasterfrom
fix/macos-tray-multimonitor-appearance

Conversation

@kdroidFilter
Copy link
Owner

@kdroidFilter kdroidFilter commented Feb 3, 2026

Summary

  • Pre-render both light and dark icon variants at the Kotlin level and pass them to Swift via a new tray_set_icons_for_appearance() native API
  • Swift observer swaps cached NSImage instantly on appearance change — no Kotlin round-trip needed
  • Fix observer race condition by cancelling the settle callback on each new appearance change
  • Reduce debounce delay from 40 ms to 10 ms and register context before KVO observation starts

Test plan

  • Run demo with Tray(ImageVector) on a multi-monitor macOS setup with different wallpapers/appearances
  • Verify the tray icon swaps instantly (no flicker or delay) when moving to a screen with a different appearance
  • Verify single-monitor light/dark mode switching still works correctly
  • Verify Tray(Painter) and Tray(DrawableResource) variants still benefit from the observer fix (faster detection)
  • Rebuild native lib (cd maclib && bash build.sh) and run ./gradlew build

Closes #306

Pre-render both light and dark icon variants at the Kotlin level and
cache them in Swift so the appearance observer can swap icons instantly
on screen/theme changes without a Kotlin round-trip.

- Add tray_set_icons_for_appearance() native API (tray.h / tray.swift)
- Cache light/dark NSImage in TrayContext, swap in observer evaluate()
- Fix observer race condition: cancel settleItem on new appearance change
- Reduce debounce from 40ms to 10ms for faster detection
- Register context before starting KVO observation in tray_init
- Add JNA binding and forwarding through MacTrayManager/MacTrayInitializer
- Tray(ImageVector) with auto-tint pre-renders both variants on macOS

Closes #306
@kdroidFilter kdroidFilter force-pushed the fix/macos-tray-multimonitor-appearance branch from ad70498 to 3abf6c6 Compare February 3, 2026 16:26
@kdroidFilter kdroidFilter merged commit 963777e into master Feb 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS]Tray Icon Color/Appearance Changes Incorrectly Based on Active Screen

1 participant