From 5e70179b8cd67e1a0acf9628cb9069c041b961e7 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 22 Oct 2016 20:27:58 +0200 Subject: [PATCH] announce toggle of Numlock, Capslock and Scrolllock --- src/fenrir/core/inputManager.py | 52 +++++++++++++++++++++++++++------ src/fenrir/inputDriver/evdev.py | 52 ++++++++++++++------------------- tools/traceEvdev.py | 3 ++ 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/src/fenrir/core/inputManager.py b/src/fenrir/core/inputManager.py index 5ca14160..a8464fda 100644 --- a/src/fenrir/core/inputManager.py +++ b/src/fenrir/core/inputManager.py @@ -10,17 +10,17 @@ from core import inputEvent class inputManager(): def __init__(self): - pass + self.setLedState = True def initialize(self, environment): self.env = environment self.env['runtime']['settingsManager'].loadDriver(\ self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver') # init LEDs with current state - self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock() + self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState() self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] - self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock() + self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getLedState(1) self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock'] - self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock() + self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2) self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] self.grabDevices() @@ -43,6 +43,7 @@ class inputManager(): if len(self.env['input']['currInput']) == 0: self.env['input']['prevDeepestInput'] = [] self.env['input']['shortcutRepeat'] = 1 + self.handleLedStates(mEvent) self.env['input']['lastInputTime'] = time.time() elif mEvent['EventState'] == 1: if not mEvent['EventName'] in self.env['input']['currInput']: @@ -56,22 +57,55 @@ class inputManager(): self.env['input']['shortcutRepeat'] += 1 else: self.env['input']['shortcutRepeat'] = 1 + self.handleLedStates(mEvent) self.env['input']['lastInputTime'] = time.time() elif mEvent['EventState'] == 2: - pass + self.env['input']['lastInputTime'] = time.time() else: pass self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] - self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock() + self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState() self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock'] - self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock() + self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getLedState(1) self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] - self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock() + self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2) self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO) if self.noKeyPressed(): self.env['input']['prevInput'] = [] + self.setLedState = True return eventReceived - + + def handleLedStates(self, mEvent): + if not self.setLedState: + return + if mEvent['EventName'] == 'KEY_NUMLOCK': + if mEvent['EventState'] == 1 and not self.env['input']['newNumLock'] == 1: + self.env['runtime']['inputDriver'].toggleLedState() + self.setLedState = False + return + if mEvent['EventState'] == 0 and not self.env['input']['newNumLock'] == 0: + self.env['runtime']['inputDriver'].toggleLedState() + self.setLedState = False + return + if mEvent['EventName'] == 'KEY_CAPSLOCK': + if mEvent['EventState'] == 1 and not self.env['input']['newCapsLock'] == 1: + self.env['runtime']['inputDriver'].toggleLedState(1) + self.setLedState = False + return + if mEvent['EventState'] == 0 and not self.env['input']['newCapsLock'] == 0: + self.env['runtime']['inputDriver'].toggleLedState(1) + self.setLedState = False + return + if mEvent['EventName'] == 'KEY_SCROLLLOCK': + if mEvent['EventState'] == 1 and not self.env['input']['newScrollLock'] == 1: + self.env['runtime']['inputDriver'].toggleLedState(2) + self.setLedState = False + return + if mEvent['EventState'] == 0 and not self.env['input']['newScrollLock'] == 0: + self.env['runtime']['inputDriver'].toggleLedState(2) + self.setLedState = False + return + def grabDevices(self): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): self.env['runtime']['inputDriver'].grabDevices() diff --git a/src/fenrir/inputDriver/evdev.py b/src/fenrir/inputDriver/evdev.py index 2bd61dff..bfe193f7 100644 --- a/src/fenrir/inputDriver/evdev.py +++ b/src/fenrir/inputDriver/evdev.py @@ -35,15 +35,16 @@ class driver(): for fd in r: event = self.iDevices[fd].read_one() while(event): - if not event: - return None self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) - if event.code != 0: - currMapEvent = self.env['runtime']['inputDriver'].mapEvent(event) - if not currMapEvent: - return currMapEvent - if currMapEvent['EventState'] in [0,1,2]: - return currMapEvent + if event.type == evdev.events.EV_KEY: + if event.code != 0: + currMapEvent = self.env['runtime']['inputDriver'].mapEvent(event) + if not currMapEvent: + return currMapEvent + if currMapEvent['EventState'] in [0,1,2]: + return currMapEvent + + event = self.iDevices[fd].read_one() return None @@ -96,34 +97,25 @@ class driver(): return mEvent except Exception as e: return None - - def getNumlock(self): - 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): + + def getLedState(self, led = 0): + # 0 = Numlock + # 1 = Capslock + # 2 = Rollen 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): - if self.ledDevices == {}: - return False - if self.ledDevices == None: - return False - for fd, dev in self.ledDevices.items(): - return 2 in dev.leds() + return led in dev.leds() return False - + def toggleLedState(self, led = 0): + ledState = self.getLedState(led) + for i in self.ledDevices: + if ledState == 1: + self.ledDevices[i].set_led(led , 0) + else: + self.ledDevices[i].set_led(led , 1) def grabDevices(self): # leve the old code until the new one is better tested # for fd in self.iDevices: diff --git a/tools/traceEvdev.py b/tools/traceEvdev.py index 3988953c..c83374bc 100755 --- a/tools/traceEvdev.py +++ b/tools/traceEvdev.py @@ -7,6 +7,9 @@ import time devices = map(evdev.InputDevice, (evdev.list_devices())) devices = {dev.fd: dev for dev in devices} +for fd in devices: + for i in devices[fd].capabilities(True): + print(devices[fd].fn,devices[fd].name,i) while True: r, w, x = select(devices, [], []) if r != []: