Fix A2DP Bluetooth audio routing, stream migration, hotplug monitoring, and q6voice teardown

This commit is contained in:
Luxferre committed 2026-11-04 15:42:58 +02:00
1 parent b2ade2dc42
commit b8dea31b59
34 files changed
+533 -155

No files matched your search

+96 -6
View File
@@ -4,6 +4,14 @@
export PATH="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH"
if [ -z "${XDG_RUNTIME_DIR:-}" ] || [ ! -d "${XDG_RUNTIME_DIR}" ]; then
if [ -d "/run/user/$(id -u)" ]; then
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
elif [ -d "/run/user/10000" ]; then
export XDG_RUNTIME_DIR="/run/user/10000"
fi
fi
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
. sxmo_hook_icons.sh
. sxmo_common.sh
@@ -94,6 +102,37 @@ find_bt_source() {
pactl list short sources 2>/dev/null | awk '$2 ~ /^bluez_input\./ { print $2; exit }'
}
move_streams_to_sink() {
target_sink="$1"
[ -z "$target_sink" ] && return 0
for sid in $(pactl list short sink-inputs 2>/dev/null | awk '{print $1}'); do
pactl move-sink-input "$sid" "$target_sink" >/dev/null 2>&1 || true
done
}
ensure_bt_a2dp_profile() {
bt_card="$(find_bt_card)"
[ -z "$bt_card" ] && return 1
prof="$(find_bt_profile)"
if [ "$prof" = "off" ] || [ -z "$prof" ]; then
if ! pactl set-card-profile "$bt_card" a2dp-sink >/dev/null 2>&1; then
avail_prof="$(pactl list cards 2>/dev/null | awk -v c="$bt_card" '
$1 == "Name:" { in_c = ($2 == c); in_p = 0 }
in_c && $1 == "Profiles:" { in_p = 1; next }
in_c && in_p && /^[[:space:]]*Active Profile:/ { in_p = 0 }
in_c && in_p && $1 ~ /^a2dp-sink/ && $0 !~ /available: no/ { sub(/:$/, "", $1); print $1; exit }
')"
if [ -n "$avail_prof" ]; then
pactl set-card-profile "$bt_card" "$avail_prof" >/dev/null 2>&1 || true
else
pactl set-card-profile "$bt_card" headset-head-unit-cvsd >/dev/null 2>&1 ||
pactl set-card-profile "$bt_card" headset-head-unit >/dev/null 2>&1 || true
fi
fi
fi
return 0
}
vol_file_for_dev() {
dev="$(normalize_out_dev "$1")"
case "$dev" in
@@ -172,9 +211,23 @@ deviceget() {
read -r dev < /tmp/sxmo_audio_out_device 2>/dev/null || dev=""
if [ -n "$dev" ]; then
dev="$(normalize_out_dev "$dev")"
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ]; then
dev="Speaker"
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
if [ "$dev" = "Bluetooth" ]; then
bt_sink="$(find_bt_sink)"
if [ -n "$bt_sink" ]; then
sco_mm=0
[ -r /tmp/sxmo_bt_sco_mm_active ] && read -r sco_mm < /tmp/sxmo_bt_sco_mm_active 2>/dev/null || sco_mm=0
if [ "$sco_mm" != "1" ]; then
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
move_streams_to_sink "$bt_sink"
fi
elif [ -z "$(find_bt_card)" ] && [ ! -e /tmp/sxmo_bt_connecting ]; then
if [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" = "1" ]; then
dev="Headphones"
else
dev="Speaker"
fi
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
fi
fi
printf "%s\n" "$dev"
return 0
@@ -184,7 +237,7 @@ deviceget() {
read -r dev < "$CFG_DIR/audio_out_device" 2>/dev/null || dev=""
if [ -n "$dev" ]; then
dev="$(normalize_out_dev "$dev")"
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ]; then
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ] && [ -z "$(find_bt_card)" ]; then
dev="Speaker"
fi
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
@@ -520,16 +573,51 @@ sync_pipewire_profile() {
pactl set-card-profile "$ALSA_CARD" "$prof" >/dev/null 2>&1 || true
if [ "$out_dev" = "Bluetooth" ]; then
if [ "$want_sco_mm" = "1" ]; then
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
pactl set-default-sink "alsa_output.platform-7702000.sound.HiFi__Speaker__sink" >/dev/null 2>&1 || true
move_streams_to_sink "alsa_output.platform-7702000.sound.HiFi__Speaker__sink"
else
if [ ! -r /tmp/sxmo_in_call ]; then
ensure_bt_a2dp_profile || true
fi
bt_sink="$(find_bt_sink)"
if [ -n "$bt_sink" ]; then
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
move_streams_to_sink "$bt_sink"
else
touch /tmp/sxmo_bt_connecting 2>/dev/null || true
(
for _i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
sleep 0.25
cur_want="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || true)"
[ "$cur_want" = "Bluetooth" ] || break
if [ ! -r /tmp/sxmo_in_call ]; then
ensure_bt_a2dp_profile || true
fi
bt_sink="$(find_bt_sink)"
if [ -n "$bt_sink" ]; then
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
pactl set-default-sink "$bt_sink" >/dev/null 2>&1 || true
move_streams_to_sink "$bt_sink"
out_vol="$(read_dev_vol Bluetooth)"
apply_alsa_out Bluetooth "$out_vol"
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
if [ -p /tmp/dwm_plugin_networks.fifo ]; then
printf "REFRESH\n" > /tmp/dwm_plugin_networks.fifo 2>/dev/null || true
fi
exit 0
fi
done
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
) >/dev/null 2>&1 &
fi
fi
else
rm -f /tmp/sxmo_bt_connecting 2>/dev/null || true
sink_name="alsa_output.platform-7702000.sound.HiFi__${out_dev}__sink"
pactl set-default-sink "$sink_name" >/dev/null 2>&1 || true
move_streams_to_sink "$sink_name"
fi
if [ "$in_dev" = "Bluetooth" ]; then
if [ "$want_sco_mm" = "1" ]; then
@@ -714,7 +802,7 @@ devicesetinput() {
}
devicelist() {
if [ -n "$(find_bt_sink)" ]; then
if [ -n "$(find_bt_sink)" ] || [ -n "$(find_bt_card)" ]; then
printf "Bluetooth\nSpeaker\nEarpiece\nHeadphones\n"
else
printf "Speaker\nEarpiece\nHeadphones\n"
@@ -733,7 +821,9 @@ devicecycle() {
dir="${1:-next}"
cur="$(deviceget)"
has_bt=0
[ -n "$(find_bt_sink)" ] && has_bt=1
if [ -n "$(find_bt_sink)" ] || [ -n "$(find_bt_card)" ]; then
has_bt=1
fi
if [ "$dir" = "prev" ]; then
if [ "$has_bt" = "1" ]; then
case "$cur" in