distribution/packages/jelos/sources/scripts/brightness

73 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Fewtarius
BRIGHTNESS_DEV="$(find /sys/class/backlight/*/ -name brightness -print -quit)"
BRIGHTNESS_PATH="${BRIGHTNESS_DEV%/brightness}"
MIN=0
MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit))
STEP=$(( ${MAX} / 10 ))
# Ensure set_setting exists in all contexts
if ! type set_setting &>/dev/null
then
source /etc/profile
fi
if [ ! -f "${BRIGHTNESS_DEV}" ]
then
echo "ERROR: There is no BRIGHTNESS object to manage."
exit 1
fi
getBrightness() {
echo $(<${BRIGHTNESS_DEV})
}
setBrightness() {
echo "${1}" > ${BRIGHTNESS_DEV}
set_setting system.brightness "$(( ${1} / ${STEP} ))"
}
stepUp() {
MYBRIGHTNESS=$(getBrightness)
NEWBRIGHTNESS=$((${MYBRIGHTNESS}+${STEP}))
if (( ${NEWBRIGHTNESS} > ${MAX} ))
then
NEWBRIGHTNESS=${MAX}
fi
setBrightness ${NEWBRIGHTNESS}
}
stepDown() {
MYBRIGHTNESS=$(getBrightness)
NEWBRIGHTNESS=$((${MYBRIGHTNESS}-${STEP}))
if (( ${NEWBRIGHTNESS} < ${MIN} ))
then
NEWBRIGHTNESS=${MIN}
fi
setBrightness ${NEWBRIGHTNESS}
}
case ${1} in
"up")
stepUp
;;
"down")
stepDown
;;
"device")
echo ${BRIGHTNESS_DEV}
;;
"path")
echo ${BRIGHTNESS_PATH}
;;
"set")
setBrightness "$(( ${STEP} * ${2} ))"
;;
*)
echo $(getBrightness)
;;
esac