feat: cleaner light/vol rounds

This commit is contained in:
ange 2024-05-18 22:15:56 +02:00
parent 202436aafa
commit 7b202de6cc
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
5 changed files with 8 additions and 17 deletions

View file

@ -1,17 +1,5 @@
#!/bin/bash -e
function round() {
local nb="$1"
local closest="${2#-}"
local mod; mod="$((nb % closest))"
if [ "$mod" -lt "$((closest / 2))" ]; then
echo "$((nb - mod))"
else
echo "$((nb + closest - mod))"
fi
}
function get_current() {
local cur; cur="$(cat "$1/brightness")"
local max; max="$(cat "$1/max_brightness")"
@ -30,11 +18,14 @@ NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
DIRS=(/sys/class/backlight/*)
CUR="$(get_current "${DIRS[0]}")"
echo "$CUR"
echo "\$(($CUR + $1 - $CUR % $1 + $CUR % $1 / $1 * $1))"
case "${1:0:1}" in
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$(round $((CUR + $1)) "$1")" ;;
'+'|'-') CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))" ;;
*) CUR="$1" ;;
esac
echo "$CUR"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 100 ] && CUR=100

View file

@ -5,7 +5,7 @@ NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
function update_vol() {
if [[ "$1" =~ ^(-|\+)* ]]; then
CUR="$((CUR - CUR % $1 + $1))"
CUR="$(($CUR + $1 - $CUR % $1 + $CUR % $1 * 10 / $1 / 5 * $1))"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 150 ] && CUR=150
else