From b588957fb0ff8e203fcd5a5179344aeaad807b36 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 18 Sep 2016 03:22:54 +0200 Subject: [PATCH] fill numlock, scroll and capslock state information --- src/fenrir-package/core/inputEvent.py | 2 ++ src/fenrir-package/core/inputManager.py | 12 +++++-- src/fenrir-package/inputDriver/evdev.py | 45 ++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/fenrir-package/core/inputEvent.py b/src/fenrir-package/core/inputEvent.py index 68b0a293..239f4209 100644 --- a/src/fenrir-package/core/inputEvent.py +++ b/src/fenrir-package/core/inputEvent.py @@ -13,6 +13,8 @@ input = { 'lastInputTime':time.time(), 'oldNumLock': True, 'newNumLock':True, +'oldScrollLock': True, +'newScrollLock':True, 'oldCapsLock':False, 'newCapsLock':False } diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index cbc17324..a3014506 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -18,12 +18,13 @@ class inputManager(): environment['runtime']['inputDriver'].shutdown(environment) def proceedInputEvent(self, environment): + timeout = True event = environment['runtime']['inputDriver'].getInput(environment) mEvent = environment['runtime']['inputDriver'].mapEvent(environment, event) if mEvent and event: if mEvent['EventValue'] == 0: - return True + return True timeout = False if mEvent['EventState'] == 0: if self.isFenrirKey(environment, mEvent): @@ -40,8 +41,13 @@ class inputManager(): elif mEvent['EventState'] == 2: pass else: - pass - print(environment['input']['currInput']) + pass + environment['input']['oldNumLock'] = environment['input']['newNumLock'] + environment['input']['newNumLock'] = environment['runtime']['inputDriver'].getNumlock(environment) + environment['input']['oldCapsLock'] = environment['input']['newCapsLock'] + environment['input']['newCapsLock'] = environment['runtime']['inputDriver'].getCapslock(environment) + environment['input']['oldScrollLock'] = environment['input']['newScrollLock'] + environment['input']['newScrollLock'] = environment['runtime']['inputDriver'].getScrollLock(environment) environment['input']['lastInputTime'] = time.time() environment['input']['shortcutRepeat'] = 1 return timeout diff --git a/src/fenrir-package/inputDriver/evdev.py b/src/fenrir-package/inputDriver/evdev.py index fe237014..24469c63 100644 --- a/src/fenrir-package/inputDriver/evdev.py +++ b/src/fenrir-package/inputDriver/evdev.py @@ -12,9 +12,10 @@ class driver(): def __init__(self): self.iDevices = {} self.uDevices = {} - self.getInputDevices() + self.ledDevices = {} + def initialize(self, environment): - pass + self.getInputDevices() def shutdown(self, environment): pass def getInput(self, environment): @@ -31,9 +32,16 @@ class driver(): uDevice.syn() def getInputDevices(self): + # 3 pos absolute + # 2 pos relative + # 17 LEDs + # 1 Keys + # we try to filter out mices and other stuff here self.iDevices = map(evdev.InputDevice, (evdev.list_devices())) - self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()} - + self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities() and not 3 in dev.capabilities() and not 2 in dev.capabilities()} + self.ledDevices = map(evdev.InputDevice, (evdev.list_devices())) + self.ledDevices = {dev.fd: dev for dev in self.ledDevices if 1 in dev.capabilities() and 17 in dev.capabilities() and not 3 in dev.capabilities() and not 2 in dev.capabilities()} + def mapEvent(self,environment, event): if not event: return None @@ -48,7 +56,34 @@ class driver(): except Exception as e: print(e) return None - + + def getNumlock(self,environment): + if self.ledDevices == {}: + return True + if self.ledDevices == None: + return True + for fd, dev in self.ledDevices.items(): + return 0 in dev.leds() + return True + + def getCapslock(self,environment): + if self.ledDevices == {}: + return False + if self.ledDevices == None: + return False + for fd, dev in self.ledDevices.items(): + return 1 in dev.leds() + return False + + def getScrollLock(self,environment): + if self.ledDevices == {}: + return False + if self.ledDevices == None: + return False + for fd, dev in self.ledDevices.items(): + return 2 in dev.leds() + return False + def grabDevices(self): for fd in self.iDevices: dev = self.iDevices[fd]