feat: simplify vol, light and am

This commit is contained in:
ange 2024-04-25 15:43:28 +02:00
parent 57243c81fa
commit 47c176f3bc
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
3 changed files with 46 additions and 66 deletions

View file

@ -13,7 +13,6 @@ function round() {
}
function get_current() {
local d="$1"
local cur; cur="$(cat "$1/brightness")"
local max; max="$(cat "$1/max_brightness")"
@ -21,22 +20,20 @@ function get_current() {
}
function set_light() {
local d="$1"
local max; max="$(cat "$d/max_brightness")"
local max; max="$(cat "$1/max_brightness")"
echo "$((CUR * max / 100))" > "$d/brightness"
echo "$((CUR * max / 100))" > "$1/brightness"
}
NOTIFY='notify-send -t 1000 -a changeBrightness -u low'
NOTIFYVOL="$NOTIFY -i audio-volume-high"
NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
DIRS=(/sys/class/backlight/*)
CUR="$(get_current "${DIRS[0]}")"
case "${1:0:1}" in
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$(round $((CUR + "$1")) "$1")" ;;
*) CUR="$1" ;;
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$(round $((CUR + $1)) "$1")" ;;
*) CUR="$1" ;;
esac
[ "$CUR" -lt 0 ] && CUR=0
@ -46,4 +43,4 @@ for d in "${DIRS[@]}"; do
set_light "$d"
done
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
"${NOTIFY[@]}" -h string:synchronous:light -h int:value:"$CUR" "$CUR%"