ui: Fix logic: [NSApp mainWindow] can be nil when borderless

This commit is contained in:
Hajime Hoshi 2018-12-19 02:07:45 +09:00
parent db4395d71b
commit 294bf855af
2 changed files with 14 additions and 8 deletions

View File

@ -23,15 +23,16 @@ package ui
//
// #import <AppKit/AppKit.h>
//
// static void currentMonitorPos(int* x, int* y) {
// static void currentMonitorPos(void* windowPtr, int* x, int* y) {
// NSScreen* screen = [NSScreen mainScreen];
// NSWindow* window = [NSApp mainWindow];
// if (windowPtr) {
// NSWindow* window = (NSWindow*)windowPtr;
// 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];
@ -42,6 +43,8 @@ package ui
import "C"
import (
"unsafe"
"github.com/go-gl/glfw/v3.2/glfw"
)
@ -56,7 +59,9 @@ func adjustWindowPosition(x, y int) (int, int) {
func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
x := C.int(0)
y := C.int(0)
C.currentMonitorPos(&x, &y)
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use u.window here.
win := unsafe.Pointer(u.window.GetCocoaWindow())
C.currentMonitorPos(win, &x, &y)
for _, m := range glfw.GetMonitors() {
mx, my := m.GetPos()
if int(x) == mx && int(y) == my {

View File

@ -122,6 +122,7 @@ func adjustWindowPosition(x, y int) (int, int) {
}
func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
// TODO: Should we use u.window.GetWin32Window() here?
w, err := getActiveWindow()
if err != nil {
panic(err)