X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=bin%2Fw530_backlight.sh;h=5b24fa7265de68ef3f5c578572cd16372d7b3c3b;hb=8d07083a5078d3252af1c3fc2b7b2015074e4ad9;hp=bce6b30039f635fec143094f071af741f11e986b;hpb=aa5386ee93ccdfcddbd0dc6226b8f809e77a74a0;p=config
diff --git a/bin/w530_backlight.sh b/bin/w530_backlight.sh
index bce6b30..5b24fa7 100755
--- a/bin/w530_backlight.sh
+++ b/bin/w530_backlight.sh
@@ -1,17 +1,32 @@
#!/bin/sh
+
# A very primitive backlight setter with a hardcoded backlight path, to replace
# xbacklight which currently does not work on my system.
-if ! echo "${1}" | egrep -q '^[0-9]+$'; then
- echo 'Argument must be a number.'
+
+if ! echo "${1}" | egrep -q '^[0-9]+$' && ! [ "${1}" = "+" -o "${1}" = "-" ]; then
+ echo 'Argument must be a number, or "+", or "-".'
exit 1
fi
-percentage=${1}
backlight_dir=/sys/class/backlight/intel_backlight
max_brightness=$(cat "${backlight_dir}"/max_brightness)
+target="${backlight_dir}"/brightness
+if [ "${1}" = "+" -o "${1}" = "-" ]; then
+ fract=$(expr "${max_brightness}" / 20)
+ cur_brightness=$(cat "${backlight_dir}"/brightness)
+ brightness=$(expr "${cur_brightness}" "${1}" "${fract}")
+ if [ "${brightness}" -gt "${max_brightness}" ]; then
+ brightness="${max_brightness}"
+ elif [ "${brightness}" -lt "0" ]; then
+ brightness=0
+ fi
+ sudo sh -c 'echo '"${brightness}"' > '"${target}"
+ exit 0
+fi
+percentage=${1}
if [ "${percentage}" = '100' ]; then
- sudo sh -c 'echo '"${max_brightness}"' > '"${backlight_dir}"'/brightness'
+ sudo sh -c 'echo '"${max_brightness}"' > '"${target}"
else
fract=$(expr "${max_brightness}" / 100)
brightness=$(expr "${percentage}" \* "${fract}")
- sudo sh -c 'echo '"${brightness}"' > '"${backlight_dir}"'/brightness'
+ sudo sh -c 'echo '"${brightness}"' > '"${target}"
fi