distribution/packages/jelos/sources/scripts/brightness

76 lines
1.5 KiB
Text
Raw Normal View History

2022-02-05 14:23:32 +00:00
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Fewtarius
BRIGHTNESS_DEV="$(ls /sys/class/backlight | head -n 1)"
2022-09-29 20:44:45 +00:00
MIN=1
2022-08-31 11:00:57 +00:00
MAX=$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/max_brightness)
if [ "${MAX}" = 255 ]
then
2022-09-29 20:44:45 +00:00
STEP=17
else
2022-09-29 20:44:45 +00:00
STEP=6
fi
if [[ -n "$2" ]]; then
STEP=$2
2022-02-05 14:23:32 +00:00
fi
# Ensure set_setting exists in all contexts
if ! type set_setting &>/dev/null
then
source /etc/profile
fi
2022-08-31 11:00:57 +00:00
if [ ! -f /sys/class/backlight/${BRIGHTNESS_DEV}/brightness ]
2022-02-05 14:23:32 +00:00
then
echo "ERROR: There is no BRIGHTNESS object to manage."
exit 1
fi
stepUp() {
getBrightness
MYBRIGHTNESS=$?
2022-09-29 20:44:45 +00:00
NEWBRIGHTNESS=$((${MYBRIGHTNESS}+${STEP}))
2022-02-05 14:23:32 +00:00
if (( ${NEWBRIGHTNESS} > ${MAX} ))
then
NEWBRIGHTNESS=${MAX}
fi
2022-08-31 11:00:57 +00:00
echo "${NEWBRIGHTNESS}" > /sys/class/backlight/${BRIGHTNESS_DEV}/brightness
2022-02-05 14:23:32 +00:00
set_setting system.brightness ${NEWBRIGHTNESS}
}
stepDown() {
getBrightness
MYBRIGHTNESS=$?
2022-09-29 20:44:45 +00:00
NEWBRIGHTNESS=$((${MYBRIGHTNESS}-${STEP}))
2022-02-05 14:23:32 +00:00
if (( ${NEWBRIGHTNESS} < ${MIN} ))
then
NEWBRIGHTNESS=${MIN}
fi
2022-08-31 11:00:57 +00:00
echo "${NEWBRIGHTNESS}" > /sys/class/backlight/${BRIGHTNESS_DEV}/brightness
2022-02-05 14:23:32 +00:00
set_setting system.brightness ${NEWBRIGHTNESS}
}
getBrightness() {
2022-08-31 11:00:57 +00:00
local BRIGHTNESS=$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/brightness)
2022-02-05 14:23:32 +00:00
return ${BRIGHTNESS}
}
case ${1} in
"up")
stepUp ${BRIGHTNESS}
;;
"down")
stepDown ${BRIGHTNESS}
;;
"device")
echo ${BRIGHTNESS_DEV}
;;
2022-02-05 14:23:32 +00:00
*)
getBrightness
echo $?
;;
esac