diff --git a/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py b/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py index 8e925bfe..f09b3d35 100755 --- a/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py +++ b/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py @@ -16,6 +16,6 @@ class command(): def getDescription(self): return 'No description found' def run(self): - pass + self.env['runtime']['inputManager'].updateInputDevices() def setCallback(self, callback): pass diff --git a/src/fenrirscreenreader/core/fenrirManager.py b/src/fenrirscreenreader/core/fenrirManager.py index 399f4d56..9f2a885a 100644 --- a/src/fenrirscreenreader/core/fenrirManager.py +++ b/src/fenrirscreenreader/core/fenrirManager.py @@ -166,7 +166,6 @@ class fenrirManager(): #print('handleScreenUpdate:',time.time() - startTime) def handlePlugInputDevice(self, event): - self.environment['runtime']['inputManager'].updateInputDevices() self.environment['runtime']['commandManager'].executeDefaultTrigger('onPlugInputDevice', force=True) def handleHeartBeat(self, event): diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index 579c4db4..18aebe52 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -14,7 +14,7 @@ class inputManager(): def __init__(self): self.setLedState = True self.shortcutType = 'KEY' - + self.toggleDeviceGrab = False def setShortcutType(self, shortcutType = 'KEY'): if shortcutType in ['KEY', 'BYTE']: self.shortcutType = shortcutType @@ -39,6 +39,23 @@ class inputManager(): self.env['runtime']['settingsManager'].shutdownDriver('inputDriver') def getInputEvent(self): return self.env['runtime']['inputDriver'].getInputEvent() + def handleDeviceGrab(self, useCurrentScreen = False): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): + return + if useCurrentScreen: + self.toggleDeviceGrab = True + else: + if self.env['runtime']['screenManager'].getCurrScreenIgnored() != self.env['runtime']['screenManager'].getPrevScreenIgnored(): + self.toggleDeviceGrab = True + + if self.toggleDeviceGrab: + if self.noKeyPressed(): + if self.env['runtime']['screenManager'].getCurrScreenIgnored(): + self.ungrabAllDevices() + self.env['runtime']['outputManager'].interruptOutput() + else: + self.grabAllDevices() + self.toggleDeviceGrab = False def handleInputEvent(self, eventData): self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT inputMan:' + str(eventData),debug.debugLevel.INFO) if not eventData: @@ -118,14 +135,14 @@ class inputManager(): try: self.env['runtime']['inputDriver'].ungrabAllDevices() except Exception as e: - pass + pass def updateInputDevices(self): try: self.env['runtime']['inputDriver'].updateInputDevices() except: pass - + self.handleDeviceGrab(True) def removeAllDevices(self): try: self.env['runtime']['inputDriver'].removeAllDevices() diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 3b337d6a..a496f94c 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -12,7 +12,6 @@ class screenManager(): def __init__(self): self.currScreenIgnored = False self.prevScreenIgnored = False - self.toggleDeviceGrab = False def initialize(self, environment): self.env = environment self.env['runtime']['settingsManager'].loadDriver(\ @@ -40,25 +39,12 @@ class screenManager(): self.changeBrailleScreen() if not self.isSuspendingScreen(self.env['screen']['newTTY']): self.update(eventData, 'onScreenChange') - self.env['screen']['lastScreenUpdate'] = time.time() - def handleDeviceGrab(self): - if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): - return - if self.getCurrScreenIgnored() != self.getPrevScreenIgnored(): - self.toggleDeviceGrab = True - if self.toggleDeviceGrab: - if self.env['runtime']['inputManager'].noKeyPressed(): - if self.getCurrScreenIgnored(): - self.env['runtime']['inputManager'].ungrabAllDevices() - self.env['runtime']['outputManager'].interruptOutput() - else: - self.env['runtime']['inputManager'].grabAllDevices() - self.toggleDeviceGrab = False + self.env['screen']['lastScreenUpdate'] = time.time() def handleScreenUpdate(self, eventData): self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] self.updateScreenIgnored() - self.handleDeviceGrab() + self.env['runtime']['inputManager'].handleDeviceGrab() if not self.getCurrScreenIgnored(): self.update(eventData, 'onScreenUpdate') #if trigger == 'onUpdate' or self.isScreenChange() \ diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index c4e8b454..e432b686 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -200,7 +200,6 @@ class driver(inputDriver): self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO) self.iDeviceNo = len(evdev.list_devices()) self.updateMPiDevicesFD() - def updateMPiDevicesFD(self): try: for fd in self.iDevices: @@ -297,6 +296,8 @@ class driver(inputDriver): return try: self.iDevices[fd].grab() + self.gDevices[fd] = True + except IOError: self.gDevices[fd] = True except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR) @@ -305,7 +306,7 @@ class driver(inputDriver): return try: self.gDevices[fd] = False - self.iDevices[fd].ungrab() + self.iDevices[fd].ungrab() except: pass def removeDevice(self,fd):