Skip to content

Instantly share code, notes, and snippets.

@Dregu
Last active March 26, 2025 14:10
Show Gist options
  • Save Dregu/953866953a47ef4c534574cec261358c to your computer and use it in GitHub Desktop.
Save Dregu/953866953a47ef4c534574cec261358c to your computer and use it in GitHub Desktop.
Set random wallpaper and matching active border gradient using hyprpaper/swaybg and magick
#!/bin/bash
# Set random wallpaper and matching active border gradient using hyprpaper/swaybg and magick
DIR=~/pics/wallpapers
FORCE="$1"
pkill swaybg
paper () {
[[ -z "$FORCE" ]] && export IMG="$(find $DIR -type f | shuf -n1)" || export IMG="$FORCE"
hyprctl -q hyprpaper reload "$1,$IMG" || hyprctl -q dispatch exec "swaybg -m fill -o $1 -i \"$IMG\""
}
# Set random wallpaper for all desired outputs, LAST ONE is primary monitor to extract colors from
paper HDMI-A-1
paper DP-1
# Extract some bright colors from the image (or try to brighten dark colors)
COLORS=$(for C in $(magick "$IMG" -scale 64x64! -depth 8 +dither -colors 8 -format "%c" histogram:info: \
| sed -n 's/^[^#]*#\(.\{6\}\).*$/\1/p'); do (
( [[ $(("0x$C" & 0x808080)) -gt 0 ]] && echo -n "0xEE$C " ) ||\
( [[ $(("0x$C" & 0x404040)) -gt 0 ]] && printf "0xEE%06X " $((0x$C << 1)) ) ||\
( [[ $(("0x$C" & 0x202020)) -gt 0 ]] && printf "0xEE%06X " $((0x$C << 2)) )
); done | xargs)
# Random angle for gradient
ANGLE="$(shuf -i 0-360 -n 1)deg"
# Set bg matching active border gradient or fallback if that didn't work (bg too dark or something went wrong)
[[ $COLORS =~ " " ]] && [[ $(hyprctl keyword general:col.active_border "$COLORS $ANGLE") = "ok" ]] \
|| hyprctl -q keyword general:col.active_border "rgba(ff40e0ee) rgba(aa77ccee) $ANGLE"
# Set inactive border to same angle or animations glitch
hyprctl -q keyword general:col.inactive_border "rgba(404040ee) rgba(202020ee) $ANGLE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment