diff --git a/.config/waybar/config-desktop b/.config/waybar/config-desktop index 72bfb54..f0e631c 100644 --- a/.config/waybar/config-desktop +++ b/.config/waybar/config-desktop @@ -8,7 +8,7 @@ "modules-center": [ "clock" ], - "modules-right": [ + "modules-right": [ "cpu", "memory", "disk#root", @@ -18,7 +18,8 @@ "network", "tray", "custom/wlogout" - ], "hyprland/workspaces": { + ], + "hyprland/workspaces": { "format": "{icon}", "on-click": "activate", "on-scroll-up": "hyprctl dispatch workspace e-1", @@ -97,8 +98,7 @@ }, "scroll-step": 5, "on-click": "pavucontrol", - "on-click-right": "pactl set-default-sink alsa_output.usb-FiiO_DigiHug_USB_Audio-01.iec958-stereo", - "on-click-middle": "pactl set-default-sink alsa_output.pci-0000_0c_00.1.hdmi-stereo" + "on-click-right": "~/.local/bin/switch-audio-sink" }, "tray": { "icon-size": 20 diff --git a/.config/waybar/config-laptop b/.config/waybar/config-laptop index fb0718f..c98a507 100644 --- a/.config/waybar/config-laptop +++ b/.config/waybar/config-laptop @@ -8,7 +8,7 @@ "modules-center": [ "clock" ], - "modules-right": [ + "modules-right": [ "backlight", "cpu", "memory", @@ -20,7 +20,8 @@ "battery", "tray", "custom/wlogout" - ], "hyprland/workspaces": { + ], + "hyprland/workspaces": { "format": "{icon}", "on-click": "activate", "on-scroll-up": "hyprctl dispatch workspace e-1", @@ -105,8 +106,7 @@ }, "scroll-step": 5, "on-click": "pavucontrol", - "on-click-right": "pactl set-default-sink alsa_output.usb-FiiO_DigiHug_USB_Audio-01.iec958-stereo", - "on-click-middle": "pactl set-default-sink alsa_output.pci-0000_0c_00.1.hdmi-stereo" + "on-click-right": "~/.local/bin/switch-audio-sink" }, "battery": { "states": { diff --git a/.local/bin/switch-audio-sink b/.local/bin/switch-audio-sink new file mode 100755 index 0000000..937b57e --- /dev/null +++ b/.local/bin/switch-audio-sink @@ -0,0 +1,49 @@ +#!/usr/bin/env zsh +# Minimal PipeWire sink cycler using starred lines from wpctl status. +# Deps: pw-dump, jq, wpctl + +set -euo pipefail + +# Collect sink IDs (Audio/Sink nodes) +sinks=($(pw-dump | jq -r '.[] | select(.info.props."media.class"=="Audio/Sink") | .id')) +(( ${#sinks} )) || exit 0 + +# Get all lines containing a star (default indicators for various classes) +starred=$(wpctl status | grep -F '*') || true + +# Extract numbers (IDs) from starred lines (the number before the first dot after the star) +typeset -a star_ids +while IFS= read -r line; do + # Match: * . + if [[ $line =~ [*][[:space:]]*([0-9]+)\. ]]; then + star_ids+=("${match[1]}") + fi +done <<< "$starred" + +# Find first starred ID that is actually one of our sinks +current="" +for cid in "${star_ids[@]}"; do + for s in "${sinks[@]}"; do + if [[ $cid == $s ]]; then + current=$cid + break 2 + fi + done +done + +# Fallback if no starred sink matched +[[ -z $current ]] && current=${sinks[1]} + +# Locate index of current in sinks (zsh arrays are 1-based) +idx=1 +for i in {1..${#sinks[@]}}; do + [[ ${sinks[$i]} == "$current" ]] && { idx=$i; break; } +done + +# Compute next sink (wrap) +next=${sinks[$(( (idx % ${#sinks}) + 1 ))]} + +# Switch default +wpctl set-default "$next" >/dev/null 2>&1 || exit 1 + +echo "Switched to sink $next"