71 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env zsh
function parse-config {
if ! [[ -f $HOME/.config/wallpaper/config ]]; then
echo "<3>Config does not exist, cannot operate."
return 6
fi
source $HOME/.config/wallpaper/config
args=()
good_config=0
if (( ${+COLOR} )); then
args+="--color=${COLOR}"
good_config=1
fi
if (( ${+IMAGE} )); then
args+="--image=$IMAGE"
good_config=1
fi
if (( ${+MODE} )); then
args+="--mode=$MODE"
fi
if ! [[ $good_config == '1' ]]; then
echo "<3>Missing COLOR or IMAGE, cannot set background."
return 78
fi
}
function reload {
systemd-notify --reloading --status "Reloading config"
parse-config
if (( ? != 0 )); then
echo "<3>Reload failed"
systemd-notify --ready --status "Config reload failed. Background not changed."
return
fi
kill $swaybg_pid
# now will return to the while loop where swaybg will be relaunched with new $args
}
function stop {
systemd-notify --stopping
should_exit=1
kill $swaybg_pid
}
parse-config
exit_code=$?
if (( exit_code )); then
exit $exit_code
fi
trap reload 1
trap stop 15
should_exit=0
while [[ $should_exit == 0 ]]; do
(swaybg --output='*' $args |& awk -F" " '{$1="<6>"; $2=""; $3=""; print}') &
swaybg_pid=$!
sleep 0.1
systemd-notify --ready --status "Background set"
wait
done