This removes the dependency on an external compiled app for writing the brightness value to sysfs, and just echoes it directly to the backlight sysfs node. In addition, if the write fails, the script exits instead of sending a misleading notification. Signed-off-by: Stacy Harper <contact@stacyharper.net>
40 lines
985 B
Bash
Executable file
40 lines
985 B
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# include common definitions
|
|
# shellcheck source=scripts/core/sxmo_common.sh
|
|
. "$(dirname "$0")/sxmo_common.sh"
|
|
|
|
BACKLIGHT="${BACKLIGHT:-/sys/devices/platform/backlight/backlight/backlight}"
|
|
if [ ! -e "$BACKLIGHT" ] && [ -e /sys/class/backlight/edp-backlight ]; then
|
|
BACKLIGHT=/sys/class/backlight/edp-backlight
|
|
fi
|
|
|
|
[ ! -e "$BACKLIGHT" ] && echo "unable to find backlight device" && exit 1
|
|
|
|
MAX=$(cat $BACKLIGHT/max_brightness)
|
|
MIN=2
|
|
MINSTEP=1
|
|
STEP=$(echo "($MAX - $MIN) / 10" | bc | xargs -ISTP echo -e "$MINSTEP\nSTP" | sort -r | head -n1)
|
|
|
|
setdelta() {
|
|
VAL="$(
|
|
xargs -IB echo B "$1" < $BACKLIGHT/brightness |
|
|
bc |
|
|
xargs -INUM echo -e "$MIN\nNUM" | sort -n | tail -n1 |
|
|
xargs -INUM echo -e "$MAX\nNUM" | sort -n | head -n1
|
|
)"
|
|
echo "$VAL" > "$BACKLIGHT/brightness" || exit 1
|
|
echo "set brightness to $VAL"
|
|
|
|
dunstify -i 0 -u normal -r 999 "☀ $(cat $BACKLIGHT/brightness)/${MAX}"
|
|
}
|
|
|
|
up() {
|
|
setdelta "+${STEP}"
|
|
}
|
|
|
|
down() {
|
|
setdelta "-${STEP}"
|
|
}
|
|
|
|
"$@"
|