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

View file

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