mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
internal/ui: make currentMonitor return initMonitor when the window is not initialized yet
This commit is contained in:
parent
b2872f216a
commit
180eb483bb
@ -1316,18 +1316,19 @@ func (u *UserInterface) updateVsync() {
|
|||||||
//
|
//
|
||||||
// currentMonitor must be called on the main thread.
|
// currentMonitor must be called on the main thread.
|
||||||
func (u *UserInterface) currentMonitor() *glfw.Monitor {
|
func (u *UserInterface) currentMonitor() *glfw.Monitor {
|
||||||
if !u.isRunning() {
|
if u.window == nil {
|
||||||
return u.initMonitor
|
return u.initMonitor
|
||||||
}
|
}
|
||||||
return currentMonitorImpl(u.window)
|
if m := monitorFromWindow(u.window); m != nil {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
return glfw.GetPrimaryMonitor()
|
||||||
}
|
}
|
||||||
|
|
||||||
// currentMonitorImpl returns the current active monitor.
|
// monitorFromWindow returns the monitor from the given window.
|
||||||
//
|
//
|
||||||
// The given window might or might not be used to detect the monitor.
|
// monitorFromWindow must be called on the main thread.
|
||||||
//
|
func monitorFromWindow(window *glfw.Window) *glfw.Monitor {
|
||||||
// currentMonitorImpl must be called on the main thread.
|
|
||||||
func currentMonitorImpl(window *glfw.Window) *glfw.Monitor {
|
|
||||||
// GetMonitor is available only in fullscreen.
|
// GetMonitor is available only in fullscreen.
|
||||||
if m := window.GetMonitor(); m != nil {
|
if m := window.GetMonitor(); m != nil {
|
||||||
return m
|
return m
|
||||||
@ -1336,7 +1337,7 @@ func currentMonitorImpl(window *glfw.Window) *glfw.Monitor {
|
|||||||
// Getting a monitor from a window position is not reliable in general (e.g., when a window is put across
|
// Getting a monitor from a window position is not reliable in general (e.g., when a window is put across
|
||||||
// multiple monitors, or, before SetWindowPosition is called.).
|
// multiple monitors, or, before SetWindowPosition is called.).
|
||||||
// Get the monitor which the current window belongs to. This requires OS API.
|
// Get the monitor which the current window belongs to. This requires OS API.
|
||||||
if m := currentMonitorByOS(window); m != nil {
|
if m := monitorFromWindowByOS(window); m != nil {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1344,7 +1345,8 @@ func currentMonitorImpl(window *glfw.Window) *glfw.Monitor {
|
|||||||
if m := getMonitorFromPosition(window.GetPos()); m != nil {
|
if m := getMonitorFromPosition(window.GetPos()); m != nil {
|
||||||
return m.m
|
return m.m
|
||||||
}
|
}
|
||||||
return glfw.GetPrimaryMonitor()
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) SetScreenTransparent(transparent bool) {
|
func (u *UserInterface) SetScreenTransparent(transparent bool) {
|
||||||
|
@ -183,11 +183,9 @@ func initialMonitorByOS() (*glfw.Monitor, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
func monitorFromWindowByOS(w *glfw.Window) *glfw.Monitor {
|
||||||
var x, y C.int
|
var x, y C.int
|
||||||
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here.
|
C.currentMonitorPos(C.uintptr_t(w.GetCocoaWindow()), &x, &y)
|
||||||
win := w.GetCocoaWindow()
|
|
||||||
C.currentMonitorPos(C.uintptr_t(win), &x, &y)
|
|
||||||
for _, m := range ensureMonitors() {
|
for _, m := range ensureMonitors() {
|
||||||
if int(x) == m.x && int(y) == m.y {
|
if int(x) == m.x && int(y) == m.y {
|
||||||
return m.m
|
return m.m
|
||||||
|
@ -159,7 +159,7 @@ func initialMonitorByOS() (*glfw.Monitor, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
|
func monitorFromWindowByOS(_ *glfw.Window) *glfw.Monitor {
|
||||||
// TODO: Implement this correctly. (#1119).
|
// TODO: Implement this correctly. (#1119).
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ func getSystemMetrics(nIndex int) (int32, error) {
|
|||||||
return int32(r), nil
|
return int32(r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func monitorFromWindow(hwnd windows.HWND, dwFlags uint32) uintptr {
|
func monitorFromWindow_(hwnd windows.HWND, dwFlags uint32) uintptr {
|
||||||
r, _, _ := procMonitorFromWindow.Call(uintptr(hwnd), uintptr(dwFlags))
|
r, _, _ := procMonitorFromWindow.Call(uintptr(hwnd), uintptr(dwFlags))
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ func initialMonitorByOS() (*glfw.Monitor, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
func monitorFromWindowByOS(w *glfw.Window) *glfw.Monitor {
|
||||||
return monitorFromWin32Window(windows.HWND(w.GetWin32Window()))
|
return monitorFromWin32Window(windows.HWND(w.GetWin32Window()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ func monitorFromWin32Window(w windows.HWND) *glfw.Monitor {
|
|||||||
// Get the current monitor by the window handle instead of the window position. It is because the window
|
// Get the current monitor by the window handle instead of the window position. It is because the window
|
||||||
// position is not relaiable in some cases e.g. when the window is put across multiple monitors.
|
// position is not relaiable in some cases e.g. when the window is put across multiple monitors.
|
||||||
|
|
||||||
m := monitorFromWindow(w, monitorDefaultToNearest)
|
m := monitorFromWindow_(w, monitorDefaultToNearest)
|
||||||
if m == 0 {
|
if m == 0 {
|
||||||
// monitorFromWindow can return error on Wine. Ignore this.
|
// monitorFromWindow can return error on Wine. Ignore this.
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user