mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
devicescale: Remove the updating loop
Now the value is cached, the updating loop is no longer needed.
This commit is contained in:
parent
5c85c1466a
commit
9a31bcd53d
@ -19,14 +19,11 @@
|
|||||||
package devicescale
|
package devicescale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type desktop int
|
type desktop int
|
||||||
@ -40,29 +37,6 @@ const (
|
|||||||
desktopXfce
|
desktopXfce
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
cachedScale uint64 // use atomic to read/write as multiple goroutines touch it.
|
|
||||||
cacheUpdateWait = time.Millisecond * 100
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
|
|
||||||
func currentDesktop() desktop {
|
func currentDesktop() desktop {
|
||||||
tokens := strings.Split(os.Getenv("XDG_CURRENT_DESKTOP"), ":")
|
tokens := strings.Split(os.Getenv("XDG_CURRENT_DESKTOP"), ":")
|
||||||
switch tokens[len(tokens)-1] {
|
switch tokens[len(tokens)-1] {
|
||||||
@ -121,7 +95,7 @@ func cinnamonScale() float64 {
|
|||||||
return float64(s)
|
return float64(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getscale(x, y int) float64 {
|
func impl(x, y int) float64 {
|
||||||
s := -1.0
|
s := -1.0
|
||||||
switch currentDesktop() {
|
switch currentDesktop() {
|
||||||
case desktopGnome:
|
case desktopGnome:
|
||||||
|
Loading…
Reference in New Issue
Block a user