From e58d13dced20af3139562bccbe0e8f89906a3765 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 11 May 2018 23:21:45 +0200 Subject: [PATCH 01/21] update ToDo --- TODO v2.0 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TODO v2.0 b/TODO v2.0 index 35d3c736..1fa49d45 100644 --- a/TODO v2.0 +++ b/TODO v2.0 @@ -129,9 +129,9 @@ Cleanups: [X] first item [X] last item General: -- [X] make it runable using pypy3 - -- [X] read ignorescreens from an file to be able to halt fenrir from outside + [X] make it runable using pypy3 + [X] interrupt speech while entering an ignored screen + [X] read ignorescreens from an file to be able to halt fenrir from outside - commands [X] place last spoken to clipboard (Easy for contribution) - Improvend Headline Seperator and Multible Char Support @@ -139,6 +139,8 @@ General: - autospeak indentation changes (useful for python programming) Braille Support: Driver: +[X] evdev InputDriver + [X] grab/ ungrab devices on ignored screens [X] PTY Input driver [X] new event for byte shortcuts (escape sequences) [X] create driver From e812d4e2ae3b2ac276a8660da903f0497ea53f87 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 11 May 2018 23:30:08 +0200 Subject: [PATCH 02/21] catch some driver calls --- src/fenrirscreenreader/core/inputManager.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index 9977c8a7..579c4db4 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -109,10 +109,16 @@ class inputManager(): def grabAllDevices(self): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): - self.env['runtime']['inputDriver'].grabAllDevices() + try: + self.env['runtime']['inputDriver'].grabAllDevices() + except Exception as e: + pass def ungrabAllDevices(self): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): - self.env['runtime']['inputDriver'].ungrabAllDevices() + try: + self.env['runtime']['inputDriver'].ungrabAllDevices() + except Exception as e: + pass def updateInputDevices(self): try: @@ -155,7 +161,10 @@ class inputManager(): return eventName def clearEventBuffer(self): - self.env['runtime']['inputDriver'].clearEventBuffer() + try: + self.env['runtime']['inputDriver'].clearEventBuffer() + except Exception as e: + pass def setLastDeepestInput(self, currentDeepestInput): self.lastDeepestInput = currentDeepestInput def clearLastDeepInput(self): From 426fecf60faf76de680a59e39572d1c9eeaf5f3f Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 11 May 2018 23:34:13 +0200 Subject: [PATCH 03/21] catch some driver calls --- src/fenrirscreenreader/core/screenManager.py | 18 ++++++++++-------- src/fenrirscreenreader/core/settingsManager.py | 5 ++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 426e086c..9b6fd7fa 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -158,13 +158,16 @@ class screenManager(): return '' if attributeFormatString == '': return '' - attributeFormatString = attributeFormatString.replace('fenrirBGColor', self.env['runtime']['screenDriver'].getFenrirBGColor(attribute)) - attributeFormatString = attributeFormatString.replace('fenrirFGColor', self.env['runtime']['screenDriver'].getFenrirFGColor(attribute)) - attributeFormatString = attributeFormatString.replace('fenrirUnderline', self.env['runtime']['screenDriver'].getFenrirUnderline(attribute)) - attributeFormatString = attributeFormatString.replace('fenrirBold', self.env['runtime']['screenDriver'].getFenrirBold(attribute)) - attributeFormatString = attributeFormatString.replace('fenrirBlink', self.env['runtime']['screenDriver'].getFenrirBlink(attribute)) - attributeFormatString = attributeFormatString.replace('fenrirFontSize', self.env['runtime']['screenDriver'].getFenrirFontSize(attribute)) - attributeFormatString = attributeFormatString.replace('fenrirFont', self.env['runtime']['screenDriver'].getFenrirFont(attribute)) + try: + attributeFormatString = attributeFormatString.replace('fenrirBGColor', self.env['runtime']['screenDriver'].getFenrirBGColor(attribute)) + attributeFormatString = attributeFormatString.replace('fenrirFGColor', self.env['runtime']['screenDriver'].getFenrirFGColor(attribute)) + attributeFormatString = attributeFormatString.replace('fenrirUnderline', self.env['runtime']['screenDriver'].getFenrirUnderline(attribute)) + attributeFormatString = attributeFormatString.replace('fenrirBold', self.env['runtime']['screenDriver'].getFenrirBold(attribute)) + attributeFormatString = attributeFormatString.replace('fenrirBlink', self.env['runtime']['screenDriver'].getFenrirBlink(attribute)) + attributeFormatString = attributeFormatString.replace('fenrirFontSize', self.env['runtime']['screenDriver'].getFenrirFontSize(attribute)) + attributeFormatString = attributeFormatString.replace('fenrirFont', self.env['runtime']['screenDriver'].getFenrirFont(attribute)) + except Exception as e: + pass return attributeFormatString def isSuspendingScreen(self, screen = None): if screen == None: @@ -212,7 +215,6 @@ class screenManager(): try: self.env['runtime']['screenDriver'].injectTextToScreen(text, screen) except Exception as e: - print(e) self.env['runtime']['debug'].writeDebugOut('screenManager:injectTextToScreen ' + str(e),debug.debugLevel.ERROR) def changeBrailleScreen(self): diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index abc2f4ef..444e1947 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -153,7 +153,10 @@ class settingsManager(): def shutdownDriver(self, driverType): if self.env['runtime'][driverType] == None: return - self.env['runtime'][driverType].shutdown() + try: + self.env['runtime'][driverType].shutdown() + except Exception as e: + pass del self.env['runtime'][driverType] def setFenrirKeys(self, keys): From 7b1fbafbbd0dd4daf3951264a9a335e6cbd4ef84 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 11 May 2018 23:43:04 +0200 Subject: [PATCH 04/21] add capabilitys to listDev --- play zone/listDevices.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/play zone/listDevices.py b/play zone/listDevices.py index 9af5a7e7..1ddd629b 100755 --- a/play zone/listDevices.py +++ b/play zone/listDevices.py @@ -17,5 +17,7 @@ for fd in iDevices: print('No. of keys: ' + str(len(cap[evdev.events.EV_KEY]))) print('has Key 116: ' + str(116 in cap[evdev.events.EV_KEY])) print('Is Mouse: ' + str(((evdev.events.EV_REL in cap) or (evdev.events.EV_ABS in cap)))) + print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') + print(dev.capabilities(verbose=True)) print('----------------------') From 66b0b96426c370297d2dbbafae3ec337954deb95 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 12 May 2018 00:23:45 +0200 Subject: [PATCH 05/21] set application name to fenrir --- src/fenrirscreenreader/core/fenrirManager.py | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/fenrirManager.py b/src/fenrirscreenreader/core/fenrirManager.py index 5254bf9e..9f2a885a 100644 --- a/src/fenrirscreenreader/core/fenrirManager.py +++ b/src/fenrirscreenreader/core/fenrirManager.py @@ -4,7 +4,7 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import signal, time, argparse +import signal, time, argparse, sys from fenrirscreenreader.core import i18n from fenrirscreenreader.core import settingsManager @@ -32,6 +32,7 @@ class fenrirManager(): self.command = '' self.controlMode = True self.switchCtrlModeOnce = 0 + self.setProcessName() def handleArgs(self): args = None parser = argparse.ArgumentParser(description="Fenrir Help") @@ -212,7 +213,32 @@ class fenrirManager(): if self.environment['runtime']['inputManager'].noKeyPressed(): self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) self.command = '' + def setProcessName(self, name = 'fenrir'): + """Attempts to set the process name to 'fenrir'.""" + #sys.argv[0] = name + + # Disabling the import error of setproctitle. + # pylint: disable-msg=F0401 + try: + from setproctitle import setproctitle + except ImportError: + pass + else: + setproctitle(name) + return True + + try: + from ctypes import cdll, byref, create_string_buffer + libc = cdll.LoadLibrary('libc.so.6') + stringBuffer = create_string_buffer(len(name) + 1) + stringBuffer.value = bytes(name, 'UTF-8') + libc.prctl(15, byref(stringBuffer), 0, 0, 0) + return True + except: + pass + + return False def shutdownRequest(self): try: self.environment['runtime']['eventManager'].stopMainEventLoop() From ccc34ef7788c2639d001e627482e3c9a6642c1a6 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 21:22:32 +0200 Subject: [PATCH 06/21] catch more driver calls --- src/fenrirscreenreader/core/screenManager.py | 18 ++++++++++++++++++ .../inputDriver/evdevDriver.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 9b6fd7fa..29f2ed28 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -160,11 +160,29 @@ class screenManager(): return '' try: attributeFormatString = attributeFormatString.replace('fenrirBGColor', self.env['runtime']['screenDriver'].getFenrirBGColor(attribute)) + except Exception as e: + pass + try: attributeFormatString = attributeFormatString.replace('fenrirFGColor', self.env['runtime']['screenDriver'].getFenrirFGColor(attribute)) + except Exception as e: + pass + try: attributeFormatString = attributeFormatString.replace('fenrirUnderline', self.env['runtime']['screenDriver'].getFenrirUnderline(attribute)) + except Exception as e: + pass + try: attributeFormatString = attributeFormatString.replace('fenrirBold', self.env['runtime']['screenDriver'].getFenrirBold(attribute)) + except Exception as e: + pass + try: attributeFormatString = attributeFormatString.replace('fenrirBlink', self.env['runtime']['screenDriver'].getFenrirBlink(attribute)) + except Exception as e: + pass + try: attributeFormatString = attributeFormatString.replace('fenrirFontSize', self.env['runtime']['screenDriver'].getFenrirFontSize(attribute)) + except Exception as e: + pass + try: attributeFormatString = attributeFormatString.replace('fenrirFont', self.env['runtime']['screenDriver'].getFenrirFont(attribute)) except Exception as e: pass diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index ff317cd7..cd2191e0 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -68,7 +68,7 @@ class driver(inputDriver): devices = monitor.poll(2) if devices: while monitor.poll(0.2): - time.sleep(0.2) + time.sleep(0.1) eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None}) return time.time() def plugInputDeviceWatchdogTimer(self, active): From d0bdaea86ecbec081b30ad7a4347c366f09b291f Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 21:27:29 +0200 Subject: [PATCH 07/21] more strict keyboard filter --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index cd2191e0..5beecba8 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -134,7 +134,6 @@ class driver(inputDriver): return uDevice.write_event(event) uDevice.syn() - time.sleep(0.00001) def updateInputDevices(self, force = False, init = False): if init: @@ -173,8 +172,8 @@ class driver(inputDriver): if 116 in cap[eventType.EV_KEY] and len(cap[eventType.EV_KEY]) < 10: self.env['runtime']['debug'].writeDebugOut('Device Skipped (has 116):' + currDevice.name,debug.debugLevel.INFO) continue - if len(cap[eventType.EV_KEY]) < 30: - self.env['runtime']['debug'].writeDebugOut('Device Skipped (< 30 keys):' + currDevice.name,debug.debugLevel.INFO) + if len(cap[eventType.EV_KEY]) < 60: + self.env['runtime']['debug'].writeDebugOut('Device Skipped (< 60 keys):' + currDevice.name,debug.debugLevel.INFO) continue if mode == 'ALL': self.iDevices[currDevice.fd] = currDevice From c5e50b086bc4580684c04f54838b3b8b77d3797d Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 21:46:51 +0200 Subject: [PATCH 08/21] disable device hotplug --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 5beecba8..544be9f6 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -54,10 +54,10 @@ class driver(inputDriver): self.env['runtime']['debug'].writeDebugOut('InputDriver: ' + _evdevAvailableError,debug.debugLevel.ERROR) return self.updateInputDevices() - if _udevAvailable: - self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev) - else: - self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer) + #if _udevAvailable: + # self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev) + #else: + # self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer) self.env['runtime']['processManager'].addCustomEventThread(self.inputWatchdog) def plugInputDeviceWatchdogUdev(self,active , eventQueue): context = pyudev.Context() @@ -67,8 +67,8 @@ class driver(inputDriver): while active.value: devices = monitor.poll(2) if devices: - while monitor.poll(0.2): - time.sleep(0.1) + while monitor.poll(0.1): + pass eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None}) return time.time() def plugInputDeviceWatchdogTimer(self, active): From 0d74ae0d962c400d9b3dd4746178b13a4b0d9b48 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 23:12:41 +0200 Subject: [PATCH 09/21] fix uinput handling, speedup device grabbing --- .../inputDriver/evdevDriver.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 544be9f6..0481d9f2 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -119,8 +119,9 @@ class driver(inputDriver): return for iDevice, uDevice, event in self.env['input']['eventBuffer']: try: - if self.gDevices[iDevice.fd]: - self.writeUInput(uDevice, event) + if uDevice: + if self.gDevices[iDevice.fd]: + self.writeUInput(uDevice, event) except Exception as e: pass @@ -177,18 +178,18 @@ class driver(inputDriver): continue if mode == 'ALL': self.iDevices[currDevice.fd] = currDevice - self.grabDevice(currDevice.fd) + self.addDevice(currDevice.fd) self.env['runtime']['debug'].writeDebugOut('Device added (ALL):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO) elif mode == 'NOMICE': if not ((eventType.EV_REL in cap) or (eventType.EV_ABS in cap)): self.iDevices[currDevice.fd] = currDevice - self.grabDevice(currDevice.fd) + self.addDevice(currDevice.fd) self.env['runtime']['debug'].writeDebugOut('Device added (NOMICE):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO) else: self.env['runtime']['debug'].writeDebugOut('Device Skipped (NOMICE):' + currDevice.name,debug.debugLevel.INFO) elif currDevice.name.upper() in mode.split(','): self.iDevices[currDevice.fd] = currDevice - self.grabDevice(currDevice.fd) + self.addDevice(currDevice.fd) self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO) except Exception as e: self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO) @@ -250,7 +251,7 @@ class driver(inputDriver): return for fd in self.iDevices: self.ungrabDevices(fd) - def grabDevice(self, fd): + def addDevice(self, fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): self.uDevices[fd] = None return @@ -269,6 +270,10 @@ class driver(inputDriver): except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR) return + self.grabDevice(fd) + def grabDevice(self, fd): + if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): + return try: self.iDevices[fd].grab() self.gDevices[fd] = True From 26fcd92f81eb70899a889ca81ef29c74e54127a3 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 23:16:22 +0200 Subject: [PATCH 10/21] fix function name --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 0481d9f2..6e4b8ea9 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -250,7 +250,7 @@ class driver(inputDriver): if not self._initialized: return for fd in self.iDevices: - self.ungrabDevices(fd) + self.ungrabDevice(fd) def addDevice(self, fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): self.uDevices[fd] = None @@ -279,7 +279,7 @@ class driver(inputDriver): self.gDevices[fd] = True except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR) - def ungrabDevices(self,fd): + def ungrabDevice(self,fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): return try: @@ -290,7 +290,7 @@ class driver(inputDriver): def removeDevice(self,fd): self.clearEventBuffer() try: - self.ungrabDevices(fd) + self.ungrabDevice(fd) except: pass try: From abc449bec25da23c5af4bd9c8d81fb1305a897b2 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 23:40:05 +0200 Subject: [PATCH 11/21] grab/ungrab on noKeyPressed() --- src/fenrirscreenreader/core/screenManager.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 29f2ed28..b58e0b98 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -12,6 +12,7 @@ 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,15 +41,22 @@ class screenManager(): if not self.isSuspendingScreen(self.env['screen']['newTTY']): self.update(eventData, 'onScreenChange') self.env['screen']['lastScreenUpdate'] = time.time() + def handleDeviceGrab(self): + 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 = True + def handleScreenUpdate(self, eventData): self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] self.updateScreenIgnored() - if self.getCurrScreenIgnored() != self.getPrevScreenIgnored(): - if self.getCurrScreenIgnored(): - self.env['runtime']['inputManager'].ungrabAllDevices() - self.env['runtime']['outputManager'].interruptOutput() - else: - self.env['runtime']['inputManager'].grabAllDevices() + self.handleDeviceGrab() if not self.getCurrScreenIgnored(): self.update(eventData, 'onScreenUpdate') #if trigger == 'onUpdate' or self.isScreenChange() \ From ae612ce9f2415f4df9de82e65a79c59f6b620130 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 23:42:04 +0200 Subject: [PATCH 12/21] grab/ungrab on noKeyPressed() --- src/fenrirscreenreader/core/screenManager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index b58e0b98..e24a5978 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -47,11 +47,13 @@ class screenManager(): if self.toggleDeviceGrab: if self.env['runtime']['inputManager'].noKeyPressed(): if self.getCurrScreenIgnored(): + print('ungrab') self.env['runtime']['inputManager'].ungrabAllDevices() self.env['runtime']['outputManager'].interruptOutput() else: self.env['runtime']['inputManager'].grabAllDevices() - self.toggleDeviceGrab = True + print('grab') + self.toggleDeviceGrab = False def handleScreenUpdate(self, eventData): self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] From 30372f0440f1e666f98cb748772b63b434b37e83 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 13 May 2018 23:43:35 +0200 Subject: [PATCH 13/21] grab/ungrab on noKeyPressed() --- src/fenrirscreenreader/core/screenManager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index e24a5978..77721549 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -42,6 +42,8 @@ class screenManager(): 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: From 521f551b842af9deb1aadcdb632c69911de23400 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 14 May 2018 14:13:29 +0200 Subject: [PATCH 14/21] Update evdevDriver.py --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 6e4b8ea9..0c6cf903 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -251,11 +251,18 @@ class driver(inputDriver): return for fd in self.iDevices: self.ungrabDevice(fd) - def addDevice(self, fd): + def createUInputDev(self, fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): self.uDevices[fd] = None return - try: + try: + test = self.uDevices[fd] + return + except KeyError: + pass + if not self.uDevices[fd]: + return + try: self.uDevices[fd] = UInput.from_device(self.iDevices[fd]) except Exception as e: try: @@ -269,7 +276,9 @@ class driver(inputDriver): ) except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR) - return + return + def addDevice(self, fd): + self.createUInputDev(fd) self.grabDevice(fd) def grabDevice(self, fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): From 662cfd2e2d99f3d447c722f5a945d9d5724d997c Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 14 May 2018 14:26:57 +0200 Subject: [PATCH 15/21] Update evdevDriver.py --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 0c6cf903..e0336d35 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -260,7 +260,7 @@ class driver(inputDriver): return except KeyError: pass - if not self.uDevices[fd]: + if self.uDevices[fd] != None: return try: self.uDevices[fd] = UInput.from_device(self.iDevices[fd]) From 4cde0159f908d2f15cdfa4da5068e20f5cf513a3 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 14 May 2018 14:32:07 +0200 Subject: [PATCH 16/21] Update evdevDriver.py --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index e0336d35..bfe221bb 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -67,7 +67,7 @@ class driver(inputDriver): while active.value: devices = monitor.poll(2) if devices: - while monitor.poll(0.1): + while monitor.poll(1): pass eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None}) return time.time() From 0f83708ea05c76b600ccb027fbb05694e0a4cb06 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 14 May 2018 14:57:38 +0200 Subject: [PATCH 17/21] Update inputDriver.py --- src/fenrirscreenreader/core/inputDriver.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/core/inputDriver.py b/src/fenrirscreenreader/core/inputDriver.py index ab91483e..8dac83bb 100644 --- a/src/fenrirscreenreader/core/inputDriver.py +++ b/src/fenrirscreenreader/core/inputDriver.py @@ -41,13 +41,16 @@ class inputDriver(): def toggleLedState(self, led = 0): if not self._initialized: return None - def grabDevices(self): + def grabAllDevices(self): if not self._initialized: return None - def releaseDevices(self): + def ungrabAllDevices(self): if not self._initialized: return None + def removeAllDevices(self): + if not self._initialized: + return None def __del__(self): if not self._initialized: return None - self.releaseDevices() + self.removeAllDevices() From 670afb5c5870687f3c761eb6f781d18c28356d3e Mon Sep 17 00:00:00 2001 From: chrys87 Date: Mon, 14 May 2018 14:58:17 +0200 Subject: [PATCH 18/21] Update inputDriver.py --- src/fenrirscreenreader/core/inputDriver.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fenrirscreenreader/core/inputDriver.py b/src/fenrirscreenreader/core/inputDriver.py index 8dac83bb..bc4bff62 100644 --- a/src/fenrirscreenreader/core/inputDriver.py +++ b/src/fenrirscreenreader/core/inputDriver.py @@ -40,17 +40,17 @@ class inputDriver(): return False def toggleLedState(self, led = 0): if not self._initialized: - return None + return def grabAllDevices(self): if not self._initialized: - return None + return def ungrabAllDevices(self): if not self._initialized: - return None + return def removeAllDevices(self): if not self._initialized: - return None + return def __del__(self): if not self._initialized: - return None + return self.removeAllDevices() From 79cc8ef13d6610ed9f9ac7006598adcee8041973 Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 14 May 2018 20:03:39 +0200 Subject: [PATCH 19/21] fix instance issue --- src/fenrirscreenreader/core/screenManager.py | 2 -- .../inputDriver/evdevDriver.py | 18 ++++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 77721549..449ecade 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -49,12 +49,10 @@ class screenManager(): if self.toggleDeviceGrab: if self.env['runtime']['inputManager'].noKeyPressed(): if self.getCurrScreenIgnored(): - print('ungrab') self.env['runtime']['inputManager'].ungrabAllDevices() self.env['runtime']['outputManager'].interruptOutput() else: self.env['runtime']['inputManager'].grabAllDevices() - print('grab') self.toggleDeviceGrab = False def handleScreenUpdate(self, eventData): diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index bfe221bb..12df5457 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -177,19 +177,16 @@ class driver(inputDriver): self.env['runtime']['debug'].writeDebugOut('Device Skipped (< 60 keys):' + currDevice.name,debug.debugLevel.INFO) continue if mode == 'ALL': - self.iDevices[currDevice.fd] = currDevice - self.addDevice(currDevice.fd) + self.addDevice(currDevice) self.env['runtime']['debug'].writeDebugOut('Device added (ALL):' + self.iDevices[currDevice.fd].name, debug.debugLevel.INFO) elif mode == 'NOMICE': if not ((eventType.EV_REL in cap) or (eventType.EV_ABS in cap)): - self.iDevices[currDevice.fd] = currDevice - self.addDevice(currDevice.fd) + self.addDevice(currDevice) self.env['runtime']['debug'].writeDebugOut('Device added (NOMICE):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO) else: self.env['runtime']['debug'].writeDebugOut('Device Skipped (NOMICE):' + currDevice.name,debug.debugLevel.INFO) elif currDevice.name.upper() in mode.split(','): - self.iDevices[currDevice.fd] = currDevice - self.addDevice(currDevice.fd) + self.addDevice(currDevice) self.env['runtime']['debug'].writeDebugOut('Device added (Name):' + self.iDevices[currDevice.fd].name,debug.debugLevel.INFO) except Exception as e: self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO) @@ -259,7 +256,7 @@ class driver(inputDriver): test = self.uDevices[fd] return except KeyError: - pass + self.uDevices[fd] = None if self.uDevices[fd] != None: return try: @@ -277,7 +274,8 @@ class driver(inputDriver): except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR) return - def addDevice(self, fd): + def addDevice(self, newDevice, fd): + self.iDevices[newDevice.fd] = newDevice self.createUInputDev(fd) self.grabDevice(fd) def grabDevice(self, fd): @@ -292,8 +290,8 @@ class driver(inputDriver): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): return try: + self.gDevices[fd] = False self.iDevices[fd].ungrab() - self.gDevices[fd] = False except: pass def removeDevice(self,fd): @@ -322,7 +320,7 @@ class driver(inputDriver): del(self.gDevices[fd]) except: pass - self.MPiDevicesFD() + self.updateMPiDevicesFD() def hasIDevices(self): if not self._initialized: From 861b0413db9f9823f71bb9293704fd68ef1b41dc Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 14 May 2018 20:09:08 +0200 Subject: [PATCH 20/21] fix debugDriver --- .../inputDriver/debugDriver.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/debugDriver.py b/src/fenrirscreenreader/inputDriver/debugDriver.py index d825cb8b..582813fd 100644 --- a/src/fenrirscreenreader/inputDriver/debugDriver.py +++ b/src/fenrirscreenreader/inputDriver/debugDriver.py @@ -20,7 +20,7 @@ class driver(inputDriver): def shutdown(self): if self._initialized: - self.releaseDevices() + self.removeAllDevices() self._initialized = False print('Input Debug Driver: Shutdown') @@ -51,17 +51,22 @@ class driver(inputDriver): if not self._initialized: return print('Input Debug Driver: toggleLedState') - def grabDevices(self): + def grabAllDevices(self): if not self._initialized: return - print('Input Debug Driver: grabDevices') - def releaseDevices(self): + print('Input Debug Driver: grabAllDevices') + def ungrabAllDevices(self): if not self._initialized: return - print('Input Debug Driver: releaseDevices') + print('Input Debug Driver: ungrabAllDevices') + + def removeAllDevices(self): + if not self._initialized: + return + print('Input Debug Driver: removeAllDevices') def __del__(self): if self._initialized: - self.releaseDevices() + self.removeAllDevices() print('Input Debug Driver: __del__') From e833640bb9cb642e9dbe69933e4674167ef1e411 Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 14 May 2018 20:20:28 +0200 Subject: [PATCH 21/21] fix api --- src/fenrirscreenreader/inputDriver/evdevDriver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 12df5457..85e12c9a 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -274,10 +274,10 @@ class driver(inputDriver): except Exception as e: self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: init Uinput not possible: ' + str(e),debug.debugLevel.ERROR) return - def addDevice(self, newDevice, fd): + def addDevice(self, newDevice): self.iDevices[newDevice.fd] = newDevice - self.createUInputDev(fd) - self.grabDevice(fd) + self.createUInputDev(newDevice.fd) + self.grabDevice(newDevice.fd) def grabDevice(self, fd): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): return