fix(v3/darwin): make RelativePosition mirror SetRelativePosition on both axes#5569
Conversation
…oth axes windowGetRelativePosition returned the window's absolute X (frame.origin.x, missing the screenFrame.origin.x subtraction) and computed Y without the screen's origin.y term, while windowSetRelativePosition treats both coordinates as screen-relative. As a result SetRelativePosition(RelativePosition()) moved the window on any screen whose NSScreen origin is not (0,0) — i.e. every non-primary screen. The Y drift was previously masked on side-by-side arrangements (origin.y == 0) but is just as real on stacked ones. Get now mirrors Set exactly on both axes. Verified on a two-display Mac (Retina primary + external above): before the fix a round-trip on the secondary screen teleported the window by (489, -120); after, the position is stable and Position() is unchanged. Both functions keep using the screen frame (not visibleFrame); whether "relative" should mean WorkArea-relative is tracked separately in the issue. Fixes #5408
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis change fixes macOS relative window position reporting on multi-screen setups by aligning ChangesmacOS Relative Position Coordinate Space Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes a macOS-specific coordinate space mismatch where RelativePosition() and SetRelativePosition() did not round-trip correctly on non-primary displays (especially when NSScreen origins are not (0,0)), causing unexpected window movement.
Changes:
- Update
windowGetRelativePosition(darwin) to compute screen-relative X/Y in the same coordinate space consumed bywindowSetRelativePosition. - Add an entry to
v3/UNRELEASED_CHANGELOG.mddocumenting the bug fix for #5408.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| v3/pkg/application/webview_window_darwin.go | Aligns windowGetRelativePosition math with windowSetRelativePosition for consistent screen-relative coordinates on macOS. |
| v3/UNRELEASED_CHANGELOG.md | Documents the macOS RelativePosition/SetRelativePosition coordinate-space fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Get the window position relative to its screen: X from the screen's left | ||
| // edge, Y from the screen's top edge (Y-down). Must mirror | ||
| // windowSetRelativePosition exactly so Get/Set round-trip on every screen: | ||
| // previously X was returned absolute (missing the screenFrame.origin.x | ||
| // subtraction) and Y omitted screenFrame.origin.y, so both axes drifted on | ||
| // any screen whose NSScreen origin is not (0,0) (issue #5408). |
There was a problem hiding this comment.
Fixed in the latest commit. The comment now specifies NSScreen frame (not visibleFrame), and clarifies that each axis only drifted on screens where the corresponding NSScreen frame.origin component is non-zero — not both axes on every screen.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
v3/pkg/application/webview_window_darwin.go (1)
623-628: ⚡ Quick winAlign the “relative position” wording across API layers.
This block now explicitly states screen-frame-relative semantics, while
v3/pkg/application/webview_window.gostill documentsRelativePosition/SetRelativePositionas WorkArea-relative. Please align docs vs behavior so callers have one unambiguous contract.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v3/pkg/application/webview_window_darwin.go` around lines 623 - 628, The docs for RelativePosition/SetRelativePosition are inconsistent with the darwin implementation: webview_window_darwin.go now treats positions as screen-frame-relative but webview_window.go still documents them as WorkArea-relative; update the public contract to be consistent by changing the doc comments for the RelativePosition and SetRelativePosition methods (and any top-level API doc for RelativePosition) to explicitly state "screen-frame-relative (origin at NSScreen origin / screen's top-left)" OR alternatively adjust the darwin implementation to match WorkArea-relative semantics—choose one contract and make the doc text and the implementation of RelativePosition and SetRelativePosition match across the platform files so callers see a single unambiguous behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@v3/pkg/application/webview_window_darwin.go`:
- Around line 623-628: The docs for RelativePosition/SetRelativePosition are
inconsistent with the darwin implementation: webview_window_darwin.go now treats
positions as screen-frame-relative but webview_window.go still documents them as
WorkArea-relative; update the public contract to be consistent by changing the
doc comments for the RelativePosition and SetRelativePosition methods (and any
top-level API doc for RelativePosition) to explicitly state
"screen-frame-relative (origin at NSScreen origin / screen's top-left)" OR
alternatively adjust the darwin implementation to match WorkArea-relative
semantics—choose one contract and make the doc text and the implementation of
RelativePosition and SetRelativePosition match across the platform files so
callers see a single unambiguous behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 13ea56ab-6c71-4476-9fb5-7897c0bd4677
📒 Files selected for processing (2)
v3/UNRELEASED_CHANGELOG.mdv3/pkg/application/webview_window_darwin.go
…hangelog conflict # Conflicts: # v3/UNRELEASED_CHANGELOG.md
Description
On macOS,
RelativePosition()andSetRelativePosition()disagreed about the coordinate space:frame.origin.x, noscreenFrame.origin.xsubtraction) and computed Y without the screen'sorigin.yterm.So
w.SetRelativePosition(w.RelativePosition())moved the window on any screen whose NSScreen origin isn't (0,0) — every non-primary screen. The issue reported the X mismatch; the Y term is the same class of bug, just masked on side-by-side arrangements (whereorigin.y == 0) — it bites on stacked ones.Fix
windowGetRelativePositionnow mirrorswindowSetRelativePositionexactly on both axes:Both sides keep using
frame(notvisibleFrame); whether "relative" should mean WorkArea-relative is a separate decision per the issue notes.Verification (real two-display Mac: Retina primary + external arranged above)
Round-trip probe — place window on the secondary screen, then call
SetRelativePosition(RelativePosition())and comparePosition():(394, −832)— X is the absolute value, Y wrong(−95, 150)— screen-relativego builddarwin + fullpkg/applicationtest suite pass on macOS.Fixes #5408
Type of change
Checklist:
v3/UNRELEASED_CHANGELOG.mdSummary by CodeRabbit