2020-12-20 22:13:36 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# Brightness control script using xbacklight
|
|
|
|
# Will use notify-send to create brightness notifications, if dunst is used
|
|
|
|
# or the notification daemon supports tag stacks, will automatically update
|
|
|
|
# the same notifications and not create new ones.
|
|
|
|
#
|
|
|
|
# inspired from https://gist.github.com/Blaradox/030f06d165a82583ae817ee954438f2e
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
direction=$1
|
|
|
|
step=${2:-10}
|
|
|
|
|
|
|
|
get_brightness() {
|
|
|
|
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
|
2021-03-17 14:06:02 +00:00
|
|
|
bar=$(seq -s "─" $((brightness / 5)) | sed 's/[0-9]//g')
|
2020-12-20 22:13:36 +00:00
|
|
|
if type dunstify 1>/dev/null 2>/dev/null; then
|
2021-03-17 14:06:02 +00:00
|
|
|
notcmd="dunstify -h string:x-dunst-stack-tag:brightness"
|
2020-12-20 22:13:36 +00:00
|
|
|
else
|
2021-03-17 14:06:02 +00:00
|
|
|
notcmd="notify-send -h string:x-dunst-stack-tag:brightness"
|
2020-12-20 22:13:36 +00:00
|
|
|
fi
|
2021-03-17 14:06:02 +00:00
|
|
|
$notcmd -a "changeVolume" -u low -i "$icon" \
|
|
|
|
-h int:value:"$brightness" "Brightness: $brightness%
|
|
|
|
$bar"
|
2020-12-20 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case $direction in
|
|
|
|
up)
|
|
|
|
xbacklight -inc "$step"
|
|
|
|
send_notification
|
|
|
|
;;
|
|
|
|
down)
|
|
|
|
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
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "usage: control-brightness up|down [step], where step can be any int value"
|
|
|
|
;;
|
|
|
|
esac
|