From d2595c5be7fc17a557ecd4fbad752d6cf9d67d9f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 15 Nov 2018 01:08:36 +0900 Subject: [PATCH] ui: Refactoring --- internal/ui/ui_glfw.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index bde779d56..f87333bf4 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -132,10 +132,12 @@ type cachedMonitor struct { // monitors is the monitor list cache for desktop glfw compile targets. // populated by 'cacheMonitors' which is called on init and every // monitor config change event. +// +// monitors must be manipulated on the main thread. var monitors []*cachedMonitor func cacheMonitors() { - monitors = make([]*cachedMonitor, 0, 3) + monitors = nil ms := glfw.GetMonitors() for _, m := range ms { x, y := m.GetPos() @@ -150,6 +152,8 @@ func cacheMonitors() { // getCachedMonitor returns a monitor for the given window x/y // returns false if monitor is not found. +// +// getCachedMonitor must be called on the main thread. func getCachedMonitor(wx, wy int) (*cachedMonitor, bool) { for _, m := range monitors { if m.x <= wx && wx < m.x+m.vm.Width && m.y <= wy && wy < m.y+m.vm.Height {