From 0279edf4ff23fc0655c3836dad319efdbdb7cf3f Mon Sep 17 00:00:00 2001 From: Chrys Date: Mon, 21 Oct 2019 23:09:15 +0200 Subject: [PATCH] detect device only once --- play zone/start2.sh | 10 ++++----- src/fenrirscreenreader/core/fenrirManager.py | 7 +------ src/fenrirscreenreader/core/inputManager.py | 6 +++--- .../inputDriver/evdevDriver.py | 21 ++++++++++++++----- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/play zone/start2.sh b/play zone/start2.sh index e627bbec..8dca1112 100755 --- a/play zone/start2.sh +++ b/play zone/start2.sh @@ -22,11 +22,11 @@ # #--code-- -for i in /tmp/fenrirscreenreader-*.sock ; do -if [[ "$i" != "/tmp/fenrirscreenreader-deamon.sock" ]]; then - echo -n "setting set screen#suspendingScreen=pty" | socat - UNIX-CLIENT:$i - fi -done +#for i in /tmp/fenrirscreenreader-*.sock ; do +#if [[ "$i" != "/tmp/fenrirscreenreader-deamon.sock" ]]; then +# echo -n "setting set screen#suspendingScreen=pty" | socat - UNIX-CLIENT:$i +# fi +#done /usr/bin/urxvt -e ../src/fenrir -d -s ./xterm.conf -o "general.shell=./waitForKey2;remote#socketFile=/tmp/fenrirscreenreader-waitForKey2.sock" diff --git a/src/fenrirscreenreader/core/fenrirManager.py b/src/fenrirscreenreader/core/fenrirManager.py index 99e5e188..a118a493 100644 --- a/src/fenrirscreenreader/core/fenrirManager.py +++ b/src/fenrirscreenreader/core/fenrirManager.py @@ -83,9 +83,9 @@ class fenrirManager(): else: self.environment['runtime']['inputManager'].writeEventBuffer() if self.environment['runtime']['inputManager'].noKeyPressed(): - self.environment['runtime']['inputManager'].handleDeviceGrab() self.modifierInput = False self.singleKeyCommand = False + self.environment['runtime']['inputManager'].handleDeviceGrab() if self.environment['input']['keyForeward'] > 0: self.environment['input']['keyForeward'] -=1 self.environment['runtime']['commandManager'].executeDefaultTrigger('onKeyInput') @@ -201,11 +201,6 @@ class fenrirManager(): 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: diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index d6a02d79..0fcd75c7 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -6,7 +6,7 @@ from fenrirscreenreader.core import debug from fenrirscreenreader.core import inputData -import os, inspect, time +import os, inspect, time, traceback currentdir = os.path.dirname(os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe())))) fenrirPath = os.path.dirname(currentdir) @@ -61,14 +61,14 @@ class inputManager(): return if self.env['runtime']['screenManager'].getCurrScreenIgnored(): while not self.ungrabAllDevices(): - time.sleep(0.2) + time.sleep(0.25) self.env['runtime']['debug'].writeDebugOut("retry ungrabAllDevices " ,debug.debugLevel.WARNING) print('try ungrabbing') self.env['runtime']['debug'].writeDebugOut("All devices ungrabbed" ,debug.debugLevel.INFO) print('ungrabbed') else: while not self.grabAllDevices(): - time.sleep(0.2) + time.sleep(0.25) self.env['runtime']['debug'].writeDebugOut("retry grabAllDevices" ,debug.debugLevel.WARNING) print('try grabbing') print('grabbed') diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 31d51b5f..09ed1cb5 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -64,21 +64,31 @@ class driver(inputDriver): monitor = pyudev.Monitor.from_netlink(context) monitor.filter_by(subsystem='input') monitor.start() + ignorePlug = False while active.value: validDevices = [] device = monitor.poll(1) while device: self.env['runtime']['debug'].writeDebugOut('plugInputDeviceWatchdogUdev:' + str(device), debug.debugLevel.INFO) try: - virtual = '/sys/devices/virtual/input/' in device.sys_path - if device.device_node: - validDevices.append({'device': device.device_node, 'virtual': virtual}) + if currDevice.name.upper() in ['','SPEAKUP','FENRIR-UINPUT']: + ignorePlug = True + if currDevice.phys.upper() in ['','SPEAKUP']: + ignorePlug = True + if 'BRLTTY' in currDevice.name.upper(): + ignorePlug = True + if not ignorePlug: + virtual = '/sys/devices/virtual/input/' in device.sys_path + if device.device_node: + validDevices.append({'device': device.device_node, 'virtual': virtual}) except: pass try: - device = monitor.poll(0.5) + pollTimeout = 1 + device = monitor.poll(pollTimeout) except: device = None + ignorePlug = False if validDevices: eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":validDevices}) return time.time() @@ -138,7 +148,7 @@ class driver(inputDriver): def writeUInput(self, uDevice, event): if not self._initialized: - return + return uDevice.write_event(event) uDevice.syn() @@ -345,6 +355,7 @@ class driver(inputDriver): if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): return True try: + print(self.iDevices[fd]) self.iDevices[fd].grab() self.gDevices[fd] = True self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO)