Merge branch 'master' of github.com:chrys87/fenrir

This commit is contained in:
chrys 2018-03-09 14:33:57 +01:00
commit 2ce5adba82
8 changed files with 97 additions and 103 deletions

View File

@ -5,9 +5,6 @@ Things needing little knowledge are marked with "(Easy for contribution)". so ju
[X] = Done [X] = Done
Cleanups: Cleanups:
- split oldValues := newValues out to helper function
[] split it out
[] use it in vcsa driver
- Migrate *Data.py to classes and use getter/setter (Easy for contribution) - Migrate *Data.py to classes and use getter/setter (Easy for contribution)
[] commandsData.py [] commandsData.py
[] eventData.py [] eventData.py
@ -20,7 +17,11 @@ Cleanups:
[] settingsData -> defaultSettings.py [] settingsData -> defaultSettings.py
General: General:
- make fenrir runable without settingsfile. fallback to defaults - get information already in watchdogs insteed of mainloop (use eventloop to transport)
[X] InputDriver
[] ScreenDriver
[] split oldValues := newValues out to helper function
[] move processing of diff to watchdog
- imporove attribute handling - imporove attribute handling
[] improve attributes_curr_char (Easy for contribution) [] improve attributes_curr_char (Easy for contribution)
[] add an attribute sound (Easy for contribution) [] add an attribute sound (Easy for contribution)
@ -46,6 +47,8 @@ General:
[] select field separator [] select field separator
- make it runnable via pypy3 (low priority) - make it runnable via pypy3 (low priority)
[] wrapper script for running Fenrir to check if pypy exists, use python3 as fallback. [] wrapper script for running Fenrir to check if pypy exists, use python3 as fallback.
- make fenrir runnable without root permissions
- make fenrir runable without settingsfile. fallback to defaults
Braille Support: Braille Support:
[] brailleFocusMode: [] brailleFocusMode:

0
src/fenrir/core/eventData.py Executable file → Normal file
View File

View File

@ -49,12 +49,16 @@ class fenrirManager():
self.environment['runtime']['eventManager'].startMainEventLoop() self.environment['runtime']['eventManager'].startMainEventLoop()
self.shutdown() self.shutdown()
def handleInput(self, event): def handleInput(self, event):
#startTime = time.time() #startTime = time.time
eventReceived = self.environment['runtime']['inputManager'].getInputEvent() self.environment['runtime']['debug'].writeDebugOut('DEBUG INPUT fenrirMan:' + str(event),debug.debugLevel.INFO)
if not event['Data']:
event['Data'] = self.environment['runtime']['inputManager'].getInputEvent()
if event['Data']:
event['Data']['EventName'] = self.environment['runtime']['inputManager'].convertEventName(event['Data']['EventName'])
self.environment['runtime']['inputManager'].handleInputEvent(event['Data'])
if self.environment['runtime']['inputManager'].noKeyPressed(): if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['inputManager'].clearLastDeepInput() self.environment['runtime']['inputManager'].clearLastDeepInput()
if eventReceived: if True:
if self.environment['runtime']['screenManager'].isSuspendingScreen(): if self.environment['runtime']['screenManager'].isSuspendingScreen():
self.environment['runtime']['inputManager'].writeEventBuffer() self.environment['runtime']['inputManager'].writeEventBuffer()
else: else:
@ -82,6 +86,7 @@ class fenrirManager():
if event['Data'] == '': if event['Data'] == '':
return return
command = event['Data'] command = event['Data']
if self.environment['runtime']['helpManager'].isTutorialMode(): if self.environment['runtime']['helpManager'].isTutorialMode():
if self.environment['runtime']['commandManager'].commandExists( command, 'help'): if self.environment['runtime']['commandManager'].commandExists( command, 'help'):
self.environment['runtime']['commandManager'].executeCommand( command, 'help') self.environment['runtime']['commandManager'].executeCommand( command, 'help')
@ -157,6 +162,7 @@ class fenrirManager():
if self.environment['runtime']['inputManager'].noKeyPressed(): if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
self.command = '' self.command = ''
def shutdownRequest(self): def shutdownRequest(self):
try: try:
self.environment['runtime']['eventManager'].stopMainEventLoop() self.environment['runtime']['eventManager'].stopMainEventLoop()

View File

@ -17,9 +17,12 @@ class inputDriver():
self.releaseDevices() self.releaseDevices()
self._isInitialized = False self._isInitialized = False
def getInputEvent(self): def getInputEvent(self):
time.sleep(0.05)
return None
def handleInputEvent(self, event):
time.sleep(0.05) time.sleep(0.05)
if not self._initialized: if not self._initialized:
return None return
def writeEventBuffer(self): def writeEventBuffer(self):
if not self._initialized: if not self._initialized:
return return

View File

@ -27,52 +27,49 @@ class inputManager():
def shutdown(self): def shutdown(self):
self.removeAllDevices() self.removeAllDevices()
self.env['runtime']['settingsManager'].shutdownDriver('inputDriver') self.env['runtime']['settingsManager'].shutdownDriver('inputDriver')
def getInputEvent(self):
def getInputEvent(self): return self.env['runtime']['inputDriver'].getInputEvent()
eventReceived = False def handleInputEvent(self, eventData):
mEvent = self.env['runtime']['inputDriver'].getInputEvent() self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT inputMan:' + str(eventData),debug.debugLevel.INFO)
if mEvent: if not eventData:
mEvent['EventName'] = self.convertEventName(mEvent['EventName']) return
eventReceived = True self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
self.env['input']['prevInput'] = self.env['input']['currInput'].copy() if eventData['EventState'] == 0:
if mEvent['EventState'] == 0: if eventData['EventName'] in self.env['input']['currInput']:
if mEvent['EventName'] in self.env['input']['currInput']: self.env['input']['currInput'].remove(eventData['EventName'])
self.env['input']['currInput'].remove(mEvent['EventName']) if len(self.env['input']['currInput']) > 1:
if len(self.env['input']['currInput']) > 1: self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
self.env['input']['currInput'] = sorted(self.env['input']['currInput']) elif len(self.env['input']['currInput']) == 0:
elif len(self.env['input']['currInput']) == 0: self.env['input']['shortcutRepeat'] = 1
self.setLedState = self.handleLedStates(eventData)
self.lastInputTime = time.time()
elif eventData['EventState'] == 1:
if not eventData['EventName'] in self.env['input']['currInput']:
self.env['input']['currInput'].append(eventData['EventName'])
if len(self.env['input']['currInput']) > 1:
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
if len(self.lastDeepestInput) < len(self.env['input']['currInput']):
self.setLastDeepestInput( self.env['input']['currInput'].copy())
elif self.lastDeepestInput == self.env['input']['currInput']:
if time.time() - self.lastInputTime <= self.env['runtime']['settingsManager'].getSettingAsFloat('keyboard','doubleTapTimeout'):
self.env['input']['shortcutRepeat'] += 1
else:
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.setLedState = self.handleLedStates(mEvent) self.setLedState = self.handleLedStates(eventData)
self.lastInputTime = time.time() self.lastInputTime = time.time()
elif mEvent['EventState'] == 1: elif eventData['EventState'] == 2:
if not mEvent['EventName'] in self.env['input']['currInput']: self.lastInputTime = time.time()
self.env['input']['currInput'].append(mEvent['EventName'])
if len(self.env['input']['currInput']) > 1: self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
self.env['input']['currInput'] = sorted(self.env['input']['currInput']) self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
if len(self.lastDeepestInput) < len(self.env['input']['currInput']): self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
self.setLastDeepestInput( self.env['input']['currInput'].copy()) self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getLedState(1)
elif self.lastDeepestInput == self.env['input']['currInput']: self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
if time.time() - self.lastInputTime <= self.env['runtime']['settingsManager'].getSettingAsFloat('keyboard','doubleTapTimeout'): self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
self.env['input']['shortcutRepeat'] += 1 self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO)
else: if self.noKeyPressed():
self.env['input']['shortcutRepeat'] = 1 self.env['input']['prevInput'] = []
self.setLedState = self.handleLedStates(mEvent) self.setLedState = True
self.lastInputTime = time.time()
elif mEvent['EventState'] == 2:
self.lastInputTime = time.time()
else:
pass
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getLedState(1)
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO)
if self.noKeyPressed():
self.env['input']['prevInput'] = []
self.setLedState = True
return eventReceived
def handleLedStates(self, mEvent): def handleLedStates(self, mEvent):
if not self.setLedState: if not self.setLedState:

View File

@ -15,8 +15,3 @@ from fenrir.core import debug
class driver(inputDriver): class driver(inputDriver):
def __init__(self): def __init__(self):
inputDriver.__init__(self) inputDriver.__init__(self)
def getInputEvent(self):
time.sleep(0.1)
if not self._initialized:
return None

View File

@ -12,6 +12,7 @@ try:
import evdev import evdev
from evdev import InputDevice, UInput from evdev import InputDevice, UInput
_evdevAvailable = True _evdevAvailable = True
except Exception as e: except Exception as e:
_evdevAvailableError = str(e) _evdevAvailableError = str(e)
@ -60,7 +61,7 @@ class driver(inputDriver):
self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev) self.env['runtime']['processManager'].addCustomEventThread(self.plugInputDeviceWatchdogUdev)
else: else:
self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer) self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.PlugInputDevice, self.plugInputDeviceWatchdogTimer)
self.env['runtime']['processManager'].addSimpleEventThread(fenrirEventType.KeyboardInput, self.inputWatchdog, {'dev':self.iDevicesFD}) self.env['runtime']['processManager'].addCustomEventThread(self.inputWatchdog)
def plugInputDeviceWatchdogUdev(self,active , eventQueue): def plugInputDeviceWatchdogUdev(self,active , eventQueue):
context = pyudev.Context() context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context) monitor = pyudev.Monitor.from_netlink(context)
@ -70,67 +71,55 @@ class driver(inputDriver):
devices = monitor.poll(2) devices = monitor.poll(2)
if devices: if devices:
while monitor.poll(0.5): while monitor.poll(0.5):
time.sleep(0.2) time.sleep(0.08)
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None}) eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":None})
return time.time() return time.time()
def plugInputDeviceWatchdogTimer(self, active): def plugInputDeviceWatchdogTimer(self, active):
time.sleep(2.5) time.sleep(2.5)
return time.time() return time.time()
def inputWatchdog(self,active , params):
try: def inputWatchdog(self,active , eventQueue):
deviceFd = [] while active.value:
while self.watchDog.value == 0: r, w, x = select(self.iDevices, [], [], 0.5)
if active.value == 0:
return
r = []
while r == []:
if active.value == 0:
return
r, w, x = select(list(params['dev']), [], [], 0.3)
self.watchDog.value = 0
except:
pass
def getInputEvent(self):
if not self.hasIDevices():
self.watchDog.value = 1
return None
event = None
r, w, x = select(self.iDevices, [], [], 0.00001)
if r != []:
for fd in r: for fd in r:
event = None
foreward = False
eventFired = False
try: try:
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
except: except:
self.removeDevice(fd) self.removeDevice(fd)
self.watchDog.value = 1
return None
foreward = False
while(event): while(event):
self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT1:' + str(event),debug.debugLevel.INFO)
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])
if event.type == evdev.events.EV_KEY: if event.type == evdev.events.EV_KEY:
self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT2:' + str(event),debug.debugLevel.INFO)
if event.code != 0: if event.code != 0:
self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT3:' + str(event),debug.debugLevel.INFO)
currMapEvent = self.mapEvent(event) currMapEvent = self.mapEvent(event)
if not currMapEvent: if not currMapEvent:
foreward = True foreward = True
event = self.iDevices[fd].read_one() self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT4:' + str(currMapEvent),debug.debugLevel.INFO)
continue
if not isinstance(currMapEvent['EventName'], str): if not isinstance(currMapEvent['EventName'], str):
foreward = True foreward = True
event = self.iDevices[fd].read_one() self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT5:' + str(currMapEvent),debug.debugLevel.INFO)
continue if not foreward or eventFired:
if not foreward:
if currMapEvent['EventState'] in [0,1,2]: if currMapEvent['EventState'] in [0,1,2]:
self.watchDog.value = 1 eventQueue.put({"Type":fenrirEventType.KeyboardInput,"Data":currMapEvent.copy()})
return currMapEvent eventFired = True
self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT6:' + str(currMapEvent),debug.debugLevel.INFO)
else: else:
if not event.type in [0,1,4]: if not event.type in [0,4]:
foreward = True foreward = True
self.env['runtime']['debug'].writeDebugOut('DEBUG INPUT7:' + str(currMapEvent),debug.debugLevel.INFO)
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
if foreward: if foreward and not eventFired:
self.writeEventBuffer() self.writeEventBuffer()
self.clearEventBuffer() self.clearEventBuffer()
self.watchDog.value = 1
return None def handleInputEvent(self, event):
return
def writeEventBuffer(self): def writeEventBuffer(self):
if not self._initialized: if not self._initialized:
@ -230,6 +219,7 @@ class driver(inputDriver):
mEvent['EventSec'] = event.sec mEvent['EventSec'] = event.sec
mEvent['EventUsec'] = event.usec mEvent['EventUsec'] = event.usec
mEvent['EventState'] = event.value mEvent['EventState'] = event.value
mEvent['EventType'] = event.type
return mEvent return mEvent
except Exception as e: except Exception as e:
return None return None

View File

@ -118,7 +118,7 @@ class driver(screenDriver):
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR)
self.env['screen']['autoIgnoreScreens'] = [] self.env['screen']['autoIgnoreScreens'] = []
self.env['runtime']['debug'].writeDebugOut('getSessionInformation:' + str(self.env['screen']['autoIgnoreScreens']) + ' ' + str(self.env['general']) ,debug.debugLevel.INFO) #self.env['runtime']['debug'].writeDebugOut('getSessionInformation:' + str(self.env['screen']['autoIgnoreScreens']) + ' ' + str(self.env['general']) ,debug.debugLevel.INFO)
def updateWatchdog(self,active , eventQueue): def updateWatchdog(self,active , eventQueue):
try: try: