-
Notifications
You must be signed in to change notification settings - Fork 4
/
wall-d
executable file
·263 lines (227 loc) · 10.2 KB
/
wall-d
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
#! /usr/bin/env bash
# __ ___ _ _ ____
# \ \ / / \ | | | | | _ \
# \ \ /\ / / _ \ | | | | _____| | | |
# \ V V / ___ \| |___| |__|_____| |_| |
# \_/\_/_/ \_\_____|_____| |____/
DIR="" # Path to wallpapers directory
defaultwallpaper="$HOME/.local/bin/defaultwallpaper.sh"
[ -f $defaultwallpaper ] && echo "defaultwallpaper.sh exists" || echo xwallpaper >> ~/.local/bin/defaultwallpaper.sh && chmod +x ~/.local/bin/defaultwallpaper.sh
Monitor1=$(xrandr --listactivemonitors | grep "+" | awk '{print $4}' | awk NR==1) # Select the first monitor for dual mode
[ ! -z $Monitor1 ] && Resolution1=$(xrandr --listactivemonitors | grep $Monitor1 | sed 's/[\/x]/ /g' | awk '{print $3 "x" $5}')
Monitor2=$(xrandr --listactivemonitors | grep "+" | awk '{print $4}' | awk NR==2) # Select the second monitor for dual mode
[ ! -z $Monitor2 ] && Resolution2=$(xrandr --listactivemonitors | grep $Monitor2 | sed 's/[\/x]/ /g' | awk '{print $3 "x" $5}')
Monitor3=$(xrandr --listactivemonitors | grep "+" | awk '{print $4}' | awk NR==3) # Select the third monitor for triple mode
[ ! -z $Monitor3 ] && Resolution3=$(xrandr --listactivemonitors | grep $Monitor3 | sed 's/[\/x]/ /g' | awk '{print $3 "x" $5}')
# get number of avilable active monitors
NumOfMonitors=$(xrandr --listactivemonitors | grep "+" | wc -l)
# get screen resulotion to calculate the center
x=$(xrandr | grep "*" | sed 's/x/ /g' | awk -F " " '{print $1}' | sed 's/\ //g')
y=$(xrandr | grep "*" | sed 's/x/ /g' | awk -F " " '{print $2}' | sed 's/\ //g')
xl=$(echo "($x-500)/2" | bc)
yl=$(echo "($y-500)/2" | bc)
location=$(echo 500x500+$xl+$yl)
# will be set to true when using -p flag to activate pywal
WithPywall="False"
# will be set to true when using -n flag to activate random photo selection
randomly="False"
# Will be set to True when using -b flag to only change betterlockscreen background
OnlyBetterlockscreen="False"
# Will be set to True when using -b flag to also change betterlockscreen background
WithBetterlockscreen="False"
startMessage="Apply wallpaper to lockscreen"
finishMessage="Finished applying wallpaper to lockscreen"
UseFeh="False"
UseRofi="False"
# function to reset the last set wallpaper(s)
restore() {
if [ "$UseFeh" = "True" ];
then
~/.fehbg &
else
defaultwallpaper.sh
fi
}
# help message
usage() {
echo "Wall-d: A simple and fast wallpaper manager for x"
echo ""
echo "Usage:"
echo "-h print this help message and exit"
echo "-d path/to/your/wallpapers"
echo "-r restore last set Wallpaper(s)"
echo "-p Change colorscheme using pywall"
echo "-b Change Betterlockscreen wallpaper too"
echo "-l Only change Betterlockscreen wallpaper"
echo "-n Choose a randome wallpaper(s)"
echo "-f use feh instead of xwallpaper to set and restore the wallpaper"
echo "-R use rofi instead of dmenu"
echo ""
}
while getopts :d:rhpbnlfR option; do
case "${option}" in
d) DIR=${OPTARG};;
r) restore && exit;;
p) WithPywall="True" ;;
b) WithBetterlockscreen="True" ;;
l) OnlyBetterlockscreen="True" ;;
n) randomly="True" ;;
h) usage && exit 0 ;;
f) UseFeh="True" ;;
R) UseRofi="True" ;;
*) usage && exit 0
esac
done
[ -z "$DIR" ] && usage && exit 0 # if no directory is set, print help message and exit
# show dmenu in pywal colors only if ran with -p flag
source ~/.cache/wal/colors.sh
if [ "$WithPywall" = "True" ]; then
colorOptions="-nb $color0 -nf $color15 -sb $color1 -sf $color15"
else
colorOptions=""
fi
Single(){
if [ "$randomly" = "True" ]; then
walls=$(du -a $DIR | grep 'jpg\|jpeg\|png\|gif' | shuf -n 1 | awk '{print $2}')
else
walls=$(sxiv -t -o -r -b -g $location $DIR | xargs) # running sxiv in thumbnail mode.
fi
wall1=$(printf "%s" "$walls" | awk '{w = 1; for (--w; w >=0; w--){printf "%s\t",$(NF-w)}print ""}') # Only print the last marked Wallpaper
# if no picture is marked in sxiv, exit.
[ -z "$walls" ] && exit 0
if [ "$UseRofi" = "True" ] && [ "$UseFeh" = "True" ];
then
WallMenu="rofi -dmenu -i -l 5 -p "Options""
WallOptions=$(echo -e "fill\ncenter\ntile\nscale\nno-xinerama" | $WallMenu)
elif [ "$UseRofi" = "True" ] && [ "$UseFeh" = "False" ];
then
WallMenu="rofi -dmenu -i -l 5 -p "Options""
WallOptions=$(echo -e "zoom\ncenter\ntile\nstretch\nno-randr" | $WallMenu)
elif [ "$UseRofi" = "False" ] && [ "$UseFeh" = "True" ];
then
WallMenu="dmenu $colorOptions -i -l 5 -p "Options""
WallOptions=$(echo -e "fill\ncenter\ntile\nscale\nno-xinerama" | $WallMenu)
else
WallMenu="dmenu $colorOptions -i -l 5 -p "Options""
WallOptions=$(echo -e "zoom\ncenter\ntile\nstretch\nno-randr" | $WallMenu)
fi
[ -z "$WallOptions" ] && exit 0
if [ "$OnlyBetterlockscreen" = "True" ]; then
betterlockscreen -u $wall1 -r $Resolution1
else
if [ "$UseFeh" = "True" ];
then
feh --bg-$WallOptions $wall1
else
xwallpaper --$WallOptions $wall1 && sed -i "s|xwallpaper.*|xwallpaper --$WallOptions $wall1|" $HOME/.local/bin/defaultwallpaper.sh
fi
fi
[ "$WithPywall" = "True" ] && wal -i $wall1 -n
if [ "$WithBetterlockscreen" = "True" ]; then
dunstify "Wall-d" "$startMessage"
betterlockscreen -u $wall1 -r $Resolution1
dunstify "Wall-d" "$finishMessage"
fi
}
# to set to diffrent wallpapers on each desktop
Dual() {
if [ "$randomly" = "True" ]; then
dwalls=$(du -a $DIR | grep 'jpg\|jpeg\|png\|gif' | shuf -n 1 | awk '{print $2}')
else
dwalls=$(sxiv -t -o -r -b -g $location $DIR | xargs) # running sxiv in thimbnail mode.
fi
dwallslast2=$(printf "%s" "$dwalls" | awk '{w = 2; for (--w; w >=0; w--){printf "%s\t",$(NF-w)}print ""}') # Only print the two last marked Wallpapers
dwall1=$(printf "%s" "$dwallslast2" | awk '{print $1}') # Print the path to the before-last marked wallpaper
dwall2=$(printf "%s" "$dwallslast2" | awk '{print $2}') # Print the path to the last marked wallpaper
# if no picture is marked in sxiv, exit.
[ -z "$dwalls" ] && exit 0
if [ "$UseRofi" = "True" ] && [ "$UseFeh" = "True" ];
then
WallMenu="rofi -dmenu -i -l 5 -p "Options""
WallOptions=$(echo -e "fill\ncenter\ntile\nscale\nno-xinerama" | $WallMenu)
elif [ "$UseRofi" = "True" ] && [ "$UseFeh" = "False" ];
then
WallMenu="rofi -dmenu -i -l 5 -p "Options""
WallOptions=$(echo -e "zoom\ncenter\ntile\nstretch\nno-randr" | $WallMenu)
elif [ "$UseRofi" = "False" ] && [ "$UseFeh" = "True" ];
then
WallMenu="dmenu $colorOptions -i -l 5 -p "Options""
WallOptions=$(echo -e "fill\ncenter\ntile\nscale\nno-xinerama" | $WallMenu)
else
WallMenu="dmenu $colorOptions -i -l 5 -p "Options""
WallOptions=$(echo -e "zoom\ncenter\ntile\nstretch\nno-randr" | $WallMenu)
fi
[ -z "$WallOptions" ] && exit 0
if [ "$UseFeh" = "True" ];
then
feh --bg-$WallOptions $dwall1 $dwall2
else
xwallpaper --output $Monitor1 --$WallOptions $dwall1 --output $Monitor2 --$WallOptions $dwall2 && sed -i "s|xwallpaper.*|xwallpaper --output $Monitor1 --$WallOptions $dwall1 --output $Monitor2 --$WallOptions $dwall2|" $HOME/.local/bin/defaultwallpaper.sh
fi
[ "$WithPywall" = "True" ] && wal -i $dwall1 -n
if [ "$WithBetterlockscreen" = "True" ]; then
dunstify "Wall-d" "$startMessage"
betterlockscreen -u $dwall1 -r $Resolution1
dunstify "Wall-d" "$finishMessage"
fi
}
Triple() {
if [ "$randomly" = "True" ]; then
twalls=$(du -a $DIR | grep 'jpg\|jpeg\|png\|gif' | shuf -n 1 | awk '{print $2}')
else
twalls=$(sxiv -t -o -r -b -g $location $DIR | xargs) # running sxiv in thimbnail mode.
fi
twallslast3=$(printf "%s" "$twalls" | awk '{w = 3; for (--w; w >=0; w--){printf "%s\t",$(NF-w)}print ""}') # Only print the three last marked Wallpapers
twall1=$(printf "%s" "$twallslast3" | awk '{print $1}') # Print the path to the before-before-last marked wallpaper
twall2=$(printf "%s" "$twallslast3" | awk '{print $2}') # Print the path to the before-last marked wallpaper
twall3=$(printf "%s" "$twallslast3" | awk '{print $3}') # Print the path to the last marked wallpaper
# if no picture is marked in sxiv, exit.
[ -z "$twalls" ] && exit 0
if [ "$UseRofi" = "True" ] && [ "$UseFeh" = "True" ];
then
WallMenu="rofi -dmenu -i -l 5 -p "Options""
WallOptions=$(echo -e "fill\ncenter\ntile\nscale\nno-xinerama" | $WallMenu)
elif [ "$UseRofi" = "True" ] && [ "$UseFeh" = "False" ];
then
WallMenu="rofi -dmenu -i -l 5 -p "Options""
WallOptions=$(echo -e "zoom\ncenter\ntile\nstretch\nno-randr" | $WallMenu)
elif [ "$UseRofi" = "False" ] && [ "$UseFeh" = "True" ];
then
WallMenu="dmenu $colorOptions -i -l 5 -p "Options""
WallOptions=$(echo -e "fill\ncenter\ntile\nscale\nno-xinerama" | $WallMenu)
else
WallMenu="dmenu $colorOptions -i -l 5 -p "Options""
WallOptions=$(echo -e "zoom\ncenter\ntile\nstretch\nno-randr" | $WallMenu)
fi
[ -z "$WallOptions" ] && exit 0
if [ "$UseFeh" = "True" ];
then
feh --bg-$WallOptions $dwall1 $dwall2
else
xwallpaper --output $Monitor1 --$WallOptions $twall1 --output $Monitor2 --$WallOptions $twall2 --output $Monitor3 --$WallOptions $twall3 && sed -i "s|xwallpaper.*|xwallpaper --output $Monitor1 --$WallOptions $twall1 --output $Monitor2 --$WallOptions $twall2 --output $Monitor3 --$WallOptions $twall3 |" $HOME/.local/bin/defaultwallpaper.sh
fi
[ "$WithPywall" = "True" ] && wal -i $twall2 -n
if [ "$WithBetterlockscreen" = "True" ]; then
dunstify "Wall-d" "$startMessage"
betterlockscreen -u $twall2 -r $Resolution2
dunstify "Wall-d" "$finishMessage"
fi
}
if [ "$UseRofi" = "True" ];
then
MENU="rofi -dmenu -l 3 -p "Mode?""
else
MENU="dmenu $colorOptions -l 3 -p "Mode?""
fi
if [ "$NumOfMonitors" -eq 1 ]; then
Single && exit 0
elif [ "$NumOfMonitors" -eq 2 ]; then
MODE=$(echo -e "Single: Choose one Wallpaper\nDual: Choose two Wallpapers" | $MENU)
elif [ "$NumOfMonitors" -ge 3 ]; then
MODE=$(echo -e "Single: Choose One Wallpaper\nDual: Choose Two Wallpapers\nTriple: Choose Three Wallpapers" | $MENU)
fi
case "$MODE" in
Single*) Single ;;
Dual*) Dual ;;
Triple*) Triple
esac