devicescale: Detect window manager

This commit is contained in:
Hajime Hoshi 2018-01-04 00:01:41 +09:00
parent eac5564342
commit 70f9fee8af

View File

@ -19,11 +19,31 @@
package devicescale package devicescale
import ( import (
"os"
"os/exec" "os/exec"
"regexp" "regexp"
"strconv" "strconv"
) )
type windowManager int
const (
windowManagerUnknown windowManager = iota
windowManagerGnome
windowManagerCinnamon
)
func currentWindowManager() windowManager {
switch os.Getenv("XDG_CURRENT_DESKTOP") {
case "GNOME":
return windowManagerGnome
case "X-Cinnamon":
return windowManagerCinnamon
default:
return windowManagerUnknown
}
}
var gsettingsRe = regexp.MustCompile(`\Auint32 (\d+)\s*\z`) var gsettingsRe = regexp.MustCompile(`\Auint32 (\d+)\s*\z`)
func gnomeScale() float64 { func gnomeScale() float64 {
@ -65,15 +85,19 @@ func cinnamonScale() float64 {
} }
func impl() float64 { func impl() float64 {
scale := 0.0 switch currentWindowManager() {
if s := gnomeScale(); s > scale { case windowManagerGnome:
scale = s s := gnomeScale()
if s <= 0 {
return 1
}
return s
case windowManagerCinnamon:
s := cinnamonScale()
if s <= 0 {
return 1
}
return s
} }
if s := cinnamonScale(); s > scale { return 1
scale = s
}
if scale == 0 {
return 1
}
return scale
} }