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
import (
"os"
"os/exec"
"regexp"
"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`)
func gnomeScale() float64 {
@ -65,15 +85,19 @@ func cinnamonScale() float64 {
}
func impl() float64 {
scale := 0.0
if s := gnomeScale(); s > scale {
scale = s
switch currentWindowManager() {
case windowManagerGnome:
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 {
scale = s
}
if scale == 0 {
return 1
}
return scale
return 1
}