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)
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
bar=$(seq -s "─" 0 $((brightness / 5)) | sed 's/[0-9]//g' |
sed -e 's/^─/┠/' -e 's/^\(.\{20\}\)/\1┫/')
bar=$(seq -s "─" $((brightness / 5)) | sed 's/[0-9]//g')
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
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
$notcmd -a "changeVolume" -u low -i "$icon" \
-h int:value:"$brightness" "Brightness: $brightness%
$bar"
}
case $direction in

View File

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