ui: Use more stable way to determine the current monitor

This commit is contained in:
Hajime Hoshi 2018-10-06 19:53:01 +09:00
parent 55a397bd65
commit cc336a4c38

View File

@ -767,7 +767,7 @@ func (u *userInterface) forceSetScreenSize(width, height int, scale float64, ful
u.toChangeSize = true u.toChangeSize = true
} }
// currentMonitor returns the monitor nearest from the current window. // currentMonitor returns the monitor most suitable from the current window.
// //
// 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 {
@ -777,21 +777,12 @@ func (u *userInterface) currentMonitor() *glfw.Monitor {
} }
wx, wy := w.GetPos() wx, wy := w.GetPos()
ww, wh := w.GetSize()
wr := image.Rect(wx, wy, wx+ww, wy+wh)
best := -1
var current *glfw.Monitor
for _, m := range glfw.GetMonitors() { for _, m := range glfw.GetMonitors() {
mx, my := m.GetPos() mx, my := m.GetPos()
v := m.GetVideoMode() v := m.GetVideoMode()
mr := image.Rect(mx, my, mx+v.Width, my+v.Height) if mx <= wx && wx < mx+v.Width && my <= wy && wy < my+v.Height {
overlap := wr.Intersect(mr) return m
area := overlap.Dx() * overlap.Dy()
if area > best {
current = m
best = area
} }
} }
return current return glfw.GetPrimaryMonitor()
} }