awww -> awww + swaybg
顺便修修readme:减少md代码块以应对ly gitea黑色主题的蜜汁渲染
This commit is contained in:
38
bin/chbg
38
bin/chbg
@@ -3,7 +3,11 @@ set -euo pipefail
|
||||
|
||||
THIS_COMMAND=$(basename "$0")
|
||||
IMG_MAGICK="magick"
|
||||
WP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||
SERVICE_NAME="swaybg.service"
|
||||
|
||||
WP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
|
||||
WP_FILE="$WP_DIR/wallpaper"
|
||||
BLUR_WP="$WP_DIR/wallpaper_blur"
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
@@ -12,7 +16,7 @@ Options:
|
||||
-d, --dir OUTPUT_PATH Directory to store chosen image. (default: $WP_DIR)
|
||||
-h, --help Show this help message and exit.
|
||||
Notes:
|
||||
- Images can be provided as arguments or via stdin. If both are used, they are combined.
|
||||
- This script needs 'swaybg.service' to be set up for overview background support (unless awww #521 solved). See niri documentation for details.
|
||||
- Web URLs are also supported (via 'curl' or 'wget' downloading).
|
||||
- If multiple images are provided, one will be randomly picked each time the script is executed.
|
||||
EOF
|
||||
@@ -36,8 +40,8 @@ while [[ $# -gt 0 ]]; do
|
||||
esac
|
||||
done
|
||||
|
||||
if ! command -v swww >/dev/null 2>&1; then
|
||||
echo "!) 'swww' command not found. Unable to comply." >&2
|
||||
if ! command -v awww >/dev/null 2>&1; then
|
||||
echo "x) 'awww' not found. Unable to comply." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
@@ -46,7 +50,7 @@ if command -v magick >/dev/null 2>&1; then
|
||||
elif command -v convert >/dev/null 2>&1; then
|
||||
IMG_MAGICK="convert"
|
||||
else
|
||||
echo "!) 'magick' or 'convert' command not found. Image processing unavailable." >&2
|
||||
echo "x) 'magick' or 'convert' not found. Image processing unavailable." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
@@ -61,7 +65,7 @@ set_wallpaper() {
|
||||
(( fw > 3840 && fh > 2160 )) && {
|
||||
finput=$(mktemp "${TMPDIR:-/tmp}/chbg.XXXXXXXX.webp")
|
||||
trap 'rm -f "$finput"' EXIT
|
||||
echo "-> image too large, resizing ..."
|
||||
echo " -> image too large, resizing ..."
|
||||
# echo "DEBUG: resized image at $finput"
|
||||
$IMG_MAGICK "$1" -resize "3840x2160^" \
|
||||
-quality 90 \
|
||||
@@ -69,14 +73,22 @@ set_wallpaper() {
|
||||
-define webp:alpha-quality=100 "$finput"
|
||||
}
|
||||
|
||||
echo -n "-> making blurred version of '${1##*/}' ... "
|
||||
cp $finput $WP_DIR/.wallpaper
|
||||
$IMG_MAGICK $WP_DIR/.wallpaper -filter Gaussian -blur 0x30 $WP_DIR/.wallpaper_blur
|
||||
echo -n " -> making blurred version of '${1##*/}' ... "
|
||||
cp "$finput" "$WP_FILE"
|
||||
$IMG_MAGICK "$WP_FILE" -filter Gaussian -blur 0x30 "$BLUR_WP"
|
||||
echo "Done."
|
||||
|
||||
# 原工具现在更名为 awww,但留下了 bug:https://codeberg.org/LGFae/awww/issues/521
|
||||
swww img $WP_DIR/.wallpaper
|
||||
swww img $WP_DIR/.wallpaper_blur --namespace blur
|
||||
awww img "$WP_FILE" --transition-type=random
|
||||
|
||||
if [[ -f "$HOME/.config/systemd/user/niri.service.wants/$SERVICE_NAME" ]]; then
|
||||
echo " -> restarting $SERVICE_NAME ..."
|
||||
systemctl --user restart "$SERVICE_NAME"
|
||||
else
|
||||
echo " !) '$SERVICE_NAME' didn't loaded by niri. Won't reload backdrop." >&2
|
||||
echo " => See niri documentation for setting up swaybg systemd unit." >&2
|
||||
echo " => Or wait for awww #521 on codeberg being resolved." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
imagepool=()
|
||||
@@ -132,7 +144,7 @@ if command -v curl >/dev/null 2>&1; then
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -qO "$tmpfile" "$randomimage"
|
||||
else
|
||||
echo "!) Unable to fetch image without 'curl' or 'wget'." >&2
|
||||
echo "x) Unable to fetch image without 'curl' or 'wget'." >&2
|
||||
exit 2
|
||||
fi
|
||||
set_wallpaper "$tmpfile"
|
||||
|
||||
Reference in New Issue
Block a user