From cc336a4c38e1c77ff506d4bc063b7ec348269dfa Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 6 Oct 2018 19:53:01 +0900 Subject: [PATCH] ui: Use more stable way to determine the current monitor --- internal/ui/ui_glfw.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index ee17e036d..f25524abb 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -767,7 +767,7 @@ func (u *userInterface) forceSetScreenSize(width, height int, scale float64, ful 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. func (u *userInterface) currentMonitor() *glfw.Monitor { @@ -777,21 +777,12 @@ func (u *userInterface) currentMonitor() *glfw.Monitor { } 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() { mx, my := m.GetPos() v := m.GetVideoMode() - mr := image.Rect(mx, my, mx+v.Width, my+v.Height) - overlap := wr.Intersect(mr) - area := overlap.Dx() * overlap.Dy() - if area > best { - current = m - best = area + if mx <= wx && wx < mx+v.Width && my <= wy && wy < my+v.Height { + return m } } - return current + return glfw.GetPrimaryMonitor() }