-
Notifications
You must be signed in to change notification settings - Fork 41
/
linux.go
96 lines (86 loc) · 2.81 KB
/
linux.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
88
89
90
91
92
93
94
95
96
// +build linux
package wallpaper
import (
"os/exec"
"os/user"
"path/filepath"
"strconv"
)
// Get returns the current wallpaper.
func Get() (string, error) {
if isGNOMECompliant() {
return parseDconf("gsettings", "get", "org.gnome.desktop.background", "picture-uri")
}
switch Desktop {
case "KDE":
return getKDE()
case "X-Cinnamon":
return parseDconf("dconf", "read", "/org/cinnamon/desktop/background/picture-uri")
case "MATE":
return parseDconf("dconf", "read", "/org/mate/desktop/background/picture-filename")
case "XFCE":
return getXFCE()
case "LXDE":
return getLXDE()
case "Deepin":
return parseDconf("dconf", "read", "/com/deepin/wrap/gnome/desktop/background/picture-uri")
default:
return "", ErrUnsupportedDE
}
}
// SetFromFile sets wallpaper from a file path.
func SetFromFile(file string) error {
if isGNOMECompliant() {
return exec.Command("gsettings", "set", "org.gnome.desktop.background", "picture-uri", strconv.Quote("file://"+file)).Run()
}
switch Desktop {
case "KDE":
return setKDE(file)
case "X-Cinnamon":
return exec.Command("dconf", "write", "/org/cinnamon/desktop/background/picture-uri", strconv.Quote("file://"+file)).Run()
case "MATE":
return exec.Command("dconf", "write", "/org/mate/desktop/background/picture-filename", strconv.Quote(file)).Run()
case "XFCE":
return setXFCE(file)
case "LXDE":
return exec.Command("pcmanfm", "-w", file).Run()
case "Deepin":
return exec.Command("dconf", "write", "/com/deepin/wrap/gnome/desktop/background/picture-uri", strconv.Quote("file://"+file)).Run()
default:
err := exec.Command("swaybg", "-i", file).Start()
// if the command completed successfully, return
if err == nil {
return nil
}
return exec.Command("feh", "-bg-fill", file).Run()
}
}
// SetMode sets the wallpaper mode.
func SetMode(mode Mode) error {
if isGNOMECompliant() {
return exec.Command("gsettings", "set", "org.gnome.desktop.background", "picture-options", strconv.Quote(mode.getGNOMEString())).Run()
}
switch Desktop {
case "KDE":
return setKDEMode(mode)
case "X-Cinnamon":
return exec.Command("dconf", "write", "/org/cinnamon/desktop/background/picture-options", strconv.Quote(mode.getGNOMEString())).Run()
case "MATE":
return exec.Command("dconf", "write", "/org/mate/desktop/background/picture-options", strconv.Quote(mode.getGNOMEString())).Run()
case "XFCE":
return setXFCEMode(mode)
case "LXDE":
return exec.Command("pcmanfm", "--wallpaper-mode", mode.getLXDEString()).Run()
case "Deepin":
return exec.Command("dconf", "write", "/com/deepin/wrap/gnome/desktop/background/picture-options", strconv.Quote(mode.getGNOMEString())).Run()
default:
return ErrUnsupportedDE
}
}
func getCacheDir() (string, error) {
usr, err := user.Current()
if err != nil {
return "", err
}
return filepath.Join(usr.HomeDir, ".cache"), nil
}