aboutsummaryrefslogtreecommitdiff
path: root/swob.sh
diff options
context:
space:
mode:
Diffstat (limited to 'swob.sh')
-rwxr-xr-xswob.sh23
1 files changed, 20 insertions, 3 deletions
diff --git a/swob.sh b/swob.sh
index f8f5d92..d47e980 100755
--- a/swob.sh
+++ b/swob.sh
@@ -12,7 +12,7 @@ set ${BASH_VERSION:+-o pipefail} -efu
# this is less likely.
wobdir=$XDG_RUNTIME_DIR/swob.$WAYLAND_DISPLAY
-wobfifo=$wobdir/pipe wobini= SWOB_AUDIO=
+wobfifo=$wobdir/pipe wobini= SWOB_AUDIO= SWOB_MAX_VOLUME=${SWOB_MAX_VOLUME:-100}
scan_confdirs() {
for dir in ${XDG_CONFIG_HOME:+"$XDG_CONFIG_HOME"} ~/.config /etc "${0%/*}"/../etc; do
@@ -95,6 +95,14 @@ get_audio_type() {
SWOB_AUDIO=alsa # default to ALSA
}
+pactl_vol() {
+ pactl set-sink-"$1" @DEFAULT_SINK@ "$(echo "$2" | sed -E 's/(.*)([+-])$/\2\1/')"
+}
+
+percent_to_float() {
+ awk -v percent="$1" 'BEGIN{printf "%.1f", percent/100}'
+}
+
set_vol() {
set +fu
get_audio_type
@@ -104,7 +112,7 @@ set_vol() {
pipewire)
case $1 in
toggle) to_set=mute ;;
- *) to_set='volume -l 1.0' ;;
+ *) to_set="volume -l $(percent_to_float "$SWOB_MAX_VOLUME")" ;;
esac
wpctl set-$to_set @DEFAULT_AUDIO_SINK@ "$1"
wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed -E \
@@ -117,8 +125,17 @@ set_vol() {
toggle) to_set=mute ;;
*) to_set=volume ;;
esac
- pactl set-sink-$to_set @DEFAULT_SINK@ "$(echo "$1" | sed -E 's/(.*)([+-])$/\2\1/')"
+ sign="${1:(-1)}"
percent=`pactl get-sink-volume @DEFAULT_SINK@ | sed -En 's/.* ([0-9]+)%.*/\1/p'`
+
+ if test "$to_set" = "mute" \
+ -o \( "$percent" -lt "$SWOB_MAX_VOLUME" \) \
+ -o \( "$percent" -eq "$SWOB_MAX_VOLUME" -a "$sign" = "-" \); then
+ pactl_vol "$to_set" "$1"
+ else
+ pactl set-sink-$to_set @DEFAULT_SINK@ "${SWOB_MAX_VOLUME}%"
+ fi
+
mute_cmd='pactl get-sink-mute @DEFAULT_SINK@'
mute_out=`$mute_cmd`
case $mute_out in