mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Revert "internal/uidriver/glfw: Refactoring: use glfw.Window when possible"
This reverts commit 475453d5d2
.
Reason: #1584: A wrong active monitor was detected at the initial phase?
Closes #1584
This commit is contained in:
parent
45642668f7
commit
26432dfc9e
@ -44,9 +44,11 @@ type monitorInfo struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// user32 is defined at hideconsole_windows.go
|
// user32 is defined at hideconsole_windows.go
|
||||||
procGetSystemMetrics = user32.NewProc("GetSystemMetrics")
|
procGetSystemMetrics = user32.NewProc("GetSystemMetrics")
|
||||||
procMonitorFromWindow = user32.NewProc("MonitorFromWindow")
|
procGetActiveWindow = user32.NewProc("GetActiveWindow")
|
||||||
procGetMonitorInfoW = user32.NewProc("GetMonitorInfoW")
|
procGetForegroundWindow = user32.NewProc("GetForegroundWindow")
|
||||||
|
procMonitorFromWindow = user32.NewProc("MonitorFromWindow")
|
||||||
|
procGetMonitorInfoW = user32.NewProc("GetMonitorInfoW")
|
||||||
)
|
)
|
||||||
|
|
||||||
func getSystemMetrics(nIndex int) (int, error) {
|
func getSystemMetrics(nIndex int) (int, error) {
|
||||||
@ -57,6 +59,22 @@ func getSystemMetrics(nIndex int) (int, error) {
|
|||||||
return int(r), nil
|
return int(r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getActiveWindow() (uintptr, error) {
|
||||||
|
r, _, e := procGetActiveWindow.Call()
|
||||||
|
if e != nil && e.(windows.Errno) != 0 {
|
||||||
|
return 0, fmt.Errorf("ui: GetActiveWindow failed: error code: %d", e)
|
||||||
|
}
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getForegroundWindow() (uintptr, error) {
|
||||||
|
r, _, e := procGetForegroundWindow.Call()
|
||||||
|
if e != nil && e.(windows.Errno) != 0 {
|
||||||
|
return 0, fmt.Errorf("ui: GetForegroundWindow failed: error code: %d", e)
|
||||||
|
}
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
func monitorFromWindow(hwnd uintptr, dwFlags uint32) (uintptr, error) {
|
func monitorFromWindow(hwnd uintptr, dwFlags uint32) (uintptr, error) {
|
||||||
r, _, e := procMonitorFromWindow.Call(hwnd, uintptr(dwFlags))
|
r, _, e := procMonitorFromWindow.Call(hwnd, uintptr(dwFlags))
|
||||||
if e != nil && e.(windows.Errno) != 0 {
|
if e != nil && e.(windows.Errno) != 0 {
|
||||||
@ -116,11 +134,30 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
|||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
|
||||||
|
// TODO: Should we return nil here?
|
||||||
|
w, err := getActiveWindow()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if w == 0 {
|
||||||
|
// The active window doesn't exist when launching, or the application is runnable on unfocused.
|
||||||
|
// Get the foreground window, that is common among multiple processes.
|
||||||
|
w, err = getForegroundWindow()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if w == 0 {
|
||||||
|
// GetForegroundWindow can return null according to the document.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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, err := monitorFromWindow(w.GetWin32Window(), monitorDefaultToNearest)
|
m, err := monitorFromWindow(w, monitorDefaultToNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 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