From 30f579f12b2ebf59b92d18bef098a02527d4cec5 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 18 Sep 2016 15:13:24 +0200 Subject: [PATCH] initial keyboard grab --- .../commands/commands/shut_up.py | 5 ++- .../commands/onInput/10000-shut_up.py | 14 ++++---- ...resent_char_if_cursor_change_horizontal.py | 19 +++++------ ...-present_line_if_cursor_change_vertical.py | 7 ++-- src/fenrir-package/core/commandManager.py | 1 + src/fenrir-package/core/inputManager.py | 32 ++++++++++++------- src/fenrir-package/fenrir.py | 13 ++++++-- src/fenrir-package/inputDriver/evdev.py | 21 ++++++++---- 8 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/fenrir-package/commands/commands/shut_up.py b/src/fenrir-package/commands/commands/shut_up.py index cb9c3968..0d530174 100644 --- a/src/fenrir-package/commands/commands/shut_up.py +++ b/src/fenrir-package/commands/commands/shut_up.py @@ -4,12 +4,11 @@ class command(): def __init__(self): pass def initialize(self, environment): - return environment + pass def shutdown(self, environment): - return environment + pass def getDescription(self, environment): return 'interrupts the current presentation' - def run(self, environment): environment['runtime']['outputManager'].interruptOutput(environment) def setCallback(self, callback): diff --git a/src/fenrir-package/commands/onInput/10000-shut_up.py b/src/fenrir-package/commands/onInput/10000-shut_up.py index aa29866e..d1fac41a 100644 --- a/src/fenrir-package/commands/onInput/10000-shut_up.py +++ b/src/fenrir-package/commands/onInput/10000-shut_up.py @@ -4,23 +4,23 @@ class command(): def __init__(self): pass def initialize(self, environment): - return environment + pass def shutdown(self, environment): - return environment + pass def getDescription(self, environment): return '' def run(self, environment): if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'interruptOnKeyPress'): - return environment + return + if environment['runtime']['inputManager'].noKeyPressed(environment): + return if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: - return environment + return # if environment['screenData']['newCursor'] == environment['screenData']['oldCursor'] and\ # environment['screenData']['newDelta'] == environment['screenData']['oldDelta']: # return environment - if environment['input']['currShortcut'] != '': - return environment environment['runtime']['outputManager'].interruptOutput(environment) - return environment + def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/onInput/54000-present_char_if_cursor_change_horizontal.py b/src/fenrir-package/commands/onInput/54000-present_char_if_cursor_change_horizontal.py index 43bf5bed..6154ecf9 100644 --- a/src/fenrir-package/commands/onInput/54000-present_char_if_cursor_change_horizontal.py +++ b/src/fenrir-package/commands/onInput/54000-present_char_if_cursor_change_horizontal.py @@ -4,33 +4,34 @@ class command(): def __init__(self): pass def initialize(self, environment): - return environment + pass def shutdown(self, environment): - return environment + pass def getDescription(self, environment): return '' def run(self, environment): # TTY Change if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: - return environment + return + if environment['runtime']['inputManager'].noKeyPressed(environment): + return # detect an change on the screen, we just want to cursor arround, so no change should appear if environment['screenData']['newDelta'] != '': - return environment + return if environment['screenData']['newNegativeDelta'] != '': - return environment + return # is it a horizontal change? if environment['screenData']['newCursor']['y'] != environment['screenData']['oldCursor']['y'] or\ environment['screenData']['newCursor']['x'] == environment['screenData']['oldCursor']['x']: - return environment - + return + print('drin') if environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']][environment['screenData']['newCursor']['x']].strip() == '': pass #environment['runtime']['outputManager'].presentText(environment, "blank",True) else: environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']][environment['screenData']['newCursor']['x']],interrupt=True) - - return environment + def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/onInput/55000-present_line_if_cursor_change_vertical.py b/src/fenrir-package/commands/onInput/55000-present_line_if_cursor_change_vertical.py index b36a74af..bf0db01c 100644 --- a/src/fenrir-package/commands/onInput/55000-present_line_if_cursor_change_vertical.py +++ b/src/fenrir-package/commands/onInput/55000-present_line_if_cursor_change_vertical.py @@ -4,9 +4,9 @@ class command(): def __init__(self): pass def initialize(self, environment): - return environment + pass def shutdown(self, environment): - return environment + pass def getDescription(self, environment): return '' @@ -21,8 +21,7 @@ class command(): environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True) else: environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']], True) - - return environment + def setCallback(self, callback): pass diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index 8d2fff19..33c3e03c 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -72,6 +72,7 @@ class commandManager(): environment['commands'][section][command].run(environment) except Exception as e: print(e) + environment['runtime']['debug'].writeDebugOut(environment,"Executing command:" + section + "." + command ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) self.clearCommandQueued(environment) diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 6de657be..5272ec51 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -17,7 +17,7 @@ class inputManager(): environment['input']['oldCapsLock'] = environment['input']['newCapsLock'] environment['input']['newScrollLock'] = environment['runtime']['inputDriver'].getScrollLock(environment) environment['input']['oldScrollLock'] = environment['input']['newScrollLock'] - #self.grabDevices(environment) + self.grabDevices(environment) def shutdown(self, environment): environment['runtime']['inputManager'].releaseDevices(environment) @@ -25,11 +25,9 @@ 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: + mEvent = environment['runtime']['inputDriver'].getInput(environment) + if mEvent: if mEvent['EventValue'] == 0: return True timeout = False @@ -45,7 +43,7 @@ class inputManager(): environment['input']['currInput'] = sorted(environment['input']['currInput']) elif mEvent['EventState'] == 1: if self.isFenrirKey(environment, mEvent): - if not 'KEY_FENRIR' in environment['input']['currInput']: + if not self.isFenrirKeyPressed(environment): environment['input']['currInput'].append('KEY_FENRIR') elif mEvent['EventName'] in ['KEY_RIGHTCTRL','KEY_LEFTCTRL'] : if not 'KEY_CTRL' in environment['input']['currInput']: @@ -76,20 +74,30 @@ class inputManager(): environment['runtime']['inputDriver'].grabDevices(environment) def releaseDevices(self, environment): - environment['runtime']['inputDriver'].releaseDevices() + environment['runtime']['inputDriver'].releaseDevices(environment) def isConsumeInput(self, environment): - return environment['input']['consumeKey'] and \ - not environment['input']['keyForeward'] or \ - not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices') + return environment['runtime']['commandManager'].isCommandQueued(environment) and \ + not environment['input']['keyForeward'] + #and + # not (environment['input']['keyForeward'] or \ + # environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices')) + + def clearEventBuffer(self, environment): + environment['runtime']['inputDriver'].clearEventBuffer(environment) - def passInput(self, environment): + def writeEventBuffer(self, environment): try: - environment['runtime']['inputDriver'] + environment['runtime']['inputDriver'].writeEventBuffer(environment) except Exception as e: + print(e) environment['runtime']['debug'].writeDebugOut(environment,"Error while writeUInput",debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR) + def isFenrirKeyPressed(self, environment): + return 'KEY_FENRIR' in environment['input']['currInput'] + def noKeyPressed(self, environment): + return environment['input']['currInput'] == [] def getPrevDeepestInput(self, environment): shortcut = [] shortcut.append(environment['input']['shortcutRepeat']) diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index b9fc9629..3788831f 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -41,16 +41,23 @@ class fenrir(): self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR) if not timeout: self.prepareCommand() - self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') - self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') + if not (self.environment['runtime']['inputManager'].isConsumeInput(self.environment) or \ + self.environment['runtime']['inputManager'].isFenrirKeyPressed(self.environment)): + self.environment['runtime']['inputManager'].writeEventBuffer(self.environment) + elif not self.environment['runtime']['commandManager'].isCommandQueued(self.environment) or self.environment['runtime']['inputManager'].noKeyPressed(self.environment): + self.environment['runtime']['inputManager'].clearEventBuffer(self.environment) + self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') + self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') + self.handleCommands() def prepareCommand(self): if self.environment['input']['keyForeward']: return + if time.time() - self.environment['commandInfo']['lastCommandExecutionTime'] < 0.2: + return shortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment) command = self.environment['runtime']['inputManager'].getCommandForShortcut(self.environment, shortcut) - print(command) self.environment['runtime']['commandManager'].queueCommand(self.environment, command) def handleCommands(self): diff --git a/src/fenrir-package/inputDriver/evdev.py b/src/fenrir-package/inputDriver/evdev.py index 24469c63..0f617733 100644 --- a/src/fenrir-package/inputDriver/evdev.py +++ b/src/fenrir-package/inputDriver/evdev.py @@ -15,7 +15,7 @@ class driver(): self.ledDevices = {} def initialize(self, environment): - self.getInputDevices() + self.getInputDevices(environment) def shutdown(self, environment): pass def getInput(self, environment): @@ -24,14 +24,23 @@ class driver(): if r != []: for fd in r: event = self.iDevices[fd].read_one() - return event + environment['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) + return environment['runtime']['inputDriver'].mapEvent(environment, event) return None - def writeUInput(self, uDevice, event,environment): + def writeEventBuffer(self, environment): + for iDevice, uDevice, event in environment['input']['eventBuffer']: + self.writeUInput(environment, uDevice, event) + self.clearEventBuffer(environment) + + def clearEventBuffer(self, environment): + del environment['input']['eventBuffer'][:] + + def writeUInput(self, environment, uDevice, event): uDevice.write_event(event) uDevice.syn() - def getInputDevices(self): + def getInputDevices(self, environment): # 3 pos absolute # 2 pos relative # 17 LEDs @@ -84,7 +93,7 @@ class driver(): return 2 in dev.leds() return False - def grabDevices(self): + def grabDevices(self, environment): for fd in self.iDevices: dev = self.iDevices[fd] cap = dev.capabilities() @@ -100,7 +109,7 @@ class driver(): ) dev.grab() - def releaseDevices(self): + def releaseDevices(self, environment): for fd in self.iDevices: try: self.iDevices[fd].ungrab()