From dbe71e81bd82975b3013b92933ce4368db6b8b96 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 8 Oct 2018 05:38:46 +0900 Subject: [PATCH] ui: Bug fix: currentMonitorPos returned wrong values on macOS [NSScreen mainScreen] sometimes returned a wrong screen for the window. Use [[NSApp mainWindow] screen] when possible. Fixes #703 --- internal/ui/ui_mac.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/ui/ui_mac.go b/internal/ui/ui_mac.go index 80cfd25ae..e9cece7b3 100644 --- a/internal/ui/ui_mac.go +++ b/internal/ui/ui_mac.go @@ -24,7 +24,15 @@ package ui // #import // // static void currentMonitorPos(int* x, int* y) { -// NSDictionary* screenDictionary = [[NSScreen mainScreen] deviceDescription]; +// NSScreen* screen = [NSScreen mainScreen]; +// NSWindow* window = [NSApp mainWindow]; +// if ([window isVisible]) { +// // When the window is visible, the window is already initialized. +// // [NSScreen mainScreen] sometimes tells a lie when the window is put across monitors (#703). +// // Use [[NSApp mainWindow] screen] instead. +// screen = [window screen]; +// } +// NSDictionary* screenDictionary = [screen deviceDescription]; // NSNumber* screenID = [screenDictionary objectForKey:@"NSScreenNumber"]; // CGDirectDisplayID aID = [screenID unsignedIntValue]; // const CGRect bounds = CGDisplayBounds(aID);