scripts: Remove bar animations from vol/brightness

Removed the ascii-art bar animations calculated for e.g. dunst
notifications for the controls of brightness and volume.

The dunst notifications finally have a working bar slider built into
them when invoked with the correct stack option.
This commit is contained in:
Marty Oehme 2021-06-02 23:30:47 +02:00
parent 0b2c6c9b4b
commit 226c4b5f0d
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 78 additions and 84 deletions

View file

@ -7,7 +7,7 @@
# inspired from https://gist.github.com/Blaradox/030f06d165a82583ae817ee954438f2e
usage() {
echo "usage: control-brightness up|down [step], where step can be any int value
echo "usage: control-brightness up|down [step], where step can be any int value
or: control-brightness set target, where target can be an int value 0-100"
}
@ -15,43 +15,39 @@ direction=$1
step=${2:-10}
get_brightness() {
xbacklight -get | cut -d. -f1
xbacklight -get | cut -d. -f1
}
send_notification() {
icon="preferences-system-brightness-lock"
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 "─" $((brightness / 5)) | sed 's/[0-9]//g')
if type dunstify 1>/dev/null 2>/dev/null; then
notcmd="dunstify -h string:x-dunst-stack-tag:brightness"
else
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"
icon="preferences-system-brightness-lock"
brightness=$(get_brightness)
if type dunstify 1>/dev/null 2>/dev/null; then
notcmd="dunstify -h string:x-dunst-stack-tag:brightness"
else
notcmd="notify-send -h string:x-dunst-stack-tag:brightness"
fi
$notcmd -a "changeVolume" -u low -i "$icon" \
-h int:value:"$brightness" "Brightness: $brightness%"
}
case $direction in
up)
xbacklight -inc "$step"
send_notification
;;
xbacklight -inc "$step"
send_notification
;;
down)
xbacklight -dec "$step"
send_notification
;;
xbacklight -dec "$step"
send_notification
;;
set)
if [ -z "$step" ]; then
echo "set option requires target brightness to be specified."
return 1
fi
xbacklight -set "$step"
send_notification
;;
if [ -z "$step" ]; then
echo "set option requires target brightness to be specified."
return 1
fi
xbacklight -set "$step"
send_notification
;;
*)
echo "usage: control-brightness up|down [step], where step can be any int value"
;;
echo "usage: control-brightness up|down [step], where step can be any int value"
;;
esac

View file

@ -6,94 +6,92 @@ step=${2:-5dB}
# amixer channel to target
amixer_quiet() {
amixer -c 0 "$@" >/dev/null
amixer -c 0 "$@" >/dev/null
}
amixer_noisy="amixer -c 0 "
# Query amixer for the current volume
get_volume() {
$amixer_noisy get Master | tail -1 | awk '{print $4}' | sed 's/[^0-9]*//g'
$amixer_noisy get Master | tail -1 | awk '{print $4}' | sed 's/[^0-9]*//g'
}
# query amixer for mute state (off=muted)
get_mute() {
$amixer_noisy get Master | tail -1 | awk '{print $6}' | sed 's/[^a-z]*//g'
$amixer_noisy get Master | tail -1 | awk '{print $6}' | sed 's/[^a-z]*//g'
}
set_volume() {
# Change the volume using alsa(might differ if you use pulseaudio)
amixer_quiet set Master "$@" >/dev/null
# Change the volume using alsa(might differ if you use pulseaudio)
amixer_quiet set Master "$@" >/dev/null
# Play the volume changed sound
# -- this is *extremely* laggy (>8s) on my system, no idea why and no time to find out
# canberra-gtk-play -i audio-volume-change -d "changeVolume"
# Play the volume changed sound
# -- this is *extremely* laggy (>8s) on my system, no idea why and no time to find out
# canberra-gtk-play -i audio-volume-change -d "changeVolume"
}
# set mute state (off=mute)
set_mute() {
[ "$(get_mute)" = "on" ] && toggleto=off || toggleto=on
if [ "$1" = 'off' ]; then
amixer_quiet set Master mute
elif [ "$1" = 'on' ]; then
amixer_quiet set Master unmute
# the following is needed, see https://superuser.com/questions/805525/why-is-unmute-not-working-with-amixer-command
amixer_quiet set Speaker unmute
amixer_quiet set Headphone unmute
else
amixer_quiet set Master "$toggleto"
amixer_quiet set Speaker "$toggleto"
amixer_quiet set Headphone "$toggleto"
fi
[ "$(get_mute)" = "on" ] && toggleto=off || toggleto=on
if [ "$1" = 'off' ]; then
amixer_quiet set Master mute
elif [ "$1" = 'on' ]; then
amixer_quiet set Master unmute
# the following is needed, see https://superuser.com/questions/805525/why-is-unmute-not-working-with-amixer-command
amixer_quiet set Speaker unmute
amixer_quiet set Headphone unmute
else
amixer_quiet set Master "$toggleto"
amixer_quiet set Speaker "$toggleto"
amixer_quiet set Headphone "$toggleto"
fi
}
usage() {
echo "control-volume up|down [step], with step any int value
echo "control-volume up|down [step], with step any int value
or: control-brightness set [target], with target any int value 0-100"
}
send_notification() {
if type dunstify 1>/dev/null 2>/dev/null; then
notcmd="dunstify -h string:x-dunst-stack-tag:brightness"
else
notcmd="notify-send -h string:x-dunst-stack-tag:brightness"
fi
if type dunstify 1>/dev/null 2>/dev/null; then
notcmd="dunstify -h string:x-dunst-stack-tag:brightness"
else
notcmd="notify-send -h string:x-dunst-stack-tag:brightness"
fi
vol="$(get_volume)"
bar=$(seq -s "─" $((vol / 5)) | sed 's/[0-9]//g')
vol="$(get_volume)"
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%
$bar"
fi
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%"
fi
}
case $direction in
up)
set_volume "${step}+"
;;
set_volume "${step}+"
;;
down)
set_volume "${step}-"
;;
set_volume "${step}-"
;;
mute)
set_mute "$step"
;;
set_mute "$step"
;;
mutetoggle)
set_mute
;;
set_mute
;;
set)
if [ -z "$step" ]; then
echo "set option requires target brightness to be specified."
return 1
fi
set_volume "$step"
;;
if [ -z "$step" ]; then
echo "set option requires target brightness to be specified."
return 1
fi
set_volume "$step"
;;
*)
usage
;;
usage
;;
esac
send_notification