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() \