commit 05aae6c9dc16485f5f467976c5e2f79c028d7103 parent 1c2ba4e58aec3c003d02c6b7bb2ccc2eb89db4d0 Author: Markus Hanetzok <markus@hanetzok.net> Date: Mon, 6 Oct 2025 19:59:02 +0200 improve setwallpaper script replace xwallpaper with hsetroot, use dominant_colours to set the bg of the root window depending on the dominant colour of the wallpaper Diffstat:
M | .local/bin/setwallpaper | | | 22 | +++++++++++++++------- |
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/.local/bin/setwallpaper b/.local/bin/setwallpaper @@ -1,19 +1,27 @@ #!/bin/bash -bgfile="$1" -wplocation="$XDG_DATA_HOME"/wallpaper +wallpaper="$XDG_DATA_HOME"/wallpaper.png setbg() { + # get dominant color of wallpaper image + domcol="$(dominant_colours "$1" --no-palette --max-colours=1)" + + # get display and image width dpwidth="$(xrandr | grep '*' | awk '{print $1}' | sed 's/\(.*\)x.*/\1/')" imgwidth="$(LANG=C exiv2 -q $1 | grep "Image size" | awk '{print $4$5$6}' | sed 's/\(.*\)x.*/\1/')" if [ "$dpwidth" -gt "$imgwidth" ]; then - xwallpaper --center $wplocation + # if the display width is greater then the image width, we want the image centered... + hsetroot -solid "$domcol" -center $wallpaper else - xwallpaper --zoom $wplocation + # ...otherwise make it fit the screen + hsetroot -cover $wallpaper fi } -[[ ! -z "$bgfile" ]] && [[ -f "$bgfile" ]] && cp -f "$bgfile" "$wplocation" -[[ -f "$wplocation" ]] || { notify-send "No wallpaper file found!"; exit 1; } +# check if a file is given as argument and set it as new default +[[ ! -z "$1" ]] && [[ -f "$1" ]] && magick "$1" "$wallpaper" && notify-send "Set new wallpaper..." + +# check if there is a file at our default wallpaper location +[[ -f "$wallpaper" ]] || { notify-send "No wallpaper file found!"; exit 1; } -setbg $wplocation +setbg $wallpaper