forked from reujab/wallpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkde.go
60 lines (51 loc) · 1.15 KB
/
kde.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
//+build linux
package wallpaper
import (
"bufio"
"errors"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
)
func parseKDEConfig() (string, error) {
usr, err := user.Current()
if err != nil {
return "", err
}
filename := filepath.Join(usr.HomeDir, ".config", "plasma-org.kde.plasma.desktop-appletsrc")
if err != nil {
return "", err
}
file, err := os.Open(filename)
if err != nil {
return "", err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if len(line) >= 6 && line[:6] == "Image=" {
return strings.TrimSpace(removeProtocol(line[6:])), nil
}
}
if scanner.Err() != nil {
return "", scanner.Err()
}
err = file.Close()
if err != nil {
return "", err
}
return "", errors.New("kde image not found")
}
func setKDEBackground(uri string) error {
return exec.Command("qdbus", "org.kde.plasmashell", "/PlasmaShell", "org.kde.PlasmaShell.evaluateScript", `
const monitors = desktops()
for (var i = 0; i < monitors.length; i++) {
monitors[i].currentConfigGroup = ["Wallpaper"]
monitors[i].writeConfig("Image", `+strconv.Quote(uri)+`)
}
`).Run()
}