#!/bin/bash

DEFAULT_WALLPAPER="/usr/share/fuss-artwork/wallpapers/fuss-wallpaper.svg" 

for m in $(xrandr | grep " connected" | cut -d' ' -f1); do
    PROP="/backdrop/screen0/monitor${m}/workspace0/last-image" 

    # Find the current background
    CURRENT=$(xfconf-query -c xfce4-desktop -p "$PROP" 2>/dev/null || echo "")

    # if it does not exist, is empty, or does not point to a readable file, the fallback is set
    if [[ -z "$CURRENT" || ! -f "$CURRENT" ]]; then
        xfconf-query -c xfce4-desktop -p "$PROP" --create -t string -s "$DEFAULT_WALLPAPER" 
    fi
done

# Reload the desktop only if anything has changed
xfdesktop --reload

