Improved support for muting sources.

This commit is contained in:
dabruh 2022-05-28 23:51:20 +02:00
parent 70cf73dc8c
commit f1344b61d2
2 changed files with 20 additions and 14 deletions

View File

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

View File

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