-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-wallpaper.sh
executable file
·89 lines (71 loc) · 2.48 KB
/
set-wallpaper.sh
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
#!/usr/bin/env bash
wallpaper_category=$1
# environment variables --------------------------------------------------------
[ ! "$XDG_PICTURES_DIR" ] && export XDG_PICTURES_DIR="$HOME/Pictures"
[ ! "$XDG_STATE_HOME" ] && export XDG_STATE_HOME="$HOME/.local/state"
# variables --------------------------------------------------------------------
wallpaper_category_file="$XDG_STATE_HOME/wallpaper"
wallpapers_dir="$XDG_PICTURES_DIR/wallpapers"
# functions --------------------------------------------------------------------
function getLastCategory {
last_category="faded"
if [ -f "$wallpaper_category_file" ]; then
last_category=$(cat "$wallpaper_category_file")
fi
}
function handleCategoryInput {
wallpaper_category="$1"
if [ ! "$wallpaper_category" ]; then
wallpaper_category="$last_category"
fi
}
function updateStateFile {
caterogy="$1"
echo "$caterogy" >"$wallpaper_category_file"
}
function selectRandomWallpaper {
category="$1"
# wallpaper=$(find "$wallpapers_dir/$category" -type f,l | shuf -n 1)
wallpaper=$(find "$wallpapers_dir/$category" -type f | shuf -n 1)
}
# functions - x11 --------------------------------------------------------------
function setNitrogen {
monitors=$(xrandr --query |
grep -e '\sconnected' |
awk '{print $1}')
for monitor in $monitors; do
nitrogen --set-zoom-fill --random --head="$monitor" "$wallpapers_dir/$wallpaper_category"
done
}
# functions - wayland ----------------------------------------------------------
function setHyprPaper {
monitors=$(hyprctl -j monitors | jq -r '.[].name')
[ ! "$(pidof hyprpaper)" ] && hyprpaper &
hyprctl hyprpaper unload all
for monitor in $monitors; do
selectRandomWallpaper "$wallpaper_category"
hyprctl hyprpaper preload "$wallpaper"
hyprctl hyprpaper wallpaper "$monitor,$wallpaper"
done
}
function setWPaperD {
config_file="$XDG_CONFIG_HOME/wpaperd/wallpaper.toml"
sed -i "s|path = .*$|path = \"$wallpapers_dir/$wallpaper_category\"|" "$config_file"
# restart wpaperd
[ "$(pidof wpaperd)" ] && killall wpaperd
wpaperd
}
# execution ====================================================================
getLastCategory
handleCategoryInput "$wallpaper_category"
updateStateFile "$wallpaper_category"
case $XDG_SESSION_TYPE in
wayland)
setWPaperD
;;
x11)
export DISPLAY=":0"
setNitrogen
;;
*) exit 1 ;;
esac