-
Notifications
You must be signed in to change notification settings - Fork 40
/
gnome.go
55 lines (47 loc) · 1.05 KB
/
gnome.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package wallpaper
import (
"os/exec"
"strings"
yaml "gopkg.in/yaml.v2"
)
func removeProtocol(input string) string {
if len(input) >= 7 && input[:7] == "file://" {
return input[7:]
}
return input
}
func parseDconf(command string, args ...string) (string, error) {
output, err := exec.Command(command, args...).Output()
if err != nil {
return "", err
}
// unquote string
var unquoted string
// the output is quoted with single quotes, which cannot be unquoted using strconv.Unquote, but it is valid yaml
err = yaml.UnmarshalStrict(output, &unquoted)
if err != nil {
return unquoted, err
}
return removeProtocol(unquoted), nil
}
func isGNOMECompliant() bool {
return strings.Contains(Desktop, "GNOME") || Desktop == "Unity" || Desktop == "Pantheon"
}
func (mode Mode) getGNOMEString() string {
switch mode {
case Center:
return "centered"
case Crop:
return "zoom"
case Fit:
return "scaled"
case Span:
return "spanned"
case Stretch:
return "stretched"
case Tile:
return "wallpaper"
default:
panic("invalid wallpaper mode")
}
}