initial keyboard grab
This commit is contained in:
		| @@ -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): | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
| @@ -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 ''            | ||||
|      | ||||
| @@ -22,7 +22,6 @@ class command(): | ||||
|         else: | ||||
|             environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']], True) | ||||
|   | ||||
|         return environment     | ||||
|     def setCallback(self, callback): | ||||
|         pass | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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 passInput(self, environment): | ||||
|     def clearEventBuffer(self, environment): | ||||
|         environment['runtime']['inputDriver'].clearEventBuffer(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']) | ||||
|   | ||||
| @@ -41,16 +41,23 @@ class fenrir(): | ||||
|             self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR)                 | ||||
|         if not timeout:   | ||||
|             self.prepareCommand() | ||||
|             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): | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user