mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +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 m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return glfw.GetPrimaryMonitor()
|
||||||
}
|
}
|
||||||
|
@ -44,5 +44,5 @@ func currentMonitor() *glfw.Monitor {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return glfw.GetPrimaryMonitor()
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,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")
|
||||||
procGetActiveWindow = user32.NewProc("GetActiveWindow")
|
procGetActiveWindow = user32.NewProc("GetActiveWindow")
|
||||||
procMonitorFromWindow = user32.NewProc("MonitorFromWindow")
|
procGetForegroundWindow = user32.NewProc("GetForegroundWindow")
|
||||||
procGetMonitorInfoW = user32.NewProc("GetMonitorInfoW")
|
procMonitorFromWindow = user32.NewProc("MonitorFromWindow")
|
||||||
|
procGetMonitorInfoW = user32.NewProc("GetMonitorInfoW")
|
||||||
)
|
)
|
||||||
|
|
||||||
func getSystemMetrics(nIndex int) (int, error) {
|
func getSystemMetrics(nIndex int) (int, error) {
|
||||||
@ -69,6 +70,14 @@ func getActiveWindow() (uintptr, error) {
|
|||||||
return r, nil
|
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) {
|
func monitorFromWindow(hwnd uintptr, dwFlags uint32) (uintptr, error) {
|
||||||
r, _, e := syscall.Syscall(procMonitorFromWindow.Addr(), 2, hwnd, uintptr(dwFlags), 0)
|
r, _, e := syscall.Syscall(procMonitorFromWindow.Addr(), 2, hwnd, uintptr(dwFlags), 0)
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
@ -118,9 +127,17 @@ func currentMonitor() *glfw.Monitor {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if w == 0 {
|
if w == 0 {
|
||||||
// There is no window at launching.
|
// There is no window at launching, but there is a hidden initialized window.
|
||||||
// TODO: Use glfw.GetCurrentContext() like currentMonitor() in ui_unix.go.
|
// Get the foreground window, that is common among multiple processes.
|
||||||
return glfw.GetPrimaryMonitor()
|
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
|
// Get the current monitor by the window handle instead of the window position. It is because the window
|
||||||
@ -144,5 +161,5 @@ func currentMonitor() *glfw.Monitor {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return glfw.GetPrimaryMonitor()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user