You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openbox/bin/brightness.bash

60 lines
1.2 KiB
Bash

#!/bin/bash
##
# Change brightness and show a notification
multiply-by-10-and-strip-decimals() {
declare number="$1"
bc <<<"10 * $number" | sed 's/\..*$//g'
}
current-brightness() {
xrandr --current --verbose | grep -Pom 1 '(?<=Brightness: ).*'
}
bar() {
declare -i count="$1"
[[ $count -eq 0 ]] && return 0
printf '─'
((count--))
bar "$count"
}
prefix-with-zero-point() {
echo "0.$1"
}
current-output() {
xrandr --query | grep -Po '^.*(?= connected)'
}
set-brightness() {
declare output="$1" brightness="$2"
xrandr --output "$output" --brightness "$brightness"
}
notify-brightness() {
notify-send.sh \
--replace-file=$HOME/.cache/clopper-ob/brightness.id \
" $(bar $((3 * $(multiply-by-10-and-strip-decimals $(current-brightness)))))"
}
increase-brightness() {
if [[ $(multiply-by-10-and-strip-decimals $(current-brightness)) -ge 10 ]]; then
return 0
fi
set-brightness "$(current-output)" "$(bc <<<"$(current-brightness) + 0.1")"
}
decrease-brightness() {
set-brightness "$(current-output)" "$(bc <<<"$(current-brightness) - 0.1")"
}
if [[ $1 == '+' ]]; then
increase-brightness
elif [[ $1 == '-' ]]; then
decrease-brightness
fi
notify-brightness