scripts: Add unified volume bars to control scripts

`control-brightness` and `control-volume` both now have the exact same
progress bar indicator.
Additionally, by using the same dunst 'stack' they replace each other if
invoked in quick succession, which I really like.
This commit is contained in:
Marty Oehme 2021-03-17 15:06:02 +01:00
parent a6b3a973bb
commit 5ce6111f51
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 10 additions and 5 deletions

View file

@ -23,13 +23,15 @@ send_notification() {
brightness=$(get_brightness) brightness=$(get_brightness)
# Make the bar with the special character ─ (it's not dash -) # Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character # https://en.wikipedia.org/wiki/Box-drawing_character
bar=$(seq -s "─" 0 $((brightness / 5)) | sed 's/[0-9]//g' | bar=$(seq -s "─" $((brightness / 5)) | sed 's/[0-9]//g')
sed -e 's/^─/┠/' -e 's/^\(.\{20\}\)/\1┫/')
if type dunstify 1>/dev/null 2>/dev/null; then if type dunstify 1>/dev/null 2>/dev/null; then
dunstify -i "$icon" -u normal " $bar" -a "xbacklight" -h string:x-dunst-stack-tag:brightness notcmd="dunstify -h string:x-dunst-stack-tag:brightness"
else else
notify-send -i "$icon" -u normal " $bar" -a "xbacklight" -h string:x-dunst-stack-tag:brightness notcmd="notify-send -h string:x-dunst-stack-tag:brightness"
fi fi
$notcmd -a "changeVolume" -u low -i "$icon" \
-h int:value:"$brightness" "Brightness: $brightness%
$bar"
} }
case $direction in case $direction in

View file

@ -54,13 +54,16 @@ send_notification() {
fi fi
vol="$(get_volume)" vol="$(get_volume)"
bar=$(seq -s "─" $((vol / 5)) | sed 's/[0-9]//g')
if [ "$vol" -eq 0 ] || [ "$(get_mute)" = "off" ]; then if [ "$vol" -eq 0 ] || [ "$(get_mute)" = "off" ]; then
# Show the sound muted notification # Show the sound muted notification
$notcmd -a "changeVolume" -u low -i audio-volume-muted "Volume muted" $notcmd -a "changeVolume" -u low -i audio-volume-muted "Volume muted"
else else
# Show the volume notification # Show the volume notification
$notcmd -a "changeVolume" -u low -i audio-volume-high \ $notcmd -a "changeVolume" -u low -i audio-volume-high \
-h int:value:"$vol" "Volume: $vol%" -h int:value:"$vol" "Volume: $vol%
$bar"
fi fi
} }