Skip to content

fix(v3/darwin): make RelativePosition mirror SetRelativePosition on both axes#5569

Merged
leaanthony merged 5 commits into
masterfrom
fix/darwin-relative-position-5408
Jun 13, 2026
Merged

fix(v3/darwin): make RelativePosition mirror SetRelativePosition on both axes#5569
leaanthony merged 5 commits into
masterfrom
fix/darwin-relative-position-5408

Conversation

@leaanthony

@leaanthony leaanthony commented Jun 10, 2026

Copy link
Copy Markdown
Member

Description

On macOS, RelativePosition() and SetRelativePosition() disagreed about the coordinate space:

  • Get returned the absolute X (frame.origin.x, no screenFrame.origin.x subtraction) and computed Y without the screen's origin.y term.
  • Set treats both X and Y as screen-relative.

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 (where origin.y == 0) — it bites on stacked ones.

Fix

windowGetRelativePosition now mirrors windowSetRelativePosition exactly on both axes:

*x = frame.origin.x - screenFrame.origin.x;
*y = (screenFrame.origin.y + screenFrame.size.height) - frame.origin.y - frame.size.height;

Both sides keep using frame (not visibleFrame); 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 compare Position():

Build rel returned window after round-trip
master (394, −832) — X is the absolute value, Y wrong teleported by (489, −120)
this branch (−95, 150) — screen-relative unchanged (394, −1290)

go build darwin + full pkg/application test suite pass on macOS.

Fixes #5408

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the general coding style of this project
  • I have updated v3/UNRELEASED_CHANGELOG.md

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect window position calculations on macOS when using multiple displays, ensuring consistent position values across all screens.

…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
Copilot AI review requested due to automatic review settings June 10, 2026 22:12
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7ea71a40-a2ef-4030-a8b0-7edec7d99788

📥 Commits

Reviewing files that changed from the base of the PR and between bb3734d and f3970eb.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_darwin.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/webview_window_darwin.go

Walkthrough

This change fixes macOS relative window position reporting on multi-screen setups by aligning windowGetRelativePosition with windowSetRelativePosition and documenting the coordinate conventions and round-trip expectations.

Changes

macOS Relative Position Coordinate Space Fix

Layer / File(s) Summary
windowGetRelativePosition coordinate calculation update
v3/pkg/application/webview_window_darwin.go
windowGetRelativePosition now returns screen-relative X and Y using the current NSScreen frame, and its comments describe the coordinate mapping and Get/Set round-trip behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Bug, MacOS, v3, size:XS, awaiting review 🕝

Suggested reviewers

  • flofreud

Poem

🐇 I hopped across two screens today,
and found an X had lost its way.
Now Get and Set both neatly agree,
with Y in step from top to tree.
A tidy bounce in macOS glee.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: making RelativePosition mirror SetRelativePosition on both X and Y axes.
Description check ✅ Passed The description addresses the issue with code examples, verification steps, and includes required metadata (bug fix type, Fixes #5408, checklist items completed).
Linked Issues check ✅ Passed The PR fully addresses issue #5408 by fixing the coordinate space inconsistency on both X and Y axes as required, with verification and matching implementation approach.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the RelativePosition/SetRelativePosition inconsistency in windowGetRelativePosition; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/darwin-relative-position-5408

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by windowSetRelativePosition.
  • Add an entry to v3/UNRELEASED_CHANGELOG.md documenting 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.

Comment on lines +623 to +628
// 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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
v3/pkg/application/webview_window_darwin.go (1)

623-628: ⚡ Quick win

Align the “relative position” wording across API layers.

This block now explicitly states screen-frame-relative semantics, while v3/pkg/application/webview_window.go still documents RelativePosition/SetRelativePosition as 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2633f81 and c5520db.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/pkg/application/webview_window_darwin.go

@leaanthony leaanthony merged commit 41a3680 into master Jun 13, 2026
21 of 25 checks passed
@leaanthony leaanthony deleted the fix/darwin-relative-position-5408 branch June 13, 2026 23:00
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.

[v3, macOS] RelativePosition() and SetRelativePosition() use inconsistent X coordinate spaces

2 participants