-
Notifications
You must be signed in to change notification settings - Fork 17
/
gnome2.go
75 lines (64 loc) · 2.11 KB
/
gnome2.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
package wallutils
import (
"fmt"
"os"
)
// Gnome2 windowmanager detector
type Gnome2 struct {
mode string
verbose bool
}
// Name returns the name of this window manager or desktop environment
func (g2 *Gnome2) Name() string {
return "Gnome2"
}
// ExecutablesExists checks if executables associated with this backend exists in the PATH
func (g2 *Gnome2) ExecutablesExists() bool {
return which("gconftool-2") != ""
}
// Running examines environment variables to try to figure out if this backend is currently running
func (g2 *Gnome2) Running() bool {
return (os.Getenv("GDMSESSION") == "gnome") || (os.Getenv("DESKTOP_SESSION") == "gnome")
}
// SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (g2 *Gnome2) SetMode(mode string) {
g2.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 (g2 *Gnome2) SetVerbose(verbose bool) {
g2.verbose = verbose
}
// SetWallpaper sets the desktop wallpaper, given an image filename.
// The image must exist and be readable.
func (g2 *Gnome2) SetWallpaper(imageFilename string) error {
if !exists(imageFilename) {
return fmt.Errorf("no such file: %s", imageFilename)
}
// initialize the mode setting (stretched/tiled etc)
mode := defaultMode
if g2.mode != "" {
mode = g2.mode
}
switch mode {
case "none", "wallpaper", "centered", "scaled", "stretched", "zoom", "spanned":
break
case "stretch":
mode = "stretched"
case "center":
mode = "centered"
case "fill", "scale":
mode = "scaled"
case "tile":
mode = "wallpaper"
default:
// Invalid and unrecognized desktop wallpaper mode
return fmt.Errorf("invalid desktop wallpaper mode for GNOME2: %s", mode)
}
// Set the wallpaper mode
if err := run("gconftool-2", []string{"--type", "string", "--set", "/desktop/gnome/background/picture_options", mode}, g2.verbose); err != nil {
return err
}
// Set the wallpaper image
return run("gconftool-2", []string{"--type", "string", "--set", "/desktop/gnome/background/picture_filename", imageFilename}, g2.verbose)
}