forked from xyproto/wallutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfce4.go
47 lines (40 loc) · 1.16 KB
/
xfce4.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
package wallutils
import (
"errors"
"fmt"
"strings"
)
// Xfce4 windowmanager detector
type Xfce4 struct {
verbose bool
}
func (x *Xfce4) Name() string {
return "Xfce4"
}
func (x *Xfce4) ExecutablesExists() bool {
return (which("xfconf-query") != "") && (which("xfce4-session") != "")
}
func (x *Xfce4) Running() bool {
return (containsE("GDMSESSION", "xfce") || containsE("XDG_SESSION_DESKTOP", "xfce") || containsE("DESKTOP_SESSION", "xfce"))
}
func (x *Xfce4) SetVerbose(verbose bool) {
x.verbose = verbose
}
// SetWallpaper sets the desktop wallpaper, given an image filename.
// The image must exist and be readable.
func (x *Xfce4) SetWallpaper(imageFilename string) error {
command := "xfconf-query --channel xfce4-desktop --list"
properties := strings.Split(output(command, x.verbose), "\n")
if len(properties) == 0 {
return errors.New("Could not list any properties for Xfce4")
}
for _, prop := range properties {
if strings.HasSuffix(prop, "/last-image") {
command = fmt.Sprintf("xfconf-query --channel xfce4-desktop --property %s --set %q", prop, imageFilename)
if err := run(command, x.verbose); err != nil {
return err
}
}
}
return nil
}