summaryrefslogtreecommitdiffstats
path: root/bin/bright
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2021-08-22 19:44:33 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2021-08-22 19:44:33 (EDT)
commitb7ebac8283285f6abeb3799a842f79dc15727c12 (patch)
treeff32f8b56fe61bdd2b3b41f8865977d23d90c2f6 /bin/bright
parent11ea13b80978e78830e1074556d242e380dbefc8 (diff)
downloadfluxbox-b7ebac8283285f6abeb3799a842f79dc15727c12.zip
fluxbox-b7ebac8283285f6abeb3799a842f79dc15727c12.tar.gz
fluxbox-b7ebac8283285f6abeb3799a842f79dc15727c12.tar.bz2
bin/bright: New script
Diffstat (limited to 'bin/bright')
-rwxr-xr-xbin/bright62
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/bright b/bin/bright
new file mode 100755
index 0000000..7aa0801
--- /dev/null
+++ b/bin/bright
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+set -eu
+
+get_b()
+{
+ local b=
+
+ b=$(brightnessctl --class=backlight get) || return 1
+ printf '%.0f\n' $(printf \
+ 'scale = 4; (7 * sqrt((2 - %d) * (%d - 3102))) / 1550\n' \
+ ${b} ${b} | bc)
+
+ return 0
+}
+
+set_b()
+{
+ local b="${1}"
+ shift 1
+
+ brightnessctl --class=backlight set $(printf '%.0f\n' \
+ $(printf 'scale = 4; 2 + (1 - sqrt(1 - (%d / 7)^2)) * 1550\n' \
+ ${b} | bc)) || return 1
+
+ return 0
+}
+
+usage()
+{
+ printf 'Usage: %s {-|+}\n' "${0}"
+
+ return 0
+}
+
+main()
+{
+ local dir=
+ local b=
+
+ if [ ${#} -ne 1 ]; then
+ usage 1>&2
+ return 1
+ fi
+ dir="${1}"
+ shift 1
+
+ case "${dir}" in
+ -|+);;
+ *)
+ usage 1>&2
+ return 1
+ ;;
+ esac
+
+ b=$(get_b) || return 1
+ set_b $((${b} ${dir} 1)) || return 1
+
+ return 0
+}
+
+main "${@}"