summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x.gitignore.d/fluxbox1
-rwxr-xr-xbin/bright62
2 files changed, 63 insertions, 0 deletions
diff --git a/.gitignore.d/fluxbox b/.gitignore.d/fluxbox
index 1664a9b..55ff1e6 100755
--- a/.gitignore.d/fluxbox
+++ b/.gitignore.d/fluxbox
@@ -21,6 +21,7 @@
!/.xinitrc.d/.placeholder
!/.xsession
!/bin/
+!/bin/bright
!/bin/xsession
!/lib/
!/lib/panel/
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 "${@}"