mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
fix(darwin): make Position() and SetPosition() use consistent coordinate systems (#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 #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 #4816 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
9a131a049d
commit
537c74327d
2 changed files with 14 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Unreleased Changes
|
||||
|
||||
<!--
|
||||
<!--
|
||||
This file is used to collect changelog entries for the next v3-alpha release.
|
||||
Add your changes under the appropriate sections below.
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file
|
|||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
- Fix `Position()` and `SetPosition()` using inconsistent coordinate systems on macOS, causing window position drift when saving/restoring state (#4816) by @leaanthony
|
||||
|
||||
## Deprecated
|
||||
<!-- Soon-to-be removed features -->
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue