improve grabbing

This commit is contained in:
chrys 2018-05-17 21:57:54 +02:00
parent 4e14b4aa9d
commit b9038f5982
5 changed files with 26 additions and 23 deletions

View File

@ -16,6 +16,6 @@ class command():
def getDescription(self): def getDescription(self):
return 'No description found' return 'No description found'
def run(self): def run(self):
pass self.env['runtime']['inputManager'].updateInputDevices()
def setCallback(self, callback): def setCallback(self, callback):
pass pass

View File

@ -166,7 +166,6 @@ class fenrirManager():
#print('handleScreenUpdate:',time.time() - startTime) #print('handleScreenUpdate:',time.time() - startTime)
def handlePlugInputDevice(self, event): def handlePlugInputDevice(self, event):
self.environment['runtime']['inputManager'].updateInputDevices()
self.environment['runtime']['commandManager'].executeDefaultTrigger('onPlugInputDevice', force=True) self.environment['runtime']['commandManager'].executeDefaultTrigger('onPlugInputDevice', force=True)
def handleHeartBeat(self, event): def handleHeartBeat(self, event):

View File

@ -14,7 +14,7 @@ class inputManager():
def __init__(self): def __init__(self):
self.setLedState = True self.setLedState = True
self.shortcutType = 'KEY' self.shortcutType = 'KEY'
self.toggleDeviceGrab = False
def setShortcutType(self, shortcutType = 'KEY'): def setShortcutType(self, shortcutType = 'KEY'):
if shortcutType in ['KEY', 'BYTE']: if shortcutType in ['KEY', 'BYTE']:
self.shortcutType = shortcutType self.shortcutType = shortcutType
@ -39,6 +39,23 @@ class inputManager():
self.env['runtime']['settingsManager'].shutdownDriver('inputDriver') self.env['runtime']['settingsManager'].shutdownDriver('inputDriver')
def getInputEvent(self): def getInputEvent(self):
return self.env['runtime']['inputDriver'].getInputEvent() 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): def handleInputEvent(self, eventData):
self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT inputMan:' + str(eventData),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT inputMan:' + str(eventData),debug.debugLevel.INFO)
if not eventData: if not eventData:
@ -125,7 +142,7 @@ class inputManager():
self.env['runtime']['inputDriver'].updateInputDevices() self.env['runtime']['inputDriver'].updateInputDevices()
except: except:
pass pass
self.handleDeviceGrab(True)
def removeAllDevices(self): def removeAllDevices(self):
try: try:
self.env['runtime']['inputDriver'].removeAllDevices() self.env['runtime']['inputDriver'].removeAllDevices()

View File

@ -12,7 +12,6 @@ class screenManager():
def __init__(self): def __init__(self):
self.currScreenIgnored = False self.currScreenIgnored = False
self.prevScreenIgnored = False self.prevScreenIgnored = False
self.toggleDeviceGrab = False
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\ self.env['runtime']['settingsManager'].loadDriver(\
@ -41,24 +40,11 @@ class screenManager():
if not self.isSuspendingScreen(self.env['screen']['newTTY']): if not self.isSuspendingScreen(self.env['screen']['newTTY']):
self.update(eventData, 'onScreenChange') self.update(eventData, 'onScreenChange')
self.env['screen']['lastScreenUpdate'] = time.time() 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
def handleScreenUpdate(self, eventData): def handleScreenUpdate(self, eventData):
self.env['screen']['oldApplication'] = self.env['screen']['newApplication'] self.env['screen']['oldApplication'] = self.env['screen']['newApplication']
self.updateScreenIgnored() self.updateScreenIgnored()
self.handleDeviceGrab() self.env['runtime']['inputManager'].handleDeviceGrab()
if not self.getCurrScreenIgnored(): if not self.getCurrScreenIgnored():
self.update(eventData, 'onScreenUpdate') self.update(eventData, 'onScreenUpdate')
#if trigger == 'onUpdate' or self.isScreenChange() \ #if trigger == 'onUpdate' or self.isScreenChange() \

View File

@ -200,7 +200,6 @@ class driver(inputDriver):
self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("Device Skipped (Exception): " + deviceFile +' ' + currDevice.name +' '+ str(e),debug.debugLevel.INFO)
self.iDeviceNo = len(evdev.list_devices()) self.iDeviceNo = len(evdev.list_devices())
self.updateMPiDevicesFD() self.updateMPiDevicesFD()
def updateMPiDevicesFD(self): def updateMPiDevicesFD(self):
try: try:
for fd in self.iDevices: for fd in self.iDevices:
@ -298,6 +297,8 @@ class driver(inputDriver):
try: try:
self.iDevices[fd].grab() self.iDevices[fd].grab()
self.gDevices[fd] = True self.gDevices[fd] = True
except IOError:
self.gDevices[fd] = True
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR)
def ungrabDevice(self,fd): def ungrabDevice(self,fd):