commit 0b7f31735e240c270d00e7568286bb91e55e276a Author: Burathar Date: Mon Jun 22 11:14:43 2020 +0200 Add initial files diff --git a/theme_daemon.py b/theme_daemon.py new file mode 100755 index 0000000..c936e7c --- /dev/null +++ b/theme_daemon.py @@ -0,0 +1,58 @@ +#! /bin/python3 +import sys +import time +import signal +from openrazer_command import Keyboard, Color +from evdev import InputDevice, ecodes + +class GracefulKiller: + kill_now = False + def __init__(self): + signal.signal(signal.SIGINT, self.exit_gracefully) + signal.signal(signal.SIGTERM, self.exit_gracefully) + + def exit_gracefully(self,signum, frame): + self.kill_now = True + +keyboard = Keyboard() + +if not keyboard.found_keyboard(): + print("No keyboard was found") + exit() + +def redraw(capslock_enabled, numlock_enabled): + keyboard.set_static(Color(0,100,0)) + + if capslock_enabled: + keyboard.set_keys(Color(255,255,255), 'caps_lock') + + if numlock_enabled: + keyboard.set_keys(Color(255,255,255), 'num_lock') + + keyboard.draw() + +def daemon(): + device = InputDevice('/dev/input/by-id/usb-Razer_Razer_BlackWidow_Chroma_V2-event-kbd') + capslock_enabled = False + numlock_enabled = False + killer = GracefulKiller() + + while not killer.kill_now: + update = False + + capslock_previous = capslock_enabled + numlock_previous = numlock_enabled + leds = device.leds() + capslock_enabled = 1 in leds + numlock_enabled = 0 in leds + if capslock_previous != capslock_enabled or numlock_previous != numlock_enabled: + update = True + + if update: + redraw(capslock_enabled, numlock_enabled) + + time.sleep(.1) + sys.exit(0) + +if __name__=='__main__': + daemon()