From 0e8ebc43b44d925e219e189bd1fcc5ea924d1e9b Mon Sep 17 00:00:00 2001 From: Chrys Date: Sat, 24 Aug 2019 18:26:40 +0200 Subject: [PATCH] try remove sound for virtual devices --- .../onPlugInputDevice/50000-UpdateDevices.py | 22 ------------ .../onPlugInputDevice/80000-plugSound.py | 25 ------------- .../commands/onPlugInputDevice/plugSound.py | 35 +++++++++++++++++++ src/fenrirscreenreader/core/inputManager.py | 27 +++++++++----- .../inputDriver/evdevDriver.py | 8 +++-- 5 files changed, 59 insertions(+), 58 deletions(-) delete mode 100755 src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py delete mode 100755 src/fenrirscreenreader/commands/onPlugInputDevice/80000-plugSound.py create mode 100755 src/fenrirscreenreader/commands/onPlugInputDevice/plugSound.py diff --git a/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py b/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py deleted file mode 100755 index 9d0c0677..00000000 --- a/src/fenrirscreenreader/commands/onPlugInputDevice/50000-UpdateDevices.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/python -# -*- coding: utf-8 -*- - -# Fenrir TTY screen reader -# By Chrys, Storm Dragon, and contributers. - -from fenrirscreenreader.core import debug - -class command(): - def __init__(self): - pass - def initialize(self, environment): - self.env = environment - def shutdown(self): - pass - def getDescription(self): - return 'No description found' - def run(self): - pass - #self.env['runtime']['inputManager'].updateInputDevices() - def setCallback(self, callback): - pass diff --git a/src/fenrirscreenreader/commands/onPlugInputDevice/80000-plugSound.py b/src/fenrirscreenreader/commands/onPlugInputDevice/80000-plugSound.py deleted file mode 100755 index 34a6dac0..00000000 --- a/src/fenrirscreenreader/commands/onPlugInputDevice/80000-plugSound.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/python -# -*- coding: utf-8 -*- - -# Fenrir TTY screen reader -# By Chrys, Storm Dragon, and contributers. - -from fenrirscreenreader.core import debug -import time - -class command(): - def __init__(self): - pass - def initialize(self, environment): - self.env = environment - self.lastTime = time.time() - def shutdown(self): - pass - def getDescription(self): - return 'No description found' - def run(self): - if time.time() - self.lastTime > 2: - self.env['runtime']['outputManager'].playSoundIcon(soundIcon = 'accept', interrupt=True) - lastTime = time.time() - def setCallback(self, callback): - pass diff --git a/src/fenrirscreenreader/commands/onPlugInputDevice/plugSound.py b/src/fenrirscreenreader/commands/onPlugInputDevice/plugSound.py new file mode 100755 index 00000000..425c21c0 --- /dev/null +++ b/src/fenrirscreenreader/commands/onPlugInputDevice/plugSound.py @@ -0,0 +1,35 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from fenrirscreenreader.core import debug +import time + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + self.lastTime = time.time() + self.tempDisable = False + def shutdown(self): + pass + def getDescription(self): + return 'No description found' + def run(self): + if time.time() - self.lastTime > 5: + if not self.isTempDisable(): + self.env['runtime']['outputManager'].playSoundIcon(soundIcon = 'accept', interrupt=True) + else: + self.resetTempDisable() + lastTime = time.time() + def setCallback(self, callback): + pass + def setTempDisable(self): + self.tempDisable = True + def resetTempDisable(self): + self.tempDisable = False + def isTempDisable(self): + return self.tempDisable diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index ee3e522e..6ce3d667 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -132,11 +132,11 @@ class inputManager(): def handleLedStates(self, mEvent): try: if mEvent['EventName'] == 'KEY_NUMLOCK': - self.env['runtime']['inputDriver'].toggleLedState() - elif mEvent['EventName'] == 'KEY_CAPSLOCK': - self.env['runtime']['inputDriver'].toggleLedState(1) - elif mEvent['EventName'] == 'KEY_SCROLLLOCK': - self.env['runtime']['inputDriver'].toggleLedState(2) + self.env['runtime']['inputDriver'].toggleLedState() + elif mEvent['EventName'] == 'KEY_CAPSLOCK': + self.env['runtime']['inputDriver'].toggleLedState(1) + elif mEvent['EventName'] == 'KEY_SCROLLLOCK': + self.env['runtime']['inputDriver'].toggleLedState(2) except: pass def grabAllDevices(self): @@ -144,7 +144,7 @@ class inputManager(): try: self.env['runtime']['inputDriver'].grabAllDevices() except Exception as e: - pass + pass def ungrabAllDevices(self): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): try: @@ -152,8 +152,19 @@ class inputManager(): except Exception as e: pass def handlePlugInputDevice(self, eventData): - self.env['runtime']['inputManager'].updateInputDevices(eventData) - + playSound = False + for deviceEntry in eventData: + self.env['runtime']['inputManager'].updateInputDevices(deviceEntry['device']) + # dont play sounds for virtual devices + try: + playSound = playSound or not deviceEntry['virtual'] + except: + playSound = True + if not playSound: + try: + self.env['commands']['onPlugInputDevice']['PLUGSOUND'].setTempDisable() + except: + pass def updateInputDevices(self, newDevice = None): try: self.env['runtime']['inputDriver'].updateInputDevices(newDevice) diff --git a/src/fenrirscreenreader/inputDriver/evdevDriver.py b/src/fenrirscreenreader/inputDriver/evdevDriver.py index 0705f71f..e4a66695 100644 --- a/src/fenrirscreenreader/inputDriver/evdevDriver.py +++ b/src/fenrirscreenreader/inputDriver/evdevDriver.py @@ -70,13 +70,13 @@ class driver(inputDriver): while device: self.env['runtime']['debug'].writeDebugOut('plugInputDeviceWatchdogUdev:' + str(device), debug.debugLevel.INFO) try: - #if not '/sys/devices/virtual/input/' in device.sys_path: + virtual = '/sys/devices/virtual/input/' in device.sys_path if device.device_node: - validDevices.append(str(device.device_node)) + validDevices.append({'device': device.device_node, 'virtual': virtual}) except: pass try: - device = monitor.poll(0.1) + device = monitor.poll(0.5) except: device = None if validDevices: @@ -149,6 +149,8 @@ class driver(inputDriver): deviceFileList = None if newDevices and not init: + if not isinstance(newDevices, list): + newDevices = [newDevices] deviceFileList = newDevices else: deviceFileList = evdev.list_devices()