#!/bin/bash # Windows "Source/Sink" speaker volume -> USB gadget Feature Unit (numid=7, PCM # Capture Volume 0-100) + mute (numid=6). Mirror it onto the USB headset sink so # the Windows volume slider actually controls what the user hears in the headset. # Poll-based (200ms), only acts on change to avoid hammering the mixer on the # gadget's ~10Hz async rate-feedback events. set -u export XDG_RUNTIME_DIR=/run/user/1000 CG=UAC2Gadget HSSINK=alsa_output.usb-Logi_USB_Headset_Logi_USB_Headset-00.analog-stereo last=-1; lastm=-1 while true; do v=$(amixer -c "$CG" cget numid=7 2>/dev/null | awk -F= '/: values=/{print $2; exit}') m=$(amixer -c "$CG" cget numid=6 2>/dev/null | awk -F= '/: values=/{print $2; exit}') if [ -n "$v" ] && { [ "$v" != "$last" ] || [ "$m" != "$lastm" ]; }; then pactl set-sink-volume "$HSSINK" "${v}%" >/dev/null 2>&1 case "$m" in off|0) pactl set-sink-mute "$HSSINK" 1 >/dev/null 2>&1 ;; *) pactl set-sink-mute "$HSSINK" 0 >/dev/null 2>&1 ;; esac last="$v"; lastm="$m" fi sleep 0.2 done