From d3bec267afc1923f6c8ddb8a0b07711121f260b2 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 23 May 2018 01:12:31 +0200 Subject: [PATCH] fix pty --- src/fenrirscreenreader/core/inputManager.py | 42 ++++++++++--------- src/fenrirscreenreader/core/screenManager.py | 20 +++++++-- .../core/settingsManager.py | 20 ++++----- .../inputDriver/evdevDriver.py | 2 +- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index f10b86ce..0a4c0f83 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 + self.executeDeviceGrab = False def setShortcutType(self, shortcutType = 'KEY'): if shortcutType in ['KEY', 'BYTE']: self.shortcutType = shortcutType @@ -24,6 +24,8 @@ class inputManager(): self.env = environment self.env['runtime']['settingsManager'].loadDriver(\ self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver') + self.updateInputDevices() + # init LEDs with current state self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState() self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] @@ -39,27 +41,25 @@ 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'): + def setExecuteDeviceGrab(self, newExecuteDeviceGrab = True): + self.executeDeviceGrab = newExecuteDeviceGrab + def handleDeviceGrab(self): + if not self.executeDeviceGrab: 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 + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): + return + if not self.noKeyPressed(): + return + if self.env['runtime']['screenManager'].getCurrScreenIgnored(): + self.ungrabAllDevices() + self.env['runtime']['outputManager'].interruptOutput() + else: + self.grabAllDevices() + self.executeDeviceGrab = False def handleInputEvent(self, eventData): - self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT inputMan:' + str(eventData),debug.debugLevel.INFO) if not eventData: return + self.handleDeviceGrab() self.env['input']['prevInput'] = self.env['input']['currInput'].copy() if eventData['EventState'] == 0: if eventData['EventName'] in self.env['input']['currInput']: @@ -97,6 +97,8 @@ class inputManager(): if self.noKeyPressed(): self.env['input']['prevInput'] = [] self.setLedState = True + else: + self.handleDeviceGrab() def handleLedStates(self, mEvent): if not self.setLedState: @@ -144,7 +146,9 @@ class inputManager(): self.env['runtime']['inputDriver'].updateInputDevices(newDevice) except: pass - self.handleDeviceGrab(True) + self.setExecuteDeviceGrab() + if newDevice: + self.handleDeviceGrab() def removeAllDevices(self): try: self.env['runtime']['inputDriver'].removeAllDevices() diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 68d4ca18..5be25c98 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -18,7 +18,10 @@ class screenManager(): self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver') self.getCurrScreen() self.getCurrScreen() - self.getSessionInformation() + self.getSessionInformation() + self.updateScreenIgnored() + self.updateScreenIgnored() + def getCurrScreen(self): try: self.env['runtime']['screenDriver'].getCurrScreen() @@ -32,18 +35,27 @@ class screenManager(): def shutdown(self): self.env['runtime']['settingsManager'].shutdownDriver('screenDriver') + def isCurrScreenIgnoredChanged(self): + return self.getCurrScreenIgnored() != self.getPrevScreenIgnored() def hanldeScreenChange(self, eventData): self.getCurrScreen() - self.getSessionInformation() + self.updateScreenIgnored() + if self.isCurrScreenIgnoredChanged(): + self.env['runtime']['inputManager'].setExecuteDeviceGrab() + self.env['runtime']['inputManager'].handleDeviceGrab() + self.getSessionInformation() + if self.isScreenChange(): self.changeBrailleScreen() if not self.isSuspendingScreen(self.env['screen']['newTTY']): self.update(eventData, 'onScreenChange') - self.env['screen']['lastScreenUpdate'] = time.time() - + self.env['screen']['lastScreenUpdate'] = time.time() + def handleScreenUpdate(self, eventData): self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] self.updateScreenIgnored() + if self.isCurrScreenIgnoredChanged(): + self.env['runtime']['inputManager'].setExecuteDeviceGrab() self.env['runtime']['inputManager'].handleDeviceGrab() if not self.getCurrScreenIgnored(): self.update(eventData, 'onScreenUpdate') diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 27eff00e..2bf89e80 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -275,18 +275,24 @@ class settingsManager(): environment['runtime']['processManager'] = processManager.processManager() environment['runtime']['processManager'].initialize(environment) + + environment['runtime']['outputManager'] = outputManager.outputManager() + environment['runtime']['outputManager'].initialize(environment) + + environment['runtime']['byteManager'] = byteManager.byteManager() + environment['runtime']['byteManager'].initialize(environment) environment['runtime']['inputManager'] = inputManager.inputManager() environment['runtime']['inputManager'].initialize(environment) + environment['runtime']['screenManager'] = screenManager.screenManager() + environment['runtime']['screenManager'].initialize(environment) + environment['runtime']['commandManager'] = commandManager.commandManager() environment['runtime']['commandManager'].initialize(environment) environment['runtime']['helpManager'] = helpManager.helpManager() environment['runtime']['helpManager'].initialize(environment) - - environment['runtime']['byteManager'] = byteManager.byteManager() - environment['runtime']['byteManager'].initialize(environment) if environment['runtime']['inputManager'].getShortcutType() == 'KEY': if not os.path.exists(self.getSetting('keyboard','keyboardLayout')): @@ -308,10 +314,7 @@ class settingsManager(): environment['runtime']['byteManager'].loadByteShortcuts(self.getSetting('keyboard','keyboardLayout')) else: environment['runtime']['byteManager'].loadByteShortcuts(self.getSetting('keyboard','keyboardLayout')) - - - environment['runtime']['outputManager'] = outputManager.outputManager() - environment['runtime']['outputManager'].initialize(environment) + environment['runtime']['cursorManager'] = cursorManager.cursorManager() environment['runtime']['cursorManager'].initialize(environment) environment['runtime']['applicationManager'] = applicationManager.applicationManager() @@ -320,9 +323,6 @@ class settingsManager(): environment['runtime']['headLineManager'].initialize(environment) environment['runtime']['tableManager'] = tableManager.tableManager() environment['runtime']['tableManager'].initialize(environment) - if environment['runtime']['screenManager'] == None: - environment['runtime']['screenManager'] = screenManager.screenManager() - environment['runtime']['screenManager'].initialize(environment) environment['runtime']['debug'].writeDebugOut('\/-------environment-------\/',debug.debugLevel.INFO, onAnyLevel=True) environment['runtime']['debug'].writeDebugOut(str(environment), debug.debugLevel.INFO, onAnyLevel=True) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index c7295d62..00e11805 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -53,7 +53,7 @@ class driver(inputDriver): global _evdevAvailableError self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR) return - self.updateInputDevices() + if _udevAvailable: self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev) #else: