Repository navigation
fix(panel): improve tray icon positioning logic for macOS - #154
Conversation
|
Thank you so much! I can’t easily test it for the next two days. But if others jump in and review this, I’d be happy to merge it. |
robinebers
left a comment
There was a problem hiding this comment.
Hey! 👋 This is Rob's AI reviewer. Thanks for the contribution — really appreciate you tackling this multi-monitor bug!
The approach is solid: the coordinate model (logical_pos × scale = physical origin) correctly matches the upstream Tauri bug (tauri-apps/tauri#7890), the fallback to primary monitor is much safer than the old expect() panic, switching to LogicalPosition is the right call, and the inline comments explaining why are excellent. Two things to address before merge:
-
Icon-width heuristic breaks for dynamic tray icons — The
icon_phys_w > 100.0threshold was likely tested against the static fallback PNG (~132px on Retina). But OpenUsage dynamically replaces the tray icon with variable-width rendered content (bars, circles, text like "75%"). On a 2x display, most of these produce icons well under 100px — for example, bars-only is ~36px, bars + "75%" is ~99px, circle is ~36px. That means the scale detection silently fails for the majority of real-world states, and the overlapping-region disambiguation (the whole point of the fix) won't work. A more robust approach: instead of inferring scale from icon size, compareicon_phys_wagainst the monitor's own scale factor when disambiguating. For example, check if(icon_phys_w / expected_logical_w)is closer to each candidate monitor's scale, or simply use the monitor whose scale factor best explains the icon's reported physical dimensions. -
Hardcoded panel width —
let panel_width = 400.0_f64duplicates a value fromtauri.conf.json. The old code read this fromwindow.outer_size(), which stayed in sync automatically. If the configured width ever changes, this silently breaks positioning. Consider usingwindow.outer_size()again, converting to logical points.
Everything else — the monitor detection logic, the coordinate math, graceful fallback, and the quality of the comments — looks great. Nice work!
robinebers
left a comment
There was a problem hiding this comment.
needs addressing of icon width
|
Looking into it. |
|
@robinebers Fixed the PR comments. |
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src-tauri/src/panel.rs">
<violation number="1" location="src-tauri/src/panel.rs:162">
P2: Monitor hit-testing mixes logical mouse coordinates with Tauri’s physical monitor positions, so HiDPI displays can fail to detect the cursor’s monitor and fall back to primary.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where the panel overlay appeared on the primary monitor instead of the monitor where the tray icon was clicked in multi-monitor macOS setups. The fix uses NSEvent::mouseLocation() to unambiguously determine which monitor contains the cursor, then converts the tray icon's coordinates to logical coordinates within that monitor for proper panel positioning.
Changes:
- Replaced direct tray coordinate-based monitor detection with cursor position-based detection using macOS's NSEvent API
- Added coordinate space conversion logic to handle mixed-DPI setups
- Implemented fallback to primary monitor when cursor position cannot be determined
- Added objc2-app-kit dependency for NSEvent access
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| src-tauri/src/panel.rs | Rewrote position_panel_at_tray_icon function to use NSEvent::mouseLocation() for monitor detection and added coordinate conversion logic for mixed-DPI setups |
| src-tauri/Cargo.toml | Added objc2-app-kit dependency with NSEvent, NSScreen, and NSGraphics features |
| src-tauri/Cargo.lock | Updated lock file to include objc2-app-kit dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src-tauri/src/panel.rs">
<violation number="1" location="src-tauri/src/panel.rs:162">
P2: Monitor position is physical pixels while mouse coordinates are logical points; comparing them directly mixes units and can mis-detect the monitor on HiDPI setups.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Prevent edge-case double matches when the cursor is exactly on monitor seams by using half-open monitor bounds. Co-authored-by: Cursor <[email protected]>
Description
Fix panel overlay appearing on primary monitor instead of the monitor where the tray icon was clicked.
Related Issue
Fixes #150
Type of Change
Testing
bun run buildand it succeededbun run testand all tests passbun tauri devScreenshots
Before:

After:

Checklist
mainbranchSummary by cubic
Fixes the macOS panel opening on the wrong display by anchoring it to the monitor under the cursor, with consistent behavior on mixed‑DPI setups. Also prevents edge-case misplacement on monitor seams.
Bug Fixes
Refactors
Written for commit df7bd51. Summary will update on new commits.