Skip to content

fix(darwin): make Position() and SetPosition() use consistent coordinate systems#4818

Merged
leaanthony merged 4 commits intov3-alphafrom
fix/macos-position-coordinate-system-v3
Jan 25, 2026
Merged

fix(darwin): make Position() and SetPosition() use consistent coordinate systems#4818
leaanthony merged 4 commits intov3-alphafrom
fix/macos-position-coordinate-system-v3

Conversation

@leaanthony
Copy link
Copy Markdown
Member

@leaanthony leaanthony commented Dec 19, 2025

Summary

  • Fix coordinate system inconsistency between Position() and SetPosition() on macOS
  • windowGetPosition() now converts Y coordinates to top-origin (matching windowSetPosition())
  • windowGetPosition() now applies DPI scale factor (matching windowSetPosition())

This ensures window positions can be saved and restored correctly across application sessions.

Test plan

  • Verify window position save/restore works correctly on macOS
  • Test on displays with different DPI scale factors
  • Confirm Position() values can be passed directly to SetPosition() for consistent round-trip behavior

Fixes #4816

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed window positioning on macOS to consistently apply DPI scaling when computing and setting window coordinates, ensuring correct placement across standard and high‑DPI displays.
    • Resolved position drift when saving/restoring window state, including multi‑monitor setups.

✏️ Tip: You can customize this high-level summary in your review settings.

…ate systems

On macOS, windowGetPosition() was returning raw Cocoa coordinates (Y=0 at
bottom of screen) while windowSetPosition() expected coordinates with Y=0
at the top of the screen. This caused window positions to drift when saving
and restoring window state across application sessions.

The fix updates windowGetPosition() to:
1. Convert Y coordinates to top-origin (matching windowSetPosition)
2. Apply DPI scale factor (matching windowSetPosition)

This ensures Position() returns values that can be directly passed back to
SetPosition() for consistent round-trip behavior.

Fixes #4816

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 19, 2025

Warning

Rate limit exceeded

@leaanthony has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

Fix macOS window coordinate inconsistency: windowGetPosition and windowSetPosition now both use screen-space coordinates with DPI scaling and a top-origin Y convention to prevent position drift when saving/restoring window state.

Changes

Cohort / File(s) Summary
macOS window positioning coordinate fix
v3/pkg/application/webview_window_darwin.go
windowGetPosition now retrieves screen scale, applies DPI scaling, and converts Y to a top-origin value; windowSetPosition now divides inputs by screen scale and computes Y using screen height to maintain top-origin convention.
Changelog update
v3/UNRELEASED_CHANGELOG.md
Added entry under "Fixed" documenting the macOS Position()/SetPosition() coordinate-system fix (references #4816).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review DPI scale retrieval and usage in both functions (v3/pkg/application/webview_window_darwin.go)
  • Verify Y conversion formulas are symmetrical and use frame/ screen heights consistently
  • Check integer/float conversions and potential off-by-one rounding

Possibly related PRs

Suggested labels

Bug, MacOS, v3-alpha, size:XS

Poem

🐰 I hopped across screens both near and far,

Y flipped and scaled like a wandering star.
Now top-origin and DPI sing in tune,
Windows stay put — no more vertical swoon.
Hooray — no drift beneath the moon! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: making Position() and SetPosition() use consistent coordinate systems on macOS.
Description check ✅ Passed The PR description provides a clear summary of the fix, test plan, and links to issue #4816, though the template checklist items are incomplete.
Linked Issues check ✅ Passed The code changes fully address issue #4816 by making windowGetPosition() apply DPI scaling and top-origin Y-coordinate conversion to match windowSetPosition() behavior.
Out of Scope Changes check ✅ Passed All changes are directly in scope: modifications to windowGetPosition() and windowSetPosition() in darwin.go address the coordinate system issue, and changelog entry documents the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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

1434-1448: Consider updating the TODO comment about DPI scaling.

The bounds() function now calls windowGetPosition() which applies DPI scaling (returning pixels), but windowGetSize() returns points without scaling. This creates an inconsistency where X and Y are in pixels but Width and Height are in points.

While this is acknowledged by the TODO comment and is out of scope for this PR, you might want to update the TODO to be more specific about this mixed-unit issue to help guide future work.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b8c8d4 and 90389c7.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_darwin.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: semgrep/ci
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (go)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
v3/pkg/application/webview_window_darwin.go (1)

574-587: LGTM! Coordinate system fix correctly implemented.

The implementation correctly addresses the inconsistency by:

  1. Applying DPI scaling via backingScaleFactor to both X and Y coordinates
  2. Converting Y from macOS native bottom-origin to top-origin coordinates using (screenFrame.size.height - frame.origin.y - frame.size.height)

The transformations are mathematically inverse to those in windowSetPosition(), ensuring proper round-trip behavior when saving and restoring window positions.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Dec 19, 2025

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: 90656bd
Status:⚡️  Build in progress...

View logs

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Missing Changelog Update

Hi @leaanthony, please update v3/UNRELEASED_CHANGELOG.md with a description of your changes.

This helps us keep track of changes for the next release.

…ate systems

On macOS, windowGetPosition() was returning raw Cocoa coordinates (Y=0 at
bottom of screen) while windowSetPosition() expected coordinates with Y=0
at the top of the screen. This caused window positions to drift when saving
and restoring window state across application sessions.

The fix updates windowGetPosition() to:
1. Convert Y coordinates to top-origin (matching windowSetPosition)
2. Apply DPI scale factor (matching windowSetPosition)

This ensures Position() returns values that can be directly passed back to
SetPosition() for consistent round-trip behavior.

Fixes #4816

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@leaanthony leaanthony merged commit 537c743 into v3-alpha Jan 25, 2026
10 of 12 checks passed
@leaanthony leaanthony deleted the fix/macos-position-coordinate-system-v3 branch January 25, 2026 01:40
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Missing Changelog Update

Hi @leaanthony, please update v3/UNRELEASED_CHANGELOG.md with a description of your changes.

This helps us keep track of changes for the next release.

@sonarqubecloud
Copy link
Copy Markdown

Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
…ate systems (wailsapp#4818)

* fix(darwin): make Position() and SetPosition() use consistent coordinate systems

On macOS, windowGetPosition() was returning raw Cocoa coordinates (Y=0 at
bottom of screen) while windowSetPosition() expected coordinates with Y=0
at the top of the screen. This caused window positions to drift when saving
and restoring window state across application sessions.

The fix updates windowGetPosition() to:
1. Convert Y coordinates to top-origin (matching windowSetPosition)
2. Apply DPI scale factor (matching windowSetPosition)

This ensures Position() returns values that can be directly passed back to
SetPosition() for consistent round-trip behavior.

Fixes wailsapp#4816

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(darwin): make Position() and SetPosition() use consistent coordinate systems

On macOS, windowGetPosition() was returning raw Cocoa coordinates (Y=0 at
bottom of screen) while windowSetPosition() expected coordinates with Y=0
at the top of the screen. This caused window positions to drift when saving
and restoring window state across application sessions.

The fix updates windowGetPosition() to:
1. Convert Y coordinates to top-origin (matching windowSetPosition)
2. Apply DPI scale factor (matching windowSetPosition)

This ensures Position() returns values that can be directly passed back to
SetPosition() for consistent round-trip behavior.

Fixes wailsapp#4816

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant