mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
ui: Bug fix: DeviceScaleFactor and MonitorSize were not correct on Windows
This commit is contained in:
parent
9264e38324
commit
96a657025f
@ -55,5 +55,5 @@ func currentMonitor() *glfw.Monitor {
|
||||
return m
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return glfw.GetPrimaryMonitor()
|
||||
}
|
||||
|
@ -44,5 +44,5 @@ func currentMonitor() *glfw.Monitor {
|
||||
return m
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return glfw.GetPrimaryMonitor()
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ var (
|
||||
// user32 is defined at hideconsole_windows.go
|
||||
procGetSystemMetrics = user32.NewProc("GetSystemMetrics")
|
||||
procGetActiveWindow = user32.NewProc("GetActiveWindow")
|
||||
procGetForegroundWindow = user32.NewProc("GetForegroundWindow")
|
||||
procMonitorFromWindow = user32.NewProc("MonitorFromWindow")
|
||||
procGetMonitorInfoW = user32.NewProc("GetMonitorInfoW")
|
||||
)
|
||||
@ -69,6 +70,14 @@ func getActiveWindow() (uintptr, error) {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func getForegroundWindow() (uintptr, error) {
|
||||
r, _, e := syscall.Syscall(procGetForegroundWindow.Addr(), 0, 0, 0, 0)
|
||||
if e != 0 {
|
||||
return 0, fmt.Errorf("ui: GetForegroundWindow failed: error code: %d", e)
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func monitorFromWindow(hwnd uintptr, dwFlags uint32) (uintptr, error) {
|
||||
r, _, e := syscall.Syscall(procMonitorFromWindow.Addr(), 2, hwnd, uintptr(dwFlags), 0)
|
||||
if e != 0 {
|
||||
@ -118,10 +127,18 @@ func currentMonitor() *glfw.Monitor {
|
||||
panic(err)
|
||||
}
|
||||
if w == 0 {
|
||||
// There is no window at launching.
|
||||
// TODO: Use glfw.GetCurrentContext() like currentMonitor() in ui_unix.go.
|
||||
// There is no window at launching, but there is a hidden initialized window.
|
||||
// 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. Use
|
||||
// the primary monitor instead.
|
||||
return glfw.GetPrimaryMonitor()
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
@ -144,5 +161,5 @@ func currentMonitor() *glfw.Monitor {
|
||||
return m
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return glfw.GetPrimaryMonitor()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user