2024-06-23 06:44:57 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
LOCK_RESOLUTION="1920x1080"
|
|
|
|
LOCK_QUALITY=70
|
|
|
|
|
|
|
|
err() {
|
|
|
|
echo "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
err "${0##*/}: $1"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
err "${0##*/}: $1"
|
|
|
|
err
|
|
|
|
fi
|
|
|
|
|
|
|
|
err "usage: ${0##*/} [-hqr] [-e RESOLUTION] [-u QUALITY] IMAGE"
|
|
|
|
err
|
|
|
|
err " -h show this message and exit"
|
|
|
|
err " -q suppress output and notifications"
|
|
|
|
err " -r restore the previous image as your wallpaper"
|
|
|
|
err " -e <RESOLUTION> override lock screen RESOLUTION"
|
|
|
|
err " -u <QUALITY> override lock screen QUALITY"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_lock() {
|
|
|
|
magick "$1" -resize "$LOCK_RESOLUTION"^ -gravity center -extent "$LOCK_RESOLUTION" -quality "$LOCK_QUALITY" "$XDG_CACHE_HOME/lock.png"
|
|
|
|
}
|
|
|
|
|
|
|
|
restore() {
|
|
|
|
[ -f "$XDG_DATA_HOME/wallpaper" ] || die "previous image not found"
|
|
|
|
|
|
|
|
previous="$(readlink -f "$XDG_DATA_HOME/wallpaper")"
|
|
|
|
case "${previous##*.}" in
|
2024-07-03 19:59:32 -04:00
|
|
|
png | jpg | jpeg) ;;
|
|
|
|
*) die "$previous: unsupported file type" ;;
|
2024-06-23 06:44:57 -04:00
|
|
|
esac
|
|
|
|
|
|
|
|
cmp -s "$previous" "$XDG_CACHE_HOME/lock.png" || convert_lock "$previous" &
|
|
|
|
xwallpaper --zoom "$XDG_DATA_HOME/wallpaper"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts ":hqre:u:" opt; do
|
|
|
|
case $opt in
|
2024-07-03 19:59:32 -04:00
|
|
|
h) usage ;;
|
|
|
|
q) QUIET=1 ;;
|
|
|
|
r) restore ;;
|
|
|
|
e) LOCK_RESOLUTION=$OPTARG ;;
|
|
|
|
u) LOCK_QUALITY=$OPTARG ;;
|
|
|
|
\?) usage "invalid option -- '$OPTARG'" ;;
|
|
|
|
:) usage "option requires an argument -- '$OPTARG'" ;;
|
2024-06-23 06:44:57 -04:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
|
|
|
if [ "$1" = "-" ]; then
|
2024-07-03 19:59:32 -04:00
|
|
|
while read -r line; do
|
|
|
|
image=$line
|
|
|
|
done
|
2024-06-23 06:44:57 -04:00
|
|
|
else
|
2024-07-03 19:59:32 -04:00
|
|
|
image=$1
|
2024-06-23 06:44:57 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$image" ] || usage "IMAGE was not provided"
|
|
|
|
[ -d "$image" ] && die "$image: is a directory"
|
|
|
|
[ -f "$image" ] || die "$image: no such file"
|
|
|
|
|
|
|
|
case "${image##*.}" in
|
2024-07-03 19:59:32 -04:00
|
|
|
png | jpg | jpeg) ;;
|
|
|
|
*) die "$image: unsupported file type" ;;
|
2024-06-23 06:44:57 -04:00
|
|
|
esac
|
|
|
|
|
|
|
|
cmp -s "$image" "$XDG_CACHE_HOME/lock.png" || convert_lock "$image" &
|
|
|
|
ln -sf "$image" "$XDG_DATA_HOME/wallpaper"
|
|
|
|
xwallpaper --zoom "$XDG_DATA_HOME/wallpaper"
|
|
|
|
|
|
|
|
[ -z "$QUIET" ] && notify-send -u low "System" "Wallpaper set to <b>${image##*/}</b>."
|