Last active
August 16, 2025 15:15
-
-
Save Dregu/953866953a47ef4c534574cec261358c to your computer and use it in GitHub Desktop.
Set random wallpaper and matching active border gradient using hyprpaper/swaybg and imagemagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set random wallpaper and matching active border gradient using hyprpaper/swaybg and imagemagick | |
DIR=~/pics/wallpapers | |
FORCE="$1" | |
# Collect old swaybg pids to kill after fading new one in | |
OLD=$(pgrep -d" " swaybg) | |
# Temporary animation hack for a slow cross dissolve, also prevents anime girl from popping up during fade | |
# using curve: bezier = linger,1,-1,1,-1 | |
hyprctl keyword animation layersIn,1,10,linear,fade | |
hyprctl keyword animation layersOut,1,10,linger,fade | |
hyprctl keyword animation fadeLayersIn,1,10,linear | |
hyprctl keyword animation fadeLayersOut,1,10,linger | |
# This function commands hyprpaper if it's running, otherwise launches 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-2 | |
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" | |
# Kill old swaybg and restore default animations after | |
sleep 2 | |
/bin/kill $OLD | |
hyprctl keyword animation layersIn,1,1.5,almostLinear | |
hyprctl keyword animation layersOut,1,1.5,almostLinear | |
hyprctl keyword animation fadeLayersIn,1,1.5,almostLinear | |
hyprctl keyword animation fadeLayersOut,1,1.5,almostLinear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment