#!/bin/sh # Switch the live sky behind the desktop: off, Hyperspace, Nebula, Digital Rain. # # Usage: wayfire-background-cycle [next|off|hyperspace|nebula|rain] # # Edits [live-wallpaper] enabled and effect in the user's wayfire.ini, which # Wayfire reloads by itself, so the choice applies at once and stays after the # next login. "off" shows the generated background again. Bound to Super+Ctrl+W # in the shipped wayfire.ini. config="${WAYFIRE_CONFIG_FILE:-${XDG_CONFIG_HOME:-$HOME/.config}/wayfire.ini}" current=$(awk ' /^[ \t]*\[.*\][ \t]*$/ { s = $0; gsub(/^[ \t]*\[|\][ \t]*$/, "", s); in_lw = (s == "live-wallpaper"); next } in_lw && /^[ \t]*enabled[ \t]*=/ { v = $0; sub(/^[^=]*=[ \t]*/, "", v); sub(/[ \t\r]*$/, "", v); enabled = tolower(v) } in_lw && /^[ \t]*effect[ \t]*=/ { v = $0; sub(/^[^=]*=[ \t]*/, "", v); sub(/[ \t\r]*$/, "", v); effect = v } END { if (enabled == "true" || enabled == "1") print (effect == "" ? "hyperspace" : effect); else print "off" } ' "$config") || exit 1 case "${1:-next}" in next) case "$current" in off) choice=hyperspace ;; hyperspace) choice=nebula ;; nebula) choice=rain ;; rain) choice=off ;; *) choice=hyperspace ;; esac ;; off|hyperspace|nebula|rain) choice=$1 ;; *) sed -n '2,9s/^# \{0,1\}//p' "$0" >&2; exit 2 ;; esac enabled=true [ "$choice" = off ] && enabled=false updated=$(awk -v enabled="$enabled" -v effect="$choice" ' function add() { if (!has_enabled) print "enabled = " enabled if (!has_effect && effect != "off") print "effect = " effect has_enabled = has_effect = 1 } /^[ \t]*\[.*\][ \t]*$/ { if (in_lw) add() s = $0; gsub(/^[ \t]*\[|\][ \t]*$/, "", s); in_lw = (s == "live-wallpaper"); if (in_lw) found = 1 print; next } in_lw && /^[ \t]*enabled[ \t]*=/ { print "enabled = " enabled; has_enabled = 1; next } in_lw && /^[ \t]*effect[ \t]*=/ { print (effect == "off" ? $0 : "effect = " effect); has_effect = 1; next } { print } END { if (in_lw) add(); else if (!found) { print ""; print "[live-wallpaper]"; add() } } ' "$config") || exit 1 [ -n "$updated" ] || exit 1 # Written in place: Wayfire watches this file, also when it is a symlink. printf '%s\n' "$updated" > "$config" || exit 1 case "$choice" in off) name="Generated background" ;; hyperspace) name="Hyperspace" ;; nebula) name="Nebula" ;; rain) name="Digital Rain" ;; esac command -v notify-send > /dev/null && notify-send -a Background -t 2500 "$name" "Super+Ctrl+W for the next one." 2> /dev/null exit 0