Integrate switch-audio-sink, update configs and scripts, various improvements

This commit is contained in:
Martin Büchler 2025-08-12 21:12:59 +02:00
parent 92b9d417fb
commit 66c886130e
3 changed files with 57 additions and 8 deletions

View File

@ -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

View File

@ -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": {

49
.local/bin/switch-audio-sink Executable file
View File

@ -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: * <spaces> <number>.
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"