From bef643c5a2e9d25fea4210e4b4d58a81ee0f025f Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 31 May 2017 05:16:12 +0200 Subject: pkgs/profpatsch/backlight: init --- pkgs/profpatsch/backlight/backlight.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 pkgs/profpatsch/backlight/backlight.py (limited to 'pkgs/profpatsch/backlight/backlight.py') diff --git a/pkgs/profpatsch/backlight/backlight.py b/pkgs/profpatsch/backlight/backlight.py new file mode 100755 index 00000000..d580260a --- /dev/null +++ b/pkgs/profpatsch/backlight/backlight.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# xbacklight uses a linear percentage, +# but the backlight intensity is actually logarithmic *facepalm*. +# So we read the current "percentage" given by xbacklight +# and calculate the next step, base 2. + +import subprocess as sub +import math +import sys + +xbacklight = "xbacklight" + +def usage(): + print("usage: backlight [inc|dec]", file=sys.stderr) + sys.exit(1) + +# read current value +current_backlight = float(sub.run(xbacklight, stdout=sub.PIPE).stdout.strip()) +# find the actual value, base 2 +current_val = round(math.sqrt(current_backlight)) + +if len(sys.argv) == 1: usage() +else: + mode = sys.argv[1] + +# modify actual value +if mode == "inc": + new_val = current_val + 1 +elif mode == "dec": + new_val = current_val - 1 +else: + usage() + +# clamp value +new_backlight = min(10, max(0, new_val)) + +# pow it again and set +sub.run([xbacklight, "-set", str(math.pow(new_backlight, 2))]) -- cgit 1.4.1