From 537c74327dabc16654ffbb61ecb103f215fac0db Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 25 Jan 2026 12:40:25 +1100 Subject: [PATCH] fix(darwin): make Position() and SetPosition() use consistent coordinate systems (#4818) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 #4816 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * 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 #4816 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- v3/UNRELEASED_CHANGELOG.md | 3 ++- v3/pkg/application/webview_window_darwin.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 8e4648038..806f0183a 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -1,6 +1,6 @@ # Unreleased Changes - +- Fix `Position()` and `SetPosition()` using inconsistent coordinate systems on macOS, causing window position drift when saving/restoring state (#4816) by @leaanthony ## Deprecated diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index baf40556c..d4534b501 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -590,11 +590,19 @@ void windowGetRelativePosition(void* nsWindow, int* x, int* y) { *y = screenFrame.size.height - frame.origin.y - frame.size.height; } -// Get absolute window position +// Get absolute window position (in screen coordinates with Y=0 at top, scaled for DPI) void windowGetPosition(void* nsWindow, int* x, int* y) { - NSRect frame = [(WebviewWindow*)nsWindow frame]; - *x = frame.origin.x; - *y = frame.origin.y; + WebviewWindow* window = (WebviewWindow*)nsWindow; + NSScreen* screen = [window screen]; + if (screen == NULL) { + screen = [NSScreen mainScreen]; + } + CGFloat scale = [screen backingScaleFactor]; + NSRect frame = [window frame]; + NSRect screenFrame = [screen frame]; + // Convert to top-origin coordinates and apply scale (matching windowSetPosition) + *x = frame.origin.x * scale; + *y = (screenFrame.size.height - frame.origin.y - frame.size.height) * scale; } void windowSetPosition(void* nsWindow, int x, int y) {