
Changing the wallpaper dynamically on every workspace change can be achieved quite easily with Hyprland.
This method requires use of swww, which is a wallpaper utility for Wayland which also supports animated gif files for wallpaper. Cool!
Install the Wallpaper Manager
swww supports dynamic change of wallpaper without the need for killing the wallpaper process like in the case of other Wayland wallpaper managers. This is achieved with the help of a daemon that runs in the background which listens for any calls to change wallpapers. Let’s install swww first:
sudo pacman -S swww
Auto-starting the daemon
Once you have it installed, you need to start the swww-daemon. You should ideally put it in the exec-once section of your Hyprland configuration (If you are still testing it, just run swww-daemon & in any terminal window).
#################
### AUTOSTART ###
#################
exec-once = swww-daemon &
Setting the Wallpaper
But wait, you need to set a wallpaper too. For that, you can invoke a dynamic change of the wallpaper with the following command. Put it in the same section of your Hyprland config file as the line above. The img flag indicates that you are instructing the swww-daemon to change the wallaper. -o flag indicates which monitor we are referring to (running “hyprctl monitors” in the terminal gives you a list of detected monitors). The last argument is obviously the reference to the wallpaper image.
#################
### AUTOSTART ###
#################
exec-once = swww-daemon &
exec-once = swww img -o eDP-1 /home/vitarsi/Pictures/Wallpapers/boot.png
Dynamic Wallpapers
Now that you have a basic Wallpaper working, let’s work on how to change wallpapers based on the active workspace. First, we need to detect any changes to the workspace.
The Hyprland wiki gives us a good starting point. We will be making use of Inter Process Communication or IPC for this.
The following shell script uses socat to open a socket which then listens to Hyprland events. The full list of events is given in the Wiki. Here, we are interested only in “workspace” event which is triggered whenever there is a change in the workspace. This can be either through a keybind (the most usual case) or workspace e+1 or even when changed with a swipe of the trackpad.
#!/bin/sh
handle() {
case $1 in
workspace*)
str=$1
i=$((${#str}-1))
workspace="${str:$i:1}"
case $workspace in
1)
swww img -o eDP-1 -t fade --transition-duration 1 /home/vitarsi/Pictures/Wallpapers/01.png
;;
2)
swww img -o eDP-1 -t fade --transition-duration 1 /home/vitarsi/Pictures/Wallpapers/02.png
;;
3)
swww img -o eDP-1 -t fade --transition-duration 1 /home/vitarsi/Pictures/Wallpapers/03.png
;;
4)
swww img -o eDP-1 -t fade --transition-duration 1 /home/vitarsi/Pictures/Wallpapers/04.png
;;
5)
swww img -o eDP-1 -t fade --transition-duration 1 /home/vitarsi/Pictures/Wallpapers/05.png
;;
6 | 7 | 8 | 9 | 0)
swww img -o eDP-1 -t fade --transition-duration 1 /home/vitarsi/Pictures/Wallpapers/06.png
;;
esac
;;
esac
}
socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle "$line"; done
As you can see, the shell script uses a switch case structure to filter the various workspace names. Save it as wallpaper.sh in your desired location. I like to put custom scripts like this in “~/.scripts“. You need to invoke this script with the exec-once in the Hyprland config.
Final Config
Finally, your Autostart section of the Hyprland config should look something like this:
#################
### AUTOSTART ###
#################
exec-once = swww-daemon &
# Set a wallpaper on boot up
exec-once = swww img -o eDP-1 /home/vitarsi/Pictures/Wallpapers/boot.png
# Run script to update wallpapers dynamically
exec-once = sh /home/vitarsi/.scripts/wallpaper.sh &
There you have it, wallpapers that change dynamically depending on your active workspace. The cool thing is that each wallpaper can be an animated gif too.