From 405cb53fb6cef98e68e545869a26f2cd335e82d5 Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Mon, 31 Oct 2022 11:46:45 +0100 Subject: [PATCH] Notify sound change on actual changes pactl subscribe get spammed a lot. I think we have to check for value difference before notifying --- scripts/core/sxmo_soundmonitor.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/core/sxmo_soundmonitor.sh b/scripts/core/sxmo_soundmonitor.sh index 048df53..0f7307e 100755 --- a/scripts/core/sxmo_soundmonitor.sh +++ b/scripts/core/sxmo_soundmonitor.sh @@ -6,15 +6,35 @@ # shellcheck source=scripts/core/sxmo_common.sh . sxmo_common.sh +notify_volume_change() { + vol="$(sxmo_audio.sh vol get)" + + if [ "$vol" != "$lastvol" ]; then + sxmo_hook_statusbar.sh volume + sxmo_audio.sh notify + fi + + lastvol="$vol" +} + +notify_mic_volume_change() { + micvol="$(sxmo_audio.sh mic volget)" + + if [ "$micvol" != "$lastmicvol" ]; then + sxmo_hook_statusbar.sh volume + sxmo_audio.sh micnotify + fi + + lastmicvol="$micvol" +} + pactl subscribe | while read -r line; do case "$line" in "Event 'change' on sink "*) - sxmo_hook_statusbar.sh volume - sxmo_audio.sh notify + notify_volume_change ;; "Event 'change' on source "*) - sxmo_hook_statusbar.sh volume - sxmo_audio.sh micnotify + notify_mic_volume_change ;; esac done