uidriver/glfw: Refactoring

This commit is contained in:
Hajime Hoshi 2020-08-24 03:05:38 +09:00
parent af6961fc17
commit 9bff1c79be
4 changed files with 9 additions and 9 deletions

View File

@ -186,17 +186,17 @@ func cacheMonitors() {
}
}
// getCachedMonitor returns a monitor for the given window x/y
// returns false if monitor is not found.
// getCachedMonitor returns a monitor for the given window x/y,
// or returns nil if monitor is not found.
//
// getCachedMonitor must be called on the main thread.
func getCachedMonitor(wx, wy int) (*cachedMonitor, bool) {
func getCachedMonitor(wx, wy int) *cachedMonitor {
for _, m := range monitors {
if m.x <= wx && wx < m.x+m.vm.Width && m.y <= wy && wy < m.y+m.vm.Height {
return m, true
return m
}
}
return nil, false
return nil
}
func (u *UserInterface) isRunning() bool {
@ -583,7 +583,7 @@ func (u *UserInterface) deviceScaleFactor() float64 {
// Before calling SetWindowPosition, the window's position is not reliable.
if u.iwindow.setPositionCalled {
// Avoid calling monitor.GetPos if we have the monitor position cached already.
if cm, ok := getCachedMonitor(u.window.GetPos()); ok {
if cm := getCachedMonitor(u.window.GetPos()); cm != nil {
return devicescale.GetAt(cm.x, cm.y)
}
}

View File

@ -68,7 +68,7 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
}
}
if m, ok := getCachedMonitor(w.GetPos()); ok {
if m := getCachedMonitor(w.GetPos()); m != nil {
return m.m
}
return glfw.GetPrimaryMonitor()

View File

@ -34,7 +34,7 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
// TODO: Implement this correctly. (#1119).
if cm, ok := getCachedMonitor(w.GetPos()); ok {
if cm := getCachedMonitor(w.GetPos()); cm != nil {
return cm.m
}
return glfw.GetPrimaryMonitor()

View File

@ -122,7 +122,7 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
func currentMonitorByOS(glfww *glfw.Window) *glfw.Monitor {
fallback := func() *glfw.Monitor {
if m, ok := getCachedMonitor(glfww.GetPos()); ok {
if m := getCachedMonitor(glfww.GetPos()); m != nil {
return m.m
}
return glfw.GetPrimaryMonitor()