From f1344b61d2676acc2c7ea1320006bbf008e09977 Mon Sep 17 00:00:00 2001 From: dabruh <11458706-dabruh@users.noreply.gitlab.com> Date: Sat, 28 May 2022 23:51:20 +0200 Subject: [PATCH] Improved support for muting sources. --- .config/i3/config.post-main-10-audio | 4 ++-- .local/bin/pavolctl | 30 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.config/i3/config.post-main-10-audio b/.config/i3/config.post-main-10-audio index 54ebd20..9ba53ed 100644 --- a/.config/i3/config.post-main-10-audio +++ b/.config/i3/config.post-main-10-audio @@ -1,8 +1,8 @@ # Use pactl to adjust volume in PulseAudio. bindsym XF86AudioRaiseVolume exec --no-startup-id pavolctl +10% bindsym XF86AudioLowerVolume exec --no-startup-id pavolctl -10% -bindsym XF86AudioMute exec --no-startup-id pavolctl set-sink-mute -bindsym XF86AudioMicMute exec --no-startup-id pavolctl set-source-mute +bindsym XF86AudioMute exec --no-startup-id pavolctl toggle Master +bindsym XF86AudioMicMute exec --no-startup-id pavolctl toggle Capture # Set cmus controls bindsym XF86AudioStop exec --no-startup-id "cmusctl -c stop" diff --git a/.local/bin/pavolctl b/.local/bin/pavolctl index f1f69d0..3582caf 100755 --- a/.local/bin/pavolctl +++ b/.local/bin/pavolctl @@ -1,29 +1,35 @@ #!/bin/bash -SINK="@DEFAULT_SINK@" -LIMIT=150 -ADJUSTMENT=$1 +PULSEAUDIO_SINK="${PULSEAUDIO_SINK:-"@DEFAULT_SINK@"}" +VOLUME_LIMIT="${VOLUME_LIMIT:-150}" + +TARGET="$1" +ADJUSTMENT="$2" + +echo "${TARGET:?} ${ADJUSTMENT:?}" >/dev/null function limit_level() { - level="$(pactl get-sink-volume "$SINK" | grep '^Volume' | cut -d' ' -f5 | grep -o "[[:digit:]]*")" + level="$(pactl get-sink-volume "$PULSEAUDIO_SINK" | grep '^Volume' | cut -d' ' -f5 | grep -o "[[:digit:]]*")" - if [[ "$level" -gt "$LIMIT" ]]; then + if [[ "$level" -gt "$VOLUME_LIMIT" ]]; then echo "Limiting volume to: $1" - set_level $LIMIT% + set_level $VOLUME_LIMIT% fi } function set_level() { echo "Desired volume adjustment: $1" - pactl set-sink-volume "$SINK" "$1" + pactl set-sink-volume "$PULSEAUDIO_SINK" "$1" } -if [[ "$ADJUSTMENT" == set-*-mute ]]; then - echo "Desired volume adjustment: $1" - pactl "$ADJUSTMENT" "$SINK" toggle -else +if [[ "$TARGET" == "volume" ]]; then set_level "$ADJUSTMENT" - limit_level $LIMIT + limit_level "$VOLUME_LIMIT" +elif [[ "$TARGET" == "toggle" ]]; then + amixer -D pulse sset "$ADJUSTMENT" toggle +else + echo "Invalid option: $TARGET $ADJUSTMENT" + exit 1 fi killall -SIGUSR1 i3status