Wallpaper switching and setting

What do y’all use? Home-grown scripting (is so, care to show that), an app (what one), and are you able to set the wallpaper at-will/on the fly/only on reboot it it gets set/changes.

A script I wrote a year or two ago, it uses feh as the actual setter though. Can do up to two monitors with/without xinerama and various scaling types.

#!/bin/bash

# simple background setting for 1-2 monitors

SET_MON=0
NO_XINERAMA=''
SET_TYPE='scale'
MON1=''
MON2=''

GUI='' CHW='' SCRIPT_PATH="$0"

badarg()
{
	printf "error: additional arg required or improper arg passed.\n"
	exit 2
}

chwall()
{
	# update each monitor's wallpaper in the script
	case $SET_MON in
		0)
			MON1="$WALL_PATH"; MON2=""
			sed -i "/^MON2=.*/ c MON2=''" "$SCRIPT_PATH"
			sed -i "/^MON1=.*/ c MON1='${MON1}'" "$SCRIPT_PATH" ;;
		*)
			eval "MON${SET_MON}='$WALL_PATH'"
			sed -i "/^MON${SET_MON}=.*/ c MON${SET_MON}='${WALL_PATH}'" "$SCRIPT_PATH"
	esac

	# update the scaling type and xinerama
	sed -i "/^SET_TYPE=.*/ c SET_TYPE='${SET_TYPE}'" "$SCRIPT_PATH"
	sed -i "/^NO_XINERAMA=.*/ c NO_XINERAMA='${NO_XINERAMA}'" "$SCRIPT_PATH"
}

run()
{
	if [[ $MON1 && $MON2 ]]; then
		feh --no-fehbg --bg-$SET_TYPE "$MON1" "$MON2"
	elif [[ $MON1 ]]; then
		# shellcheck disable=SC2086
		feh $NO_XINERAMA --no-fehbg --bg-$SET_TYPE "$MON1"
	else
		printf "error: no monitors configured\n"
		return 1
	fi
}

sxiv_sel()
{
	if hash sxiv >/dev/null 2>&1; then
		WALL_PATH="$(sxiv -rto "$HOME/Pictures" | awk 'NR==1')"
		[[ $WALL_PATH ]] && return 0
	else
		printf "error: this requires sxiv\n"
	fi
	exit 0
}

while getopts ":hxSs:t:m:" OPT; do
	case $OPT in
		h)
			printf "usage: %s [-x <y/n>] [-S, [-s <image>]] [-m monitor] [-t set_type]\n" "${0##*/}"
			exit 0
			;;
		s)
			CHW='chwall'
			if [[ $OPTARG =~ (^.*\.jpg$|^.*\.png$) && -f $OPTARG ]]; then
				WALL_PATH="$OPTARG"
			else
				badarg
			fi
			;;
		t)
			if [[ $OPTARG =~ (^center$|^fill$|^max$|^scale$|^tile$) ]]; then
				SET_TYPE="$OPTARG"
			else
				badarg
			fi
			;;
		m)
			if [[ ${OPTARG:0:1} =~ [0-2] ]]; then
				SET_MON="${OPTARG:0:1}"
			else
				badarg
			fi
			;;
		S)
			CHW='chwall'
			GUI='sxiv_sel'
			;;
		x)
			if [[ $OPTARG =~ (y|Y) ]]; then
				NO_XINERAMA=""
			elif [[ $OPTARG =~ (n|N) ]]; then
				NO_XINERAMA='--no-xinerama'
			else
				badarg
			fi
			;;
		:)
			badarg
			;;
		\?)
			printf "Invalid option: -%s\n" "$OPTARG"
			exit 2
	esac
done

eval ${GUI}
eval ${CHW}
run

It’s not very well written or documented but it uses itself as the config and will store the settings used for later runs without arguments (for autostart or reapplying). It can also use sxiv to pick an image, again poorly implemented. It works well for me like this, I had a more complex version before but decided to scrap it and keep it basic.

1 Like

I normally use fbsetbg which is a tool that installs with fluxbox; it’s a wrapper script that works with other wallpaper setting tools like hsetroot, feh, or nitrogen. I usually have hsetroot installed.

This command:

fbsetbg -C -R "$HOME/wallpaper/" &

in my ~/.xprofile ( or any window manager startup script) will randomly select an image from ~/wallpaper and center it so I get a different wallpaper with every login.

I also like to use sxiv image viewer. It’s a nice image viewer in general and can be used with helper scripts to set the wallpaper; and example script is in the ArchWik. Like fbsetbg it needs an actual wallpaper setting application installed.

3 Likes
6 Likes

I tend to use a modified setup that linux dabbler uses in his Debian setup. Its pretty nice and does set a random on login and some bindings in dwm that allow me to switch at will.

I thought about adding a random wallpaper option to Azote, but, to be honest, it’s against my nature. I need to have full control over my desktop.

1 Like

I use setroot.

setroot -t /home/user/Walls/wall.png

For people who likes GUIS i would recommend “Azote”. It is nwgs baby.

3 Likes
~$ grep wallpaper.png ~/.config/sway/config 
output * bg ~/Pictures/wallpaper.png tile
~$

I don’t really change the wallpaper but if I wanted to I would copy the image to ~/Pictures/wallpaper.png. And maybe sed -i 's/tile/fill/' ~/.config/sway/config (or whatever).

1 Like