Dough Git

commit

Add audio...?

commit
963d905e22a8ffe23b499d160d4136fc88ef9baf
author
Clove Twilight <[email protected]>
date
2026-11-07 00:41

diff --git a/README.md b/README.md
index 9d1d9ff..529bd4e 100644
--- a/README.md
+++ b/README.md
@@ -14,6 +14,7 @@ A swayfx desktop with a "Clockwork" theme pulled from the wallpaper: deep-space
 - **kitty** (terminal) with an **oh-my-posh** prompt
 - **fuzzel** (app launcher), **mako** (notifications), **gtklock** (lock screen)
 - An optional **SDDM** login screen to match
+- An optional looping **background sound** (plays only while plugged in and out of power saver)
 - The **sandrone-linux** cursor (my own)
 
 ## Install
@@ -47,6 +48,17 @@ The Clockwork SDDM theme has its own script and works without the rest of the do
 
 Or add `--with-sddm` to `./install` to get everything at once.
 
+### Background sound (optional)
+
+Off by default. Turn it on with `./install --with-sound`, or edit these lines in `sway/config` and reload sway:
+
+```
+set $ambient_sound on
+set $ambient_volume 30
+```
+
+**Super+M** mutes it until the next reload.
+
 Anything already in the way is renamed to `.bak-<date>`, never deleted.
 
 ## Bar controls
@@ -88,6 +100,7 @@ Press **Super+/** to search every shortcut (picking one runs it). The full list:
 | `Super+v` | `cliphist list \| fuzzel --dmenu --prompt "clip " \| cliphist decode \|...` |
 | `Super+Shift+v` | `cliphist wipe` |
 | `Super+slash` | `~/.local/bin/keybinds` |
+| `Super+m` | `~/.local/bin/ambient toggle` |
 | `Super+Shift+r` | `reload` |
 | `Super+Shift+e` | `swaynag -t warning -m 'You pressed the exit shortcut. Do you really...` |
 | `Ctrl+Alt+Delete` | `~/.local/bin/powermenu` |
diff --git a/binaries/ambient b/binaries/ambient
new file mode 100755
index 0000000..94d77aa
--- /dev/null
+++ b/binaries/ambient
@@ -0,0 +1,74 @@
+#!/bin/sh
+# ambient: looping background sound for the desktop.
+#
+#   ambient config on|off [volume]  apply the sway/config setting (sway runs this)
+#   ambient toggle                  mute/unmute for now (Super+M); a sway reload resets it
+#   ambient sync                    start/stop to match power (run by waybar-battery)
+#   ambient off                     stop it until sway reloads
+#
+# Plays sway/background-sound.* with mpv, only while plugged in and not in
+# power-saver (same rule as the animated wallpaper). No sound file = no-op.
+
+DIR="${XDG_CONFIG_HOME:-$HOME/.config}/sway"
+STATE="${XDG_STATE_HOME:-$HOME/.local/state}"
+ENABLED="$STATE/ambient-enabled"     # "on" or "off", from sway/config
+VOLUME="$STATE/ambient-volume"
+MUTED="$STATE/ambient-muted"         # exists while muted with Super+M
+PIDF="${XDG_RUNTIME_DIR:-/tmp}/ambient-sound.pid"
+
+sound() { for f in "$DIR"/background-sound.*; do [ -f "$f" ] && { echo "$f"; return; }; done; }
+
+running() { [ -f "$PIDF" ] && kill -0 "$(cat "$PIDF")" 2>/dev/null; }
+
+power_ok() {
+  ac=0
+  for f in /sys/class/power_supply/*/online; do
+    [ -r "$f" ] && [ "$(cat "$f")" = 1 ] && ac=1
+  done
+  [ "$ac" = 1 ] || return 1
+  [ "$(powerprofilesctl get 2>/dev/null)" != power-saver ]
+}
+
+start() {
+  running && return 0
+  f=$(sound); [ -n "$f" ] || return 0
+  command -v mpv >/dev/null || return 0
+  vol=$(cat "$VOLUME" 2>/dev/null || echo 30)
+  PIDF="$PIDF" setsid -f sh -c 'echo $$ > "$PIDF"; exec mpv --no-video --no-terminal --really-quiet --loop-file=inf --volume="$1" "$2"' _ "$vol" "$f"
+}
+
+stop() { running && kill "$(cat "$PIDF")"; rm -f "$PIDF"; }
+
+wanted() {
+  [ "$(cat "$ENABLED" 2>/dev/null)" = on ] && [ ! -e "$MUTED" ] && power_ok
+}
+
+mkdir -p "$STATE"
+case ${1:-sync} in
+  config)
+    echo "${2:-off}" > "$ENABLED"
+    case ${3:-} in ''|*[!0-9]*) ;; *) echo "$3" > "$VOLUME" ;; esac
+    rm -f "$MUTED"                       # a reload re-applies the config
+    stop
+    if wanted; then start
+    elif [ "${2:-off}" = on ] && [ -n "$(sound)" ]; then
+      notify-send -a ambient "Background sound" "On, waiting until you're plugged in and out of power-saver"
+    fi ;;
+  toggle)
+    if [ -e "$MUTED" ] || ! running; then
+      rm -f "$MUTED"
+      if [ "$(cat "$ENABLED" 2>/dev/null)" != on ]; then
+        notify-send "Background sound" "Off in sway/config (set \$ambient_sound on)"
+      elif [ -z "$(sound)" ]; then
+        notify-send "Background sound" "No sway/background-sound.* file"
+      elif ! power_ok; then
+        notify-send "Background sound" "Waits until you're plugged in and out of power-saver"
+      else start
+      fi
+    else
+      touch "$MUTED"; stop
+    fi ;;
+  sync)  if wanted; then start; else stop; fi ;;
+  off)   touch "$MUTED"; stop ;;
+  *) sed -n '2,11p' "$0" | sed 's/^# \{0,1\}//'; exit 1 ;;
+esac
diff --git a/binaries/waybar-battery b/binaries/waybar-battery
index b25438f..d5b94c3 100755
--- a/binaries/waybar-battery
+++ b/binaries/waybar-battery
@@ -26,11 +26,13 @@ esac
 if [ -n "$1" ]; then
   pkill -RTMIN+8 -x waybar
   ~/.local/bin/wallpaper sync &
+  ~/.local/bin/ambient sync &
   exit
 fi
 
-# Keep the animated wallpaper in step with power (cheap; exits early if unused)
+# Keep the animated wallpaper and background sound in step with power (cheap; exit early if unused)
 ~/.local/bin/wallpaper sync >/dev/null 2>&1 &
+~/.local/bin/ambient sync >/dev/null 2>&1 &
 
 cap=$(cat "$BAT/capacity")
 status=$(cat "$BAT/status")
diff --git a/install b/install
index fc5f596..ae59ad9 100755
--- a/install
+++ b/install
@@ -9,18 +9,20 @@
 #   ./install --dry-run           print every command without running anything
 #   --no-flatpak, --no-services   passed through to install-deps.sh
 #   --with-sddm                   also install the Clockwork login theme (install-sddm.sh)
+#   --with-sound                  turn on the background sound (install-config.sh)
 #
 # Each script also works on its own.
 
 set -uo pipefail
 
-ALL=() DEPS=() PARTS=(deps assets config scripts)
+ALL=() DEPS=() CONFIG=() PARTS=(deps assets config scripts)
 for arg in "$@"; do
   case $arg in
     --dry-run)                  ALL+=("$arg") ;;
     --no-flatpak|--no-services) DEPS+=("$arg") ;;
     --with-sddm)                PARTS+=(sddm) ;;
-    -h|--help) sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
+    --with-sound)               CONFIG+=("$arg") ;;
+    -h|--help) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
     *) echo "Unknown option: $arg (try --help)"; exit 1 ;;
   esac
 done
@@ -31,6 +33,8 @@ for part in "${PARTS[@]}"; do
   printf '\n\e[1;35m######## install-%s ########\e[0m\n' "$part"
   if [ "$part" = deps ]; then
     "$REPO/install-deps.sh" "${ALL[@]}" "${DEPS[@]}" || failed+=("$part")
+  elif [ "$part" = config ]; then
+    "$REPO/install-config.sh" "${ALL[@]}" "${CONFIG[@]}" || failed+=("$part")
   else
     "$REPO/install-$part.sh" "${ALL[@]}" || failed+=("$part")
   fi
diff --git a/install-config.sh b/install-config.sh
index 53d1d4b..cab4d58 100755
--- a/install-config.sh
+++ b/install-config.sh
@@ -3,6 +3,7 @@
 #
 #   ./install-config.sh            link every config folder/file into ~/.config
 #   ./install-config.sh --dry-run  print the commands without running them
+#   ./install-config.sh --with-sound  turn on the background sound in sway/config
 #
 # If the repo already *is* ~/.config there is nothing to do.
 # If you cloned it somewhere else (e.g. ~/dotfiles), each config the
@@ -11,11 +12,12 @@
 
 set -uo pipefail
 
-DRY=0
+DRY=0 SOUND=0
 for arg in "$@"; do
   case $arg in
     --dry-run) DRY=1 ;;
-    -h|--help) sed -n '2,10p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
+    --with-sound) SOUND=1 ;;
+    -h|--help) sed -n '2,11p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
     *) echo "Unknown option: $arg (try --help)"; exit 1 ;;
   esac
 done
@@ -29,6 +31,13 @@ REPO=$(cd "$(dirname "$0")" && pwd -P)
 TARGET="${XDG_CONFIG_HOME:-$HOME/.config}"
 [ "$DRY" = 1 ] && echo "Dry run: nothing will be changed."
 
+if [ "$SOUND" = 1 ]; then
+  step "Background sound: on"
+  run sed -i 's/^set \$ambient_sound .*/set $ambient_sound on/' "$REPO/sway/config"
+  ls "$REPO"/sway/background-sound.* >/dev/null 2>&1 ||
+    warn "No sway/background-sound.* file yet; add one and it'll start playing"
+fi
+
 step "Linking configs into $TARGET"
 if [ "$REPO" = "$(cd "$TARGET" 2>/dev/null && pwd -P)" ]; then
   echo "  The repo is $TARGET itself, so every config is already in place."
diff --git a/install-deps.sh b/install-deps.sh
index c1533a3..1a025a5 100755
--- a/install-deps.sh
+++ b/install-deps.sh
@@ -62,7 +62,7 @@ echo "Detected ${PRETTY_NAME:-$ID} (using the $FAMILY package list)"
 # apps, portals, build tools for the cargo steps below.
 case $FAMILY in
 void)
-  PKGS=(swayfx Waybar swaybg mpvpaper wlsunset swayidle autotiling polkit-gnome gnome-keyring
+  PKGS=(swayfx Waybar swaybg mpvpaper mpv wlsunset swayidle autotiling polkit-gnome gnome-keyring
         mako libnotify fuzzel gtklock ImageMagick kitty yazi
         wl-clipboard cliphist pipewire wireplumber pavucontrol
         brightnessctl playerctl power-profiles-daemon
@@ -70,7 +70,7 @@ void)
         grim slurp wf-recorder firefox flatpak xdg-desktop-portal-wlr
         jq curl unzip git fontconfig rustup) ;;
 arch)
-  PKGS=(swayfx waybar swaybg mpvpaper wlsunset swayidle autotiling polkit-gnome gnome-keyring
+  PKGS=(swayfx waybar swaybg mpvpaper mpv wlsunset swayidle autotiling polkit-gnome gnome-keyring
         mako libnotify fuzzel gtklock imagemagick kitty yazi
         wl-clipboard cliphist pipewire pipewire-pulse wireplumber pavucontrol
         brightnessctl playerctl power-profiles-daemon
@@ -78,7 +78,7 @@ arch)
         grim slurp wf-recorder firefox flatpak xdg-desktop-portal-wlr
         jq curl unzip git fontconfig base-devel rustup) ;;
 fedora)
-  PKGS=(swayfx waybar swaybg mpvpaper wlsunset swayidle autotiling polkit-gnome gnome-keyring
+  PKGS=(swayfx waybar swaybg mpvpaper mpv wlsunset swayidle autotiling polkit-gnome gnome-keyring
         mako libnotify fuzzel gtklock ImageMagick kitty yazi
         wl-clipboard cliphist pipewire wireplumber pavucontrol
         brightnessctl playerctl power-profiles-daemon
@@ -86,7 +86,7 @@ fedora)
         grim slurp wf-recorder firefox flatpak xdg-desktop-portal-wlr
         jq curl unzip git fontconfig gcc rustup) ;;
 debian)
-  PKGS=(swayfx waybar swaybg mpvpaper wlsunset swayidle autotiling policykit-1-gnome gnome-keyring
+  PKGS=(swayfx waybar swaybg mpvpaper mpv wlsunset swayidle autotiling policykit-1-gnome gnome-keyring
         mako-notifier libnotify-bin fuzzel gtklock imagemagick kitty yazi
         wl-clipboard cliphist pipewire pipewire-pulse wireplumber pavucontrol
         brightnessctl playerctl power-profiles-daemon
@@ -94,7 +94,7 @@ debian)
         grim slurp wf-recorder firefox flatpak xdg-desktop-portal-wlr
         jq curl unzip git fontconfig build-essential rustup) ;;
 suse)
-  PKGS=(swayfx waybar swaybg mpvpaper wlsunset swayidle autotiling polkit-gnome gnome-keyring
+  PKGS=(swayfx waybar swaybg mpvpaper mpv wlsunset swayidle autotiling polkit-gnome gnome-keyring
         mako libnotify-tools fuzzel gtklock ImageMagick kitty yazi
         wl-clipboard cliphist pipewire wireplumber pavucontrol
         brightnessctl playerctl power-profiles-daemon
diff --git a/sway/background-sound.mp3 b/sway/background-sound.mp3
new file mode 100644
index 0000000..31effec
Binary files /dev/null and b/sway/background-sound.mp3 differ
diff --git a/sway/config b/sway/config
index 8246233..9c5982a 100644
--- a/sway/config
+++ b/sway/config
@@ -24,6 +24,12 @@ set $clipwipe cliphist wipe
 #
 exec waybar
 exec ~/.local/bin/wallpaper restore
+
+# Background sound: on or off, volume 0-100. Plays sway/background-sound.*
+# while plugged in and out of power-saver. Super+M mutes it until the next reload.
+set $ambient_sound off
+set $ambient_volume 30
+exec_always ~/.local/bin/ambient config $ambient_sound $ambient_volume
 exec mako
 exec --no-startup-id autotiling
 
@@ -122,6 +128,7 @@ bindsym $mod+n exec $notification
 bindsym $mod+v exec $clipboard
 bindsym $mod+Shift+v exec $clipwipe
 bindsym $mod+slash exec ~/.local/bin/keybinds
+bindsym $mod+m exec ~/.local/bin/ambient toggle
 # $mod+grave (dashboard) is unbound for now.
 
 floating_modifier $mod normal