-
Notifications
You must be signed in to change notification settings - Fork 17
/
pekwm.go
78 lines (64 loc) · 2.03 KB
/
pekwm.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
package wallutils
// This is for Pekwm 0.2.0 or later
import (
"errors"
"fmt"
"github.com/xyproto/env/v2"
)
// Pekwm is a structure containing settings for running the "pekwm_bg" executable
type Pekwm struct {
mode string
verbose bool
}
// Name returns the name of this method of setting a wallpaper
func (f *Pekwm) Name() string {
return "Pekwm"
}
// ExecutablesExists checks if the "pekwm_bg" executable exists in the PATH
// (comes with pekwm 0.2.0 or later)
func (f *Pekwm) ExecutablesExists() bool {
return which("pekwm_bg") != ""
}
// Running checks if $PEKWM_CONFIG_FILE is set
func (f *Pekwm) Running() bool {
return env.Has("PEKWM_CONFIG_FILE")
}
// SetMode will set the current way to display the wallpaper (stretched, tiled etc).
// The selected mode must be compatible with pekwm_bg.
func (f *Pekwm) SetMode(mode string) {
f.mode = mode
}
// SetVerbose can be used for setting the verbose field to true or false.
// This will cause this backend to output information about what is is doing on stdout.
func (f *Pekwm) SetVerbose(verbose bool) {
f.verbose = verbose
}
// SetWallpaper sets the desktop wallpaper, given an image filename.
// The image must exist and be readable.
func (f *Pekwm) SetWallpaper(imageFilename string) error {
if !exists(imageFilename) {
return fmt.Errorf("no such file: %s", imageFilename)
}
mode := defaultMode
if f.mode != "" {
mode = f.mode
}
// Images are set with ie. "pekwm_bg Image /somewhere/image.png#scaled"
var tag string
// check if the mode is valid
switch mode {
case "stretch", "stretched", "scaled", "fill", "scale", "max":
tag = "#scaled"
case "tile", "tiled":
// pekwm_bg tiles by default
break
default:
// Invalid and unrecognized desktop wallpaper mode
return fmt.Errorf("invalid desktop wallpaper mode for Pekwm: %s", mode)
}
// set the wallpaper with pekwm_bg
if err := run("pekwm_bg", []string{"-D", "Image", imageFilename + tag}, f.verbose); err != nil {
return errors.New("pekwm_bg -D Image \"" + imageFilename + tag + "\" failed to run")
}
return nil
}