From 077b73c66e7e86a7e73c0e14c8cdb691bfc8a853 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Sun, 29 Jul 2018 13:50:32 -0400 Subject: kb-lights.py script fixed, moved to ~/.scripts --- .config/i3/config | 4 ++-- .config/i3/kb-lights.py | 35 ----------------------------------- .scripts/kb-lights.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 37 deletions(-) delete mode 100755 .config/i3/kb-lights.py create mode 100755 .scripts/kb-lights.py diff --git a/.config/i3/config b/.config/i3/config index e3c122a..b56efca 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -407,8 +407,8 @@ bindsym XF86MonBrightnessUp exec --no-startup-id xbacklight -inc 15 bindsym XF86AudioMedia exec --no-startup-id st -e ncmpcpp bindsym XF86Display exec --no-startup-id arandr #bindsym XF86KbdLightOnOff exec -bindsym XF86KbdBrightnessDown exec --no-startup-id python3.6 ~/.i3/kb-lights.py - -bindsym XF86KbdBrightnessUp exec --no-startup-id python3.6 ~/.i3/kb-lights.py + +bindsym XF86KbdBrightnessDown exec --no-startup-id python3.6 ~/.scripts/kb-lights.py - +bindsym XF86KbdBrightnessUp exec --no-startup-id python3.6 ~/.scripts/kb-lights.py + ##bindsym XF86Reply exec ##bindsym XF86MailForward exec ##bindsym XF86Save exec diff --git a/.config/i3/kb-lights.py b/.config/i3/kb-lights.py deleted file mode 100755 index f492de0..0000000 --- a/.config/i3/kb-lights.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/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.") diff --git a/.scripts/kb-lights.py b/.scripts/kb-lights.py new file mode 100755 index 0000000..f492de0 --- /dev/null +++ b/.scripts/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.") -- cgit v1.3.1