From 0b7fff402abfdcd2ae66b8f12b0fc2ef8a61d5fe Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 18 Nov 2025 12:44:46 +0100 Subject: [PATCH] rework volume control --- usr/bin/x-volume | 56 +++++++++++++++++++++++++++++++++++++++++++ usr/bin/x-volume-down | 6 ----- usr/bin/x-volume-mute | 6 ----- usr/bin/x-volume-up | 6 ----- 4 files changed, 56 insertions(+), 18 deletions(-) create mode 100755 usr/bin/x-volume delete mode 100755 usr/bin/x-volume-down delete mode 100755 usr/bin/x-volume-mute delete mode 100755 usr/bin/x-volume-up diff --git a/usr/bin/x-volume b/usr/bin/x-volume new file mode 100755 index 0000000..63f860d --- /dev/null +++ b/usr/bin/x-volume @@ -0,0 +1,56 @@ +#!/usr/bin/env sh + +# the amount to increase / decrease each time +[ -z "$AMOUNT" ] && AMOUNT=5 + +# utility for sending notifications easily +notify() { + notify-send "$@" -h string:x-dunst-stack-tag:'audioctl' -a 'audioctl' +} + +# get current volume information +vol_str="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)" + +# Remove leading non-numeric or zero characters, then remove remaining non-numeric characters. +# NOTE: if zero (0.00), the string will be empty. This is fine for arithmetic operations. +vol_int="$(echo "$vol_str" | sed 's/^[^1-9]*//; s/[^0-9]//g')" + +# if the string contains MUTED, set the variable accordion +case "$vol_str" in +*MUTED*) vol_off=1 ;; +*) vol_off=0 ;; +esac + +# handle what action to perform from the argument +echo $vol_off +case $1 in +up) vol_int=$((vol_int + AMOUNT)) ;; +down) vol_int=$((vol_int - AMOUNT)) ;; +mute) vol_off=$((!vol_off)) ;; +*) + echo 'E: could not decide what audio action to perform!' >&2 + notify 'could not decide what audio action to perform!' -u critical -t 5000 + exit 1 + ;; +esac +vol_int=$((vol_int - (vol_int % AMOUNT))) +vol_pcnt=$(echo "scale = 2; $vol_int / 100;" | bc) + +echo $vol_off +wpctl set-volume @DEFAULT_AUDIO_SINK@ "$vol_pcnt" +wpctl set-mute @DEFAULT_AUDIO_SINK@ "$vol_off" + +play -n synth 0.005 sine 1000 vol 0.2 2>/dev/null + +if [ "$vol_int" -eq 0 ] || [ "$vol_off" -eq 1 ]; then + ico=audio-volume-muted +elif [ "$vol_int" -lt 33 ]; then + ico=audio-volume-low +elif [ "$vol_int" -lt 66 ]; then + ico=audio-volume-medium +else + ico=audio-volume-high +fi + +str="volume: $vol_int% $([ $vol_off -eq 1 ] && printf '(MUTE)')" +notify -i "$ico" -u low -h "int:value:$vol_int" "$str" diff --git a/usr/bin/x-volume-down b/usr/bin/x-volume-down deleted file mode 100755 index be2445b..0000000 --- a/usr/bin/x-volume-down +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/sh -wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && play -n synth 0.005 sine 1000 vol 0.2 - -vol_str=$(wpctl get-volume @DEFAULT_AUDIO_SINK@) -vol_int="$(echo "$vol_str" | sed 's/[^0-9]*//g')" -notify-send -i audio-volume-low -u low -h int:value:"$vol_int" -h string:x-dunst-stack-tag:'audioctl' -a 'audioctl' "$vol_str" diff --git a/usr/bin/x-volume-mute b/usr/bin/x-volume-mute deleted file mode 100755 index 7b5dfdc..0000000 --- a/usr/bin/x-volume-mute +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/sh -wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle - -vol_str=$(wpctl get-volume @DEFAULT_AUDIO_SINK@) -vol_int="$(echo "$vol_str" | sed 's/[^0-9]*//g')" -notify-send -i audio-volume-muted -u low -h int:value:"$vol_int" -h string:x-dunst-stack-tag:'audioctl' -a 'audioctl' "$vol_str" diff --git a/usr/bin/x-volume-up b/usr/bin/x-volume-up deleted file mode 100755 index 1cbf76f..0000000 --- a/usr/bin/x-volume-up +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/sh -wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ && play -n synth 0.005 sine 1000 vol 0.2 - -vol_str=$(wpctl get-volume @DEFAULT_AUDIO_SINK@) -vol_int="$(echo "$vol_str" | sed 's/[^0-9]*//g')" -notify-send -i audio-volume-high -u low -h int:value:"$vol_int" -h string:x-dunst-stack-tag:'audioctl' -a 'audioctl' "$vol_str"