-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathset_wallpaper
216 lines (183 loc) · 8.93 KB
/
set_wallpaper
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
#!/bin/bash
#
# This script is run by Variety when a new wallpaper is set.
# You can use bash, python or whatever suits you for the script.
# Here you can put custom commands for setting the wallpaper on your specific desktop environment
# or run commands like notify-send to notify you of the change, or you can
# run commands that would theme your browser, login screen or whatever you desire.
#
# PARAMETERS:
# $1: The first passed parameter is the absolute path to the wallpaper image to be set as wallpaper
# (after effects, clock, etc. are applied).
#
# $2: The second passed parameter is "auto" when the wallpaper is changed automatically (i.e. regular change), "manual"
# when the user has triggered the change or "refresh" when the change is triggered by a change in quotes, clock, etc.
#
# $3: The third passed parameter is the absolute path to the original wallpaper image (before effects, clock, etc.)
#
# EXAMPLE:
# echo "$1" # /home/username/.config/variety/wallpaper/wallpaper-clock-fac0eef772f9b03bd9c0f82a79d72506.jpg
# echo "$2" # auto
# echo "$3" # /home/username/Pictures/Wallpapers/Nature/green-tunnel-1920x1080-wallpaper-861.jpg
# Here you may apply some additional custom operations on the wallpaper before it is applied.
# In the end put the path to the actual final wallpaper image file in the WP variable.
# The default is to simply set WP=$1.
WP=$1
# Enlightenment
# Needs Modules/System/DBus Extension loaded to work
if [ "`echo $DESKTOP | grep Enlightenment`" ]; then
OUTPUT_DIR="$HOME/.e/e/backgrounds"
TEMPLATE='
images { image: "@IMAGE@" USER; }
collections {
group {
name: "e/desktop/background";
data { item: "style" "4"; item: "noanimation" "1"; }
max: @WIDTH@ @HEIGHT@;
parts {
part {
name: "bg";
mouse_events: 0;
description {
state: "default" 0.0;
aspect: @ASPECT@ @ASPECT@;
aspect_preference: NONE;
image { normal: "@IMAGE@"; scale_hint: STATIC; }
}
}
}
}
}
'
OFILE="$OUTPUT_DIR/variety_wallpaper_$RANDOM"
DIMENSION="$(identify -format "%w/%h" "$WP")"
if [ ! -z "$DIMENSION" ]; then
WIDTH=$(echo $DIMENSION | cut -d/ -f1)
HEIGHT=$(echo $DIMENSION | cut -d/ -f2)
IMAGE="$(echo "$WP" | sed 's/[^[:alnum:]_-]/\\&/g')"
if [ -z "$HEIGHT" -o "$HEIGHT" = "0" ]; then
ASPECT="0.0"
else
ASPECT=$(echo "scale=9; $DIMENSION" | bc)
fi
fi
printf "%s" "$TEMPLATE" | \
sed "s/@ASPECT@/$ASPECT/g; s/@WIDTH@/$WIDTH/g; s/@HEIGHT@/$HEIGHT/g; s|@IMAGE@|$IMAGE|g" > "$OFILE.edc"
edje_cc "$OFILE.edc" "$OFILE.edj" 2>/dev/null
rm "$OFILE.edc"
## Get the current number of virtual desktops
desk_x_count=$(enlightenment_remote -desktops-get | awk '{print $1}')
desk_y_count=$(enlightenment_remote -desktops-get | awk '{print $2}')
## Get the current number of screens
screen_count=1
# If xrandr is available use it to get screen desk_x_count
if command -v xrandr >/dev/null 2>&1; then
screen_count=$(xrandr -q | grep ' connected' | wc -l)
fi
## work out the screen to update
update_screen=0
if [ $screen_count > 1 ]; then
LAST_SCREEN_UPDATE_FILE="$HOME/.config/variety/.enlightenment_last_screen.txt"
if [ -e $LAST_SCREEN_UPDATE_FILE ]; then
last_screen=$(cat $LAST_SCREEN_UPDATE_FILE)
update_screen=$((($last_screen+1)%$screen_count))
echo "us: $update_screen ls: $last_screen sc:$screen_count eq:$((($last_screen+1)%$screen_count))"
fi
echo "$update_screen" > $LAST_SCREEN_UPDATE_FILE
fi
## Set the wallpaper for each virtual desktop
for ((x=0; x<$desk_x_count; x++)); do
for ((y=0; y<$desk_y_count; y++)); do
#for ((z=0; z<$screen_count; z++)); do
# -desktop-bg-add OPT1 OPT2 OPT3 OPT4 OPT5 Add a desktop bg definition.
# OPT1 = ContainerNo(unused) OPT2 = ZoneNo OPT3 = Desk_x. OPT4 = Desk_y. OPT5 = bg file path
# This command can take a few seconds so it should run in the background
enlightenment_remote -desktop-bg-add 0 "$update_screen" "$x" "$y" "$OFILE.edj" &
#done
done
done
# Remove all Variety wallpapers, but the current one and the previous one
# as we are calling enlightenment_remote asynchronously, if the previous wallpaper hasn't been
# replaced yet then the wallpaper will get set back to the theme one causing ugly artifacts
LAST_WALLPAPER_FILE="$HOME/.config/variety/.enlightenment_last_wallpaper.txt"
LAST_WALLPAPER_FILE2="$HOME/.config/variety/.enlightenment_last_wallpaper2.txt"
LAST_WALLPAPER_FILE3="$HOME/.config/variety/.enlightenment_last_wallpaper3.txt"
LAST_WALLPAPER_FILE4="$HOME/.config/variety/.enlightenment_last_wallpaper4.txt"
if [ -e $LAST_WALLPAPER_FILE ]; then
if [ -e $LAST_WALLPAPER_FILE2 ]; then
if [ -e $LAST_WALLPAPER_FILE3 ]; then
if [ -e $LAST_WALLPAPER_FILE4 ]; then
find $OUTPUT_DIR -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | grep -v $(cat $LAST_WALLPAPER_FILE) | grep -v $(cat $LAST_WALLPAPER_FILE2) | grep -v $(cat $LAST_WALLPAPER_FILE3) | grep -v $(cat $LAST_WALLPAPER_FILE4) | xargs rm
else
find $OUTPUT_DIR -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | grep -v $(cat $LAST_WALLPAPER_FILE) | grep -v $(cat $LAST_WALLPAPER_FILE2) | grep -v $(cat $LAST_WALLPAPER_FILE3) | xargs rm
fi
cat "$LAST_WALLPAPER_FILE3" > $LAST_WALLPAPER_FILE4
else
find $OUTPUT_DIR -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | grep -v $(cat $LAST_WALLPAPER_FILE) | grep -v $(cat $LAST_WALLPAPER_FILE2) | xargs rm
fi
cat "$LAST_WALLPAPER_FILE2" > $LAST_WALLPAPER_FILE3
else
find $OUTPUT_DIR -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | grep -v $(cat $LAST_WALLPAPER_FILE) | xargs rm
fi
else
find $OUTPUT_DIR -name "variety_wallpaper*.*" | grep -v "$OFILE.edj" | xargs rm
fi
cat "$LAST_WALLPAPER_FILE" > $LAST_WALLPAPER_FILE2
echo "$OFILE.edj" > $LAST_WALLPAPER_FILE
exit 0
fi
# KDE - User will have to manually choose ~/Pictures/variety-wallpaper/ as a slideshow folder with a short iterval.
# Afterwards, with the command below, Variety will just overwrite the single file there when changing the wallpaper
# and KDE will refresh it
if [ "`env | grep KDE_FULL_SESSION | tail -c +18`" == "true" ]; then
mkdir -p "$(xdg-user-dir PICTURES)/variety-wallpaper"
cp "$WP" "$(xdg-user-dir PICTURES)/variety-wallpaper/wallpaper-kde.jpg"
exit 0
fi
# Cinnamon, for cases when it is detectable
if [ "$XDG_CURRENT_DESKTOP" == "X-Cinnamon" ]; then
gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null
if [ "`gsettings get org.cinnamon.background picture-options`" == "'none'" ]; then
gsettings set org.cinnamon.background picture-options 'zoom'
fi
gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null
if [ "`gsettings get org.cinnamon.desktop.background picture-options`" == "'none'" ]; then
gsettings set org.cinnamon.desktop.background picture-options 'zoom'
fi
exit 0
fi
# Gnome 3, Unity
gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
gsettings set com.canonical.unity-greeter background "$WP"
if [ "`gsettings get org.gnome.desktop.background picture-options`" == "'none'" ]; then
gsettings set org.gnome.desktop.background picture-options 'zoom'
fi
# XFCE
command -v xfconf-query >/dev/null 2>&1
rc=$?
if [[ $rc = 0 ]] ; then
for i in $(xfconf-query -c xfce4-desktop -p /backdrop -l|egrep -e "screen.*/monitor.*image-path$" -e "screen.*/monitor.*/last-image$"); do
xfconf-query -c xfce4-desktop -p $i -n -t string -s "" 2> /dev/null
xfconf-query -c xfce4-desktop -p $i -s "" 2> /dev/null
xfconf-query -c xfce4-desktop -p $i -s "$WP" 2> /dev/null
done
fi
# LXDE/PCmanFM
if [ "$XDG_CURRENT_DESKTOP" == "LXDE" ]; then
pcmanfm --set-wallpaper "$WP" 2> /dev/null
fi
# Feh - commented, as it may cause problems with Nautilus, (see bug https://bugs.launchpad.net/variety/+bug/1047083)
# feh --bg-scale "$WP" 2> /dev/null
# MATE after 1.6
gsettings set org.mate.background picture-filename "$WP" 2> /dev/null
# MATE before 1.6
mateconftool-2 -t string -s /desktop/mate/background/picture_filename "$WP" 2> /dev/null
# Cinnamon after 1.8, before 2.0
gsettings set org.cinnamon.background picture-uri "file://$WP" 2> /dev/null
# Cinnamon after 2.0
gsettings set org.cinnamon.desktop.background picture-uri "file://$WP" 2> /dev/null
# Gnome 2
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$WP" 2> /dev/null
# Show a notification on wallpaper change (only when the change is automatic). Display the original filename, but the post-effects image.
# name=$(echo "$3" | sed 's/\//\n/g'| tail -n 1)
# if [ "$2" == "auto" ]; then notify-send --icon "$WP" "Wallpaper changed" "$name" ; fi