Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions v3/pkg/application/webview_window_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,19 +620,25 @@ int windowGetHeight(void* nsWindow) {
return [(WebviewWindow*)nsWindow frame].size.height;
}

// Get window position
// Get the window position relative to its screen's NSScreen frame origin:
// X from the screen's left edge, Y from the screen's top edge (Y-down).
// Uses NSScreen frame (full extent, including menu bar/dock) rather than
// visibleFrame. 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 each axis was wrong only on screens whose corresponding NSScreen
// frame.origin component is non-zero (issue #5408).
void windowGetRelativePosition(void* nsWindow, int* x, int* y) {
WebviewWindow* window = (WebviewWindow*)nsWindow;
NSRect frame = [window frame];
*x = frame.origin.x;

// Translate to screen coordinates so Y=0 is the top of the screen
NSScreen* screen = [window screen];
if( screen == NULL ) {
screen = [NSScreen mainScreen];
}
NSRect screenFrame = [screen frame];
*y = screenFrame.size.height - frame.origin.y - frame.size.height;
*x = frame.origin.x - screenFrame.origin.x;
*y = (screenFrame.origin.y + screenFrame.size.height) - frame.origin.y - frame.size.height;
}

// Get absolute window position in the canonical Wails coordinate space:
Expand Down
Loading