68 lines
1.2 KiB
Plaintext
68 lines
1.2 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
## Copyright (C) 2020-2023 Aditya Shakya <adi1090x@gmail.com>
|
||
|
##
|
||
|
## Brightness Executor For Tint2
|
||
|
|
||
|
# Graphics card
|
||
|
CARD=`ls /sys/class/backlight | head -n 1`
|
||
|
|
||
|
# Get brightness
|
||
|
get_backlight() {
|
||
|
if [[ "$CARD" == *"intel_"* ]]; then
|
||
|
BNESS=`xbacklight -get`
|
||
|
LIGHT=${BNESS%.*}
|
||
|
else
|
||
|
LIGHT=$(printf "%.0f\n" `light -G`)
|
||
|
fi
|
||
|
echo "${LIGHT}%"
|
||
|
}
|
||
|
|
||
|
# Get icons
|
||
|
get_icon() {
|
||
|
backlight="$(get_backlight)"
|
||
|
current="${backlight%%%}"
|
||
|
if [[ ("$current" -ge "0") && ("$current" -le "25") ]]; then
|
||
|
icon=''
|
||
|
elif [[ ("$current" -ge "25") && ("$current" -le "50") ]]; then
|
||
|
icon=''
|
||
|
elif [[ ("$current" -ge "50") && ("$current" -le "75") ]]; then
|
||
|
icon=''
|
||
|
elif [[ ("$current" -ge "75") && ("$current" -le "100") ]]; then
|
||
|
icon=''
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Get status
|
||
|
get_status() {
|
||
|
get_icon
|
||
|
echo "$icon $(get_backlight)"
|
||
|
}
|
||
|
|
||
|
# Increase brightness
|
||
|
inc_backlight() {
|
||
|
if [[ "$CARD" == *"intel_"* ]]; then
|
||
|
xbacklight -inc 10
|
||
|
else
|
||
|
light -A 5
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Decrease brightness
|
||
|
dec_backlight() {
|
||
|
if [[ "$CARD" == *"intel_"* ]]; then
|
||
|
xbacklight -dec 10
|
||
|
else
|
||
|
light -U 5
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Execute accordingly
|
||
|
if [[ "$1" == "--inc" ]]; then
|
||
|
inc_backlight
|
||
|
elif [[ "$1" == "--dec" ]]; then
|
||
|
dec_backlight
|
||
|
else
|
||
|
echo "`get_status`"
|
||
|
fi
|