From eacb26f340277786cab88fe3ffae4fad58183274 Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 11 May 2018 23:16:18 +0200 Subject: [PATCH] grab/ungrab on ignorescreen, stop speech --- src/fenrirscreenreader/core/inputManager.py | 5 +++- src/fenrirscreenreader/core/outputManager.py | 7 ++++-- src/fenrirscreenreader/core/screenManager.py | 25 +++++++++++++++---- .../inputDriver/evdevDriver.py | 19 +++++++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index b74f4ef9..9977c8a7 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -110,7 +110,10 @@ class inputManager(): def grabAllDevices(self): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): self.env['runtime']['inputDriver'].grabAllDevices() - + def ungrabAllDevices(self): + if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): + self.env['runtime']['inputDriver'].ungrabAllDevices() + def updateInputDevices(self): try: self.env['runtime']['inputDriver'].updateInputDevices() diff --git a/src/fenrirscreenreader/core/outputManager.py b/src/fenrirscreenreader/core/outputManager.py index c6090120..5cb82e49 100644 --- a/src/fenrirscreenreader/core/outputManager.py +++ b/src/fenrirscreenreader/core/outputManager.py @@ -228,8 +228,11 @@ class outputManager(): offsetText = offsetText[offsetStart: offsetEnd] return offsetText def interruptOutput(self): - self.env['runtime']['speechDriver'].cancel() - self.env['runtime']['debug'].writeDebugOut("Interrupt speech",debug.debugLevel.INFO) + try: + self.env['runtime']['speechDriver'].cancel() + self.env['runtime']['debug'].writeDebugOut("Interrupt speech",debug.debugLevel.INFO) + except: + pass def clearFlushTime(self): self.setFlushTime(0.0) diff --git a/src/fenrirscreenreader/core/screenManager.py b/src/fenrirscreenreader/core/screenManager.py index 2a1add43..426e086c 100644 --- a/src/fenrirscreenreader/core/screenManager.py +++ b/src/fenrirscreenreader/core/screenManager.py @@ -10,7 +10,8 @@ import time, os, re, difflib class screenManager(): def __init__(self): - pass + self.currScreenIgnored = False + self.prevScreenIgnored = False def initialize(self, environment): self.env = environment self.env['runtime']['settingsManager'].loadDriver(\ @@ -40,15 +41,28 @@ class screenManager(): self.update(eventData, 'onScreenChange') self.env['screen']['lastScreenUpdate'] = time.time() def handleScreenUpdate(self, eventData): - self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] - if not self.isSuspendingScreen(self.env['screen']['newTTY']): + 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() + if not self.getCurrScreenIgnored(): self.update(eventData, 'onScreenUpdate') #if trigger == 'onUpdate' or self.isScreenChange() \ # or len(self.env['screen']['newDelta']) > 6: # self.env['runtime']['screenDriver'].getCurrApplication() self.env['screen']['lastScreenUpdate'] = time.time() + def getCurrScreenIgnored(self): + return self.currScreenIgnored + def getPrevScreenIgnored(self): + return self.prevScreenIgnored + def updateScreenIgnored(self): + self.prevScreenIgnored = self.currScreenIgnored + self.currScreenIgnored = self.isSuspendingScreen(self.env['screen']['newTTY']) def update(self, eventData, trigger='onUpdate'): - # set new "old" values self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes'] self.env['screen']['oldContentText'] = self.env['screen']['newContentText'] @@ -60,6 +74,7 @@ class screenManager(): self.env['screen']['oldAttribDelta'] = self.env['screen']['newAttribDelta'] self.env['screen']['oldNegativeDelta'] = self.env['screen']['newNegativeDelta'] self.env['screen']['newContentBytes'] = eventData['bytes'] + # get metadata like cursor or screensize self.env['screen']['lines'] = int( eventData['lines']) self.env['screen']['columns'] = int( eventData['columns']) @@ -135,7 +150,7 @@ class screenManager(): if self.env['screen']['oldContentAttrib'] != self.env['screen']['newContentAttrib']: if self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'): self.env['screen']['newAttribDelta'], self.env['screen']['newCursorAttrib'] = screen_utils.trackHighlights(self.env['screen']['oldContentAttrib'], self.env['screen']['newContentAttrib'], self.env['screen']['newContentText'], self.env['screen']['columns']) - + def formatAttributes(self, attribute, attributeFormatString = None): if not attributeFormatString: attributeFormatString = self.env['runtime']['settingsManager'].getSetting('general', 'attributeFormatString') diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index feb9f97e..ff317cd7 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -40,6 +40,7 @@ class driver(inputDriver): self.iDevices = {} self.iDevicesFD = self._manager.list() self.uDevices = {} + self.gDevices = {} self.iDeviceNo = 0 self.watchDog = Value(c_bool, True) def initialize(self, environment): @@ -116,8 +117,12 @@ class driver(inputDriver): def writeEventBuffer(self): if not self._initialized: return - for iDevice, uDevice, event in self.env['input']['eventBuffer']: - self.writeUInput(uDevice, event) + for iDevice, uDevice, event in self.env['input']['eventBuffer']: + try: + if self.gDevices[iDevice.fd]: + self.writeUInput(uDevice, event) + except Exception as e: + pass def clearEventBuffer(self): if not self._initialized: @@ -240,7 +245,7 @@ class driver(inputDriver): if not self._initialized: return for fd in self.iDevices: - self.grabDevice(fd) + self.grabDevice(fd) def ungrabAllDevices(self): if not self._initialized: return @@ -267,6 +272,7 @@ class driver(inputDriver): return try: self.iDevices[fd].grab() + 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): @@ -274,6 +280,7 @@ class driver(inputDriver): return try: self.iDevices[fd].ungrab() + self.gDevices[fd] = False except: pass def removeDevice(self,fd): @@ -298,7 +305,11 @@ class driver(inputDriver): del(self.uDevices[fd]) except: pass - self.updateMPiDevicesFD() + try: + del(self.gDevices[fd]) + except: + pass + self.MPiDevicesFD() def hasIDevices(self): if not self._initialized: