forked from reujab/wallpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfce.go
87 lines (75 loc) · 1.66 KB
/
xfce.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package wallpaper
import (
"os/exec"
"path"
"strings"
)
func getXFCEProps(key string) ([]string, error) {
output, err := exec.Command("xfconf-query", "--channel", "xfce4-desktop", "--list").Output()
if err != nil {
return nil, err
}
lines := strings.Split(strings.Trim(string(output), "\n"), "\n")
var desktops []string
for _, line := range lines {
if path.Base(line) == key {
desktops = append(desktops, line)
}
}
return desktops, nil
}
func getXFCE() (string, error) {
desktops, err := getXFCEProps("last-image")
if err != nil || len(desktops) == 0 {
return "", err
}
output, err := exec.Command("xfconf-query", "--channel", "xfce4-desktop", "--property", desktops[0]).Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(output)), nil
}
func setXFCE(file string) error {
desktops, err := getXFCEProps("last-image")
if err != nil {
return err
}
for _, desktop := range desktops {
err := exec.Command("xfconf-query", "--channel", "xfce4-desktop", "--property", desktop, "--set", file).Run()
if err != nil {
return err
}
}
return nil
}
func setXFCEMode(mode Mode) error {
styles, err := getXFCEProps("image-style")
if err != nil {
return err
}
for _, style := range styles {
err = exec.Command("xfconf-query", "--channel", "xfce4-desktop", "--property", style, "--set", mode.getXFCEString()).Run()
if err != nil {
return err
}
}
return nil
}
func (mode Mode) getXFCEString() string {
switch mode {
case Center:
return "1"
case Crop:
return "5"
case Fit:
return "4"
case Span:
return "5"
case Stretch:
return "3"
case Tile:
return "2"
default:
panic("invalid wallpaper mode")
}
}