summary refs log tree commit diff stats
path: root/background/set_unix.go
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-24 18:35:27 +0530
committerAndinus <andinus@nand.sh>2020-03-24 18:35:27 +0530
commitbf040f6d1c8c7bc33d5268db42bc2ac9016e2198 (patch)
tree76006187821bd925a1509af614e4cecbef449133 /background/set_unix.go
parent842bc9065905e8fcbd0e801526306407ac6793c4 (diff)
downloadcetus-bf040f6d1c8c7bc33d5268db42bc2ac9016e2198.tar.gz
Add background package
This rewrite has better comments and returns better error messages.
Diffstat (limited to 'background/set_unix.go')
-rw-r--r--background/set_unix.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/background/set_unix.go b/background/set_unix.go
new file mode 100644
index 0000000..e782a92
--- /dev/null
+++ b/background/set_unix.go
@@ -0,0 +1,66 @@
+// +build linux netbsd openbsd freebsd dragonfly
+
+package background
+
+import (
+	"fmt"
+	"os"
+	"os/exec"
+)
+
+// SetFromFile takes a string as an input, it must be absolute path to
+// the background. Checks are not made to check if the path exists or
+// it is actually an image, that must be verified before passing it to
+// SetFromFile. SetFromFile will exit returning in error if there is
+// any.
+func SetFromFile(path string) error {
+	var err error
+	switch os.Getenv("XDG_CURRENT_DESKTOP") {
+	case "GNOME", "Unity", "Pantheon":
+		// GNOME, Unity & Pantheon support setting background
+		// from gsettings & have the same key.
+
+		// gsettings takes path in format of a uri
+		path = fmt.Sprintf("%s%s", "file://", path)
+
+		err = exec.Command("gsettings",
+			"set org.gnome.desktop.background picture-uri", path).Run()
+		if err != nil {
+			err = fmt.Errorf("%s\n%s",
+				"set_unix.go: failed to set background with gsettings",
+				err.Error())
+		}
+		return err
+
+	case "LXDE":
+		// Background on LXDE can be set with pcmanfm (default
+		// file manager).
+		err = exec.Command("pcmanfm", "-w", path).Run()
+		if err != nil {
+			err = fmt.Errorf("%s\n%s",
+				"set_unix.go: failed to set background with pcmanfm",
+				err.Error())
+		}
+		return err
+
+	default:
+		// If WM/DE doesn't have a case then feh is used to
+		// set the background. This is tested to work on WMs
+		// similar to i3wm.
+		feh, err := exec.LookPath("feh")
+		if err != nil {
+			err = fmt.Errorf("%s\n%s",
+				"set_unix.go: feh not found in $PATH",
+				err.Error())
+			return err
+		}
+
+		err = exec.Command(feh, "--bg-fill", path).Run()
+		if err != nil {
+			err = fmt.Errorf("%s\n%s",
+				"set_unix.go: failed to set background with feh",
+				err.Error())
+		}
+		return err
+	}
+}
def'' href='/akkartik/mu/commit/014literal_string.cc?h=hlt&id=1ead356219bb2eb59487d1012f837bd07ec336f5'>1ead3562 ^
e3fa6cc7 ^
7a9b05fa ^
acc4792d ^
7a9b05fa ^
66b97b4d ^
795f5244 ^
66b97b4d ^
8619c618 ^
d18d1d3d ^

1f7e3c05 ^
d18d1d3d ^

66b97b4d ^


66b97b4d ^
08cf048f ^
90e0ae0c ^
7fb3fccb ^





00dd6685 ^

9e30dba0 ^
08cf048f ^
7fb3fccb ^


7fb3fccb ^



7fb3fccb ^







9e30dba0 ^
7fb3fccb ^
08cf048f ^
66b97b4d ^
23fd54f1 ^
3369875c ^
23fd54f1 ^

66b97b4d ^
ff58b456 ^


66b97b4d ^
08cf048f ^
1b76245c ^
7fb3fccb ^




9e30dba0 ^
7fb3fccb ^

fc52705f ^
3369875c ^
fc52705f ^

7fb3fccb ^

08cf048f ^
7fb3fccb ^








fc52705f ^
1d0a623a ^
1b76245c ^
fc52705f ^
66b97b4d ^
5e21a9f6 ^
1f59be84 ^
555d95c1 ^
2589de99 ^
1f59be84 ^
9c30b383 ^


343bc535 ^
1f59be84 ^

7a9b05fa ^
7bba6e7b ^

ea542d0a ^
9f95c745 ^
78c50205 ^
9f95c745 ^
7cc045d9 ^

78c50205 ^
65c905fe ^
48e40252 ^

7cc045d9 ^



acc4792d ^
7cc045d9 ^








a796831f ^



3369875c ^





















88be3dbc ^
1ead3562 ^
e3fa6cc7 ^
3d6c13dc ^
acc4792d ^
c51043ab ^
23fd54f1 ^
1ead3562 ^
23fd54f1 ^

acc4792d ^
23fd54f1 ^
3369875c ^
1ead3562 ^
fc52705f ^
3369875c ^
fc52705f ^
acc4792d ^
fc52705f ^
c51043ab ^
1ead3562 ^
c51043ab ^

4f10b93a ^
35457609 ^
5683823a ^
acc4792d ^

2f677225 ^

1ead3562 ^
2f677225 ^


acc4792d ^
7fb3fccb ^

1ead3562 ^
7fb3fccb ^




acc4792d ^
7fb3fccb ^

1ead3562 ^
7fb3fccb ^

acc4792d ^
2589de99 ^


d63cddea ^

2589de99 ^
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225