-
Notifications
You must be signed in to change notification settings - Fork 4
/
eos-wallpaper-set
executable file
·348 lines (307 loc) · 10.7 KB
/
eos-wallpaper-set
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
# Usage: eos-wallpaper-set [filename]
# where
# filename Picture file name (optional).
#
# Without filename, assumes all wallpapers are at /usr/share/endeavouros/backgrounds.
#################################################################################
EOS_SCRIPTS_YAD=/usr/share/endeavouros/scripts/eos-script-lib-yad
source $EOS_SCRIPTS_YAD || {
echo "ERROR: cannot read $EOS_SCRIPTS_YAD" >&2
exit 1
}
unset EOS_SCRIPTS_YAD
export -f eos_yad
export -f eos_yad_terminal
export -f eos_yad_check_internet_connection
export -f eos_yad_GetArgVal
export -f eos_yad_RunCmdTermBash
export -f eos_yad_problem
export -f eos_yad_DIE
export -f eos_yad_WARN
export -f eos_yad__detectDE
export -f eos_yad_GetDesktopName
export -f eos_GetArch
#################################################################################
Monospaced() { printf "<tt>%s</tt>" "$1" ; }
Untagged() { echo "$1" | sed -e 's|<[/]*[ib]>||g' ; }
eos_yad_infomsg() {
local msg="$1"
Untagged "$msg" >&2
which yad &>/dev/null && \
eos_yad --form --text="$(Monospaced "$msg")" --title="Message" --tail --wrap --image=info \
--button=yad-quit:0 "$@"
}
DIE() {
Untagged "$1" >&2
which yad &>/dev/null && \
eos_yad --form --text="$(Monospaced "$1")\n" --title="$progname: error" \
--width=400 \
--image=error --button=yad-ok:0
exit 1
}
WallpaperSelect() {
local pic_count=$(/usr/bin/ls -l "$picfolder" | /usr/bin/wc -l)
local height=$((pic_count * 36))
local hmax=600 hmin=300
if [ $height -gt $hmax ] ; then
height=$hmax
elif [ $height -lt $hmin ] ; then
height=$hmin
fi
eos_assert_deps $progname yad || exit 1
pic="$(eos_yad --file --filename="$picfolder" --width=700 --height=$height --title="Choose wallpaper file")"
}
XfceSetWallpaper() {
# Set all "last-image" values in file $conf to picture $pic
local impl
case "$(eos_GetArch)" in
armv7h) impl=1 ;;
*) impl=2 ;; # 2 = best for x86_64 (?)
esac
case "$impl" in
0)
local conf="$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml"
test -r "$conf" || DIE "Config file '$conf' does not exist."
sed -i "$conf" -e 's|name="last-image".*$|name="last-image" type="string" value="'"$pic"'"/>|'
eos_yad_infomsg "Reboot is required for the changes to take effect."
;;
1)
local prop
for prop in $(xfconf-query --channel xfce4-desktop --list | grep /last-image$) ; do
xfconf-query --channel xfce4-desktop --property $prop --set "$pic"
done
#eos_yad_infomsg "Reboot is required for the changes to take effect."
;;
2)
local monitors=($(xrandr | grep -w connected | awk '{print $1}'))
local monitor mon prop
for monitor in "${monitors[@]}" ; do
mon=monitor${monitor}
prop=$(xfconf-query --channel xfce4-desktop --list | grep /last-image$ | grep $mon)
xfconf-query --channel xfce4-desktop --property $prop --set "$pic"
done
;;
esac
}
WallpaperSetCommon() {
# Assume:
# - $pic is the picture file name
# - $DE is the desktop environment
test -n "$pic" || DIE "no picture!"
case "$DE" in
BUDGIE)
AssertPicture endeavouros_budgie.png
gsettings set org.gnome.desktop.background picture-uri "$pic"
;;
CINNAMON)
AssertPicture endeavouros_cinnamon.png
gsettings set org.cinnamon.desktop.background picture-uri "$pic"
;;
DEEPIN)
AssertPicture endeavouros_deepin.png
dconf write /com/deepin/wrap/gnome/desktop/background/picture-uri "'$pic'" # Note: extra quotes required!
;;
GNOME | GNOME3)
AssertPicture endeavouros_gnome.png
gsettings set org.gnome.desktop.background picture-uri "$pic"
;;
I3)
AssertPicture endeavouros_i3.png no
feh --bg-scale "$pic"
;;
KDE)
AssertPicture endeavouros_plasma.png no
python3 /usr/share/endeavouros/scripts/ksetwallpaper.py --file "$pic"
# see also:
# https://www.kubuntuforums.net/showthread.php/66762-Right-click-wallpaper-changer?p=387392&viewfull=1#post387392
;;
LXDE)
AssertPicture endeavouros_lxde.png no
pcmanfm --set-wallpaper="$pic"
;;
LXQT)
AssertPicture endeavouros_lxqt.png no
pcmanfm-qt --set-wallpaper="$pic"
;;
MATE)
AssertPicture endeavouros_mate.png no
gsettings set org.mate.background picture-filename "$pic"
;;
XFCE)
AssertPicture endeavouros_xfce4.png no
XfceSetWallpaper
;;
# Not DEs but WMs:
SWAY)
AssertPicture endeavouros-wallpaper.png no
killall swaybg # otherwise wallpaper doesn't change!
swaybg -i "$pic"
;;
BSPWM)
AssertPicture endeavouros-wallpaper.png no
nitrogen --set-auto "$pic"
;;
OPENBOX)
AssertPicture endeavouros-wallpaper.png no
nitrogen --set-auto "$pic"
;;
QTILE)
AssertPicture endeavouros-wallpaper.png no
feh --bg-scale "$pic"
;;
*)
echo "$progname: info: not setting wallpaper to $DE ..." >&2
#AssertPicture endeavouros-wallpaper.png no
#feh --bg-scale "$pic"
#DIE "Sorry, desktop '$DE' is not supported."
;;
esac
if [ ! -e "$history_of_backgrounds" ] ; then
local header="History of desktop wallpapers set by $progname (started at $(date '+%x %X'))"
local underline=${header//?/=}
cat <<EOF > "$history_of_backgrounds"
$header
$underline
EOF
fi
echo "$(date '+%x %X'): $(realpath "$pic")" >> "$history_of_backgrounds"
}
PictureNameVariations() {
# Allow very small naming choices in the default wallpapers,
# like '-' instead of '_' before the DE name.
[ -r "$pic" ] && return # picture found, OK
if [ "$(basename "$pic")" = "$fallback" ] ; then
local changed="$(echo "$pic" | sed 's|endeavouros_\([a-z][a-z]*[0-9]\.png\)$|endeavouros-\1|')"
if [ -r "$changed" ] ; then
echo "Info: wallpaper name changed from '$(basename "$pic")' to '$(basename "$changed")'" >&2
pic="$changed"
return 0
fi
fi
DIE "Picture file '$pic' does not exist."
}
AssertPicture() {
local fallback="$1"
local use_file_prefix="$2"
case "$pic" in
DEFAULT-2020 | default-2020)
case "$(eos_GetArch)" in
armv7h)
pic="$picfolder/arm-$fallback"
[ -r "$pic" ] || pic="$picfolder/$fallback" # ARM pictures missing
;;
*)
pic="$picfolder/$fallback"
;;
esac
;;
DEFAULT | default | DEFAULT-2021 | default-2021)
pic="$picfolder/endeavouros-wallpaper.png"
;;
ISO | iso)
pic="$picfolder/endeavouros-default-background.png" # new picture
[ -r "$pic" ] || pic="$picfolder/endeavouros-wallpaper.png" # old picture
;;
esac
# change $pic to full path format
case "$pic" in
"")
DIE "no picture file given!"
;;
file://*)
pic="${pic:7}"
;;
/*)
;; # OK, full path
*)
if [ -r "$picfolder/$pic" ] ; then
pic="$picfolder/$pic" # EOS picture without path given, add path
elif [ -r "$pic" ] ; then
pic="$PWD/$pic" # picture has relative path
fi
;;
esac
# Now we have a full path. Check that it exists or die.
PictureNameVariations
# Some DE's prefer file:// prefix, some not.
if [ "$use_file_prefix" = "no" ] ; then
case "$pic" in
file://*) pic="${pic:7}" ;;
esac
else
case "$pic" in
file://*) ;;
*) pic="file://$pic" ;;
esac
fi
echo "Setting desktop wallpaper $pic for '$DE' ..." >&2
}
Parameters() {
local arg msg
for arg in "$@" ; do
case "$arg" in
-h | --help)
eos_yad_infomsg "$(Usage)"
exit 0
;;
--history)
local wp=$(grep ^[0-9] "$history_of_backgrounds" | awk '{print $NF}' | sort -u | fzf)
[ "$wp" ] && Main "$wp"
exit 0
;;
-*)
msg="$(printf "\n%s\n\n" "Unsupported option '$arg'." ; Usage)"
DIE "$msg"
;;
*)
if [ -d "$arg" ] ; then
picfolder="$arg"
else
pic="$arg"
fi
;;
esac
done
}
Usage() {
cat <<EOF
Usage: <b>$progname</b> [options] [wallpaper-file | folder]
Options:
-h, --help This help.
--history Select wallpaper from previously set wallpapers.
Parameters:
<i>wallpaper-file</i>
Wallpaper file name, 'DEFAULT', or 'ISO':
- absolute or relative path, with or without leading 'file://'.
- 'DEFAULT' means the default Desktop specific wallpaper.
- 'ISO' means the default wallpaper for the installer ISO
<i>folder</i>
An existing folder path for wallpapers.
If <i>wallpaper-file</i> is not given, the <i>wallpaper chooser</i> is started.
Examples:
$progname ~/Pictures/a_picture.jpg # wallpaper file name
$progname ~/Pictures # folder path for pictures
$progname DEFAULT # Desktop specific default wallpaper
$progname ISO # wallpaper used by the ISO
$progname # starts the wallpaper chooser
EOF
}
Main()
{
local progname=${0##*/}
local DE="$(eos_GetDeOrWm)"
local picfolder=/usr/share/endeavouros/backgrounds
local pic=""
local history_of_backgrounds="$HOME/.$progname.history-of-wallpapers" # saves history of wallpaper file names
yad_missing_check $progname
case "$DE" in
XFCE) type xrandr >& /dev/null || DIE "Sorry, this implementation needs package 'xorg-xrandr' on Xfce." ;;
esac
Parameters "$@"
if [ -z "$pic" ] ; then
WallpaperSelect
fi
WallpaperSetCommon
}
Main "$@"