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
This commit is contained in:
Hajime Hoshi 2018-10-08 05:38:46 +09:00
parent c4a066ecd0
commit dbe71e81bd

View File

@ -24,7 +24,15 @@ package ui
// #import <AppKit/AppKit.h>
//
// 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);