summaryrefslogtreecommitdiffstats
path: root/.config/i3/kb-lights.py
diff options
context:
space:
mode:
authorLuke <luke@lukesmith.xyz>2018-01-21 18:29:48 -0700
committerLuke <luke@lukesmith.xyz>2018-01-21 18:29:48 -0700
commit50adee4e79febf6f74594604e9f7083461b04227 (patch)
tree54036701bd0957e51521e7f51d4d3b49450f22da /.config/i3/kb-lights.py
parent68bd2acdc8f8040deab188c748d207d93ba923ca (diff)
downloadeibhear-50adee4e79febf6f74594604e9f7083461b04227.tar.gz
eibhear-50adee4e79febf6f74594604e9f7083461b04227.tar.zst
eibhear-50adee4e79febf6f74594604e9f7083461b04227.zip
"first" commit, preparing for LARBS 2.0
Diffstat (limited to '.config/i3/kb-lights.py')
-rwxr-xr-x.config/i3/kb-lights.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/.config/i3/kb-lights.py b/.config/i3/kb-lights.py
new file mode 100755
index 0000000..f492de0
--- /dev/null
+++ b/.config/i3/kb-lights.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# coding: utf-8
+
+from sys import argv
+import dbus
+
+
+def kb_light_set(delta):
+ bus = dbus.SystemBus()
+ kbd_backlight_proxy = bus.get_object('org.freedesktop.UPower', '/org/freedesktop/UPower/KbdBacklight')
+ kbd_backlight = dbus.Interface(kbd_backlight_proxy, 'org.freedesktop.UPower.KbdBacklight')
+
+ current = kbd_backlight.GetBrightness()
+ maximum = kbd_backlight.GetMaxBrightness()
+ new = max(0, current + delta)
+
+ if 0 <= new <= maximum:
+ current = new
+ kbd_backlight.SetBrightness(current)
+
+ # Return current backlight level percentage
+ return 100 * current / maximum
+
+if __name__ == '__main__':
+ if len(argv[1:]) == 1:
+ if argv[1] == "--up" or argv[1] == "+":
+ # ./kb-light.py (+|--up) to increment
+ print(kb_light_set(1))
+ elif argv[1] == "--down" or argv[1] == "-":
+ # ./kb-light.py (-|--down) to decrement
+ print(kb_light_set(-1))
+ else:
+ print("Unknown argument:", argv[1])
+ else:
+ print("Script takes exactly one argument.", len(argv[1:]), "arguments provided.")