From 836e320b6b0781bba7da1d24360557c6f1d23eb9 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 5 May 2019 18:09:49 +0900 Subject: [PATCH] devicescale: Refactoring --- internal/devicescale/impl_unix.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/devicescale/impl_unix.go b/internal/devicescale/impl_unix.go index 521dc741a..51d943306 100644 --- a/internal/devicescale/impl_unix.go +++ b/internal/devicescale/impl_unix.go @@ -46,23 +46,23 @@ var ( ) func init() { - go scaleUpdater() + // Run as goroutine. Will keep the desktop scale up to date. + // This can be removed once the scale change event is implemented in GLFW 3.3 + // + // TODO: Now the value is cached, isn't this loop needed? + go func() { + for { + s := getscale(0, 0) + atomic.StoreUint64(&cachedScale, math.Float64bits(s)) + time.Sleep(cacheUpdateWait) + } + }() } func impl(x, y int) float64 { return math.Float64frombits(atomic.LoadUint64(&cachedScale)) } -// run as goroutine. Will keep the desktop scale up to date. -// This can be removed once the scale change event is implemented in GLFW 3.3 -func scaleUpdater() { - for { - s := getscale(0, 0) - atomic.StoreUint64(&cachedScale, math.Float64bits(s)) - time.Sleep(cacheUpdateWait) - } -} - func currentDesktop() desktop { tokens := strings.Split(os.Getenv("XDG_CURRENT_DESKTOP"), ":") switch tokens[len(tokens)-1] {