mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
ui: Fix logic: [NSApp mainWindow] can be nil when borderless
This commit is contained in:
parent
db4395d71b
commit
294bf855af
@ -23,14 +23,15 @@ package ui
|
|||||||
//
|
//
|
||||||
// #import <AppKit/AppKit.h>
|
// #import <AppKit/AppKit.h>
|
||||||
//
|
//
|
||||||
// static void currentMonitorPos(int* x, int* y) {
|
// static void currentMonitorPos(void* windowPtr, int* x, int* y) {
|
||||||
// NSScreen* screen = [NSScreen mainScreen];
|
// NSScreen* screen = [NSScreen mainScreen];
|
||||||
// NSWindow* window = [NSApp mainWindow];
|
// if (windowPtr) {
|
||||||
// if ([window isVisible]) {
|
// NSWindow* window = (NSWindow*)windowPtr;
|
||||||
// // When the window is visible, the window is already initialized.
|
// if ([window isVisible]) {
|
||||||
// // [NSScreen mainScreen] sometimes tells a lie when the window is put across monitors (#703).
|
// // When the window is visible, the window is already initialized.
|
||||||
// // Use [[NSApp mainWindow] screen] instead.
|
// // [NSScreen mainScreen] sometimes tells a lie when the window is put across monitors (#703).
|
||||||
// screen = [window screen];
|
// screen = [window screen];
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
// NSDictionary* screenDictionary = [screen deviceDescription];
|
// NSDictionary* screenDictionary = [screen deviceDescription];
|
||||||
// NSNumber* screenID = [screenDictionary objectForKey:@"NSScreenNumber"];
|
// NSNumber* screenID = [screenDictionary objectForKey:@"NSScreenNumber"];
|
||||||
@ -42,6 +43,8 @@ package ui
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/go-gl/glfw/v3.2/glfw"
|
"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 {
|
func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
|
||||||
x := C.int(0)
|
x := C.int(0)
|
||||||
y := 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() {
|
for _, m := range glfw.GetMonitors() {
|
||||||
mx, my := m.GetPos()
|
mx, my := m.GetPos()
|
||||||
if int(x) == mx && int(y) == my {
|
if int(x) == mx && int(y) == my {
|
||||||
|
@ -122,6 +122,7 @@ func adjustWindowPosition(x, y int) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
|
func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
|
||||||
|
// TODO: Should we use u.window.GetWin32Window() here?
|
||||||
w, err := getActiveWindow()
|
w, err := getActiveWindow()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user