uidriver/glfw: Bug fix: Do not use the window position for monitors

Especially in the initial phase before calling Run/RunGame, the
window position is not reliable and then getting the device scale
factor does not make sense based on the window position. Avoid
using the window position, and instead use the glfw.Monitor.
This commit is contained in:
Hajime Hoshi 2020-03-28 21:13:25 +09:00
parent 7b5fb0a0d0
commit 0a5126f776

View File

@ -180,9 +180,9 @@ func cacheMonitors() {
// returns false if monitor is not found. // returns false if monitor is not found.
// //
// getCachedMonitor must be called on the main thread. // getCachedMonitor must be called on the main thread.
func getCachedMonitor(wx, wy int) (*cachedMonitor, bool) { func getCachedMonitor(glfwMonitor *glfw.Monitor) (*cachedMonitor, bool) {
for _, m := range monitors { for _, m := range monitors {
if m.x <= wx && wx < m.x+m.vm.Width && m.y <= wy && wy < m.y+m.vm.Height { if m.m == glfwMonitor {
return m, true return m, true
} }
} }
@ -537,7 +537,7 @@ func (u *UserInterface) DeviceScaleFactor() float64 {
// deviceScaleFactor must be called from the main thread. // deviceScaleFactor must be called from the main thread.
func (u *UserInterface) deviceScaleFactor() float64 { func (u *UserInterface) deviceScaleFactor() float64 {
// Avoid calling monitor.GetPos if we have the monitor position cached already. // Avoid calling monitor.GetPos if we have the monitor position cached already.
if cm, ok := getCachedMonitor(u.window.GetPos()); ok { if cm, ok := getCachedMonitor(u.window.GetMonitor()); ok {
return devicescale.GetAt(cm.x, cm.y) return devicescale.GetAt(cm.x, cm.y)
} }
// TODO: When is this reached? // TODO: When is this reached?