fenrir/src/fenrir-package/core/inputManager.py

136 lines
6.4 KiB
Python
Raw Normal View History

#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
2016-08-11 08:37:46 -04:00
import time
from core import debug
2016-09-17 17:38:40 -04:00
from core import inputEvent
2016-07-07 15:40:10 -04:00
class inputManager():
def __init__(self):
pass
def initialize(self, environment):
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'), 'inputDriver')
2016-09-18 07:13:58 -04:00
# init LEDs with current state
environment['input']['newNumLock'] = environment['runtime']['inputDriver'].getNumlock(environment)
environment['input']['oldNumLock'] = environment['input']['newNumLock']
environment['input']['newCapsLock'] = environment['runtime']['inputDriver'].getCapslock(environment)
environment['input']['oldCapsLock'] = environment['input']['newCapsLock']
environment['input']['newScrollLock'] = environment['runtime']['inputDriver'].getScrollLock(environment)
environment['input']['oldScrollLock'] = environment['input']['newScrollLock']
2016-09-18 09:13:24 -04:00
self.grabDevices(environment)
def shutdown(self, environment):
environment['runtime']['inputManager'].releaseDevices(environment)
if environment['runtime']['inputDriver']:
environment['runtime']['inputDriver'].shutdown(environment)
def proceedInputEvent(self, environment):
2016-09-02 20:22:56 -04:00
timeout = True
2016-09-18 09:13:24 -04:00
mEvent = environment['runtime']['inputDriver'].getInput(environment)
2016-09-21 03:56:59 -04:00
mEvent['EventName'] = self.convertEventName(mEvent['EventName'])
2016-09-18 09:13:24 -04:00
if mEvent:
2016-09-17 17:38:40 -04:00
if mEvent['EventValue'] == 0:
return True
2016-09-12 18:05:29 -04:00
timeout = False
2016-09-17 17:38:40 -04:00
if mEvent['EventState'] == 0:
2016-09-21 03:56:59 -04:00
if mEvent['EventName'] in environment['input']['currInput']:
2016-09-17 17:38:40 -04:00
environment['input']['currInput'].remove(mEvent['EventName'])
2016-09-21 03:56:59 -04:00
environment['input']['currInput'] = sorted(environment['input']['currInput'])
2016-09-17 17:38:40 -04:00
elif mEvent['EventState'] == 1:
2016-09-21 03:56:59 -04:00
if not mEvent['EventName'] in environment['input']['currInput']:
environment['input']['currInput'].append(mEvent['EventName'])
environment['input']['currInput'] = sorted(environment['input']['currInput'])
2016-09-17 17:38:40 -04:00
elif mEvent['EventState'] == 2:
pass
else:
pass
environment['input']['oldNumLock'] = environment['input']['newNumLock']
environment['input']['newNumLock'] = environment['runtime']['inputDriver'].getNumlock(environment)
environment['input']['oldCapsLock'] = environment['input']['newCapsLock']
environment['input']['newCapsLock'] = environment['runtime']['inputDriver'].getCapslock(environment)
environment['input']['oldScrollLock'] = environment['input']['newScrollLock']
environment['input']['newScrollLock'] = environment['runtime']['inputDriver'].getScrollLock(environment)
2016-09-17 17:38:40 -04:00
environment['input']['lastInputTime'] = time.time()
environment['input']['shortcutRepeat'] = 1
return timeout
2016-09-12 17:29:16 -04:00
def grabDevices(self, environment):
2016-09-16 20:30:34 -04:00
if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices'):
environment['runtime']['inputDriver'].grabDevices(environment)
def releaseDevices(self, environment):
2016-09-18 09:13:24 -04:00
environment['runtime']['inputDriver'].releaseDevices(environment)
2016-09-21 03:56:59 -04:00
def convertEventName(self, eventName):
if eventName == 'KEY_LEFTCTRL':
eventName == 'KEY_CTRL'
elif eventName == 'KEY_RIGHTCTRL':
eventName = 'KEY_CTRL'
elif eventName == 'KEY_LEFTSHIFT':
eventName = 'KEY_SHIFT'
elif eventName == 'KEY_RIGHTSHIFT':
eventName = 'KEY_SHIFT'
elif eventName == 'KEY_LEFTALT':
eventName = 'KEY_ALT'
elif eventName == 'KEY_RIGHTALT':
eventName = 'KEY_ALT'
if self.isFenrirKey(environment, eventName):
eventName = 'KEY_FENRIR'
return eventName
def isConsumeInput(self, environment):
2016-09-18 09:13:24 -04:00
return environment['runtime']['commandManager'].isCommandQueued(environment) and \
not environment['input']['keyForeward']
#and
# not (environment['input']['keyForeward'] or \
# environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices'))
def clearEventBuffer(self, environment):
environment['runtime']['inputDriver'].clearEventBuffer(environment)
2016-09-18 09:13:24 -04:00
def writeEventBuffer(self, environment):
2016-08-31 07:27:04 -04:00
try:
2016-09-18 09:13:24 -04:00
environment['runtime']['inputDriver'].writeEventBuffer(environment)
2016-09-02 12:08:44 -04:00
except Exception as e:
2016-09-18 09:13:24 -04:00
print(e)
2016-09-02 12:08:44 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"Error while writeUInput",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR)
2016-09-18 09:13:24 -04:00
def isFenrirKeyPressed(self, environment):
return 'KEY_FENRIR' in environment['input']['currInput']
2016-09-12 17:29:16 -04:00
2016-09-18 09:13:24 -04:00
def noKeyPressed(self, environment):
return environment['input']['currInput'] == []
2016-09-16 19:59:38 -04:00
def getPrevDeepestInput(self, environment):
shortcut = []
shortcut.append(environment['input']['shortcutRepeat'])
shortcut.append(sorted(environment['input']['prevDeepestInput']))
def getPrevShortcut(self, environment):
shortcut = []
shortcut.append(environment['input']['shortcutRepeat'])
shortcut.append(sorted(environment['input']['prevInput']))
2016-09-17 17:38:40 -04:00
return str(shortcut)
2016-09-16 19:59:38 -04:00
2016-09-17 17:38:40 -04:00
def getCurrShortcut(self, environment):
2016-09-16 19:59:38 -04:00
shortcut = []
shortcut.append(environment['input']['shortcutRepeat'])
2016-09-17 17:38:40 -04:00
shortcut.append(sorted(environment['input']['currInput']))
return str(shortcut)
2016-09-21 03:56:59 -04:00
def isFenrirKey(self,environment, eventName):
return eventName in environment['input']['fenrirKey']
def getCommandForShortcut(self, environment, shortcut):
shortcut = shortcut.upper()
2016-09-16 19:59:38 -04:00
if not self.shortcutExists(environment, shortcut):
return ''
2016-09-16 19:59:38 -04:00
return environment['bindings'][shortcut].upper()
2016-09-16 19:59:38 -04:00
def shortcutExists(self, environment, shortcut):
return( str(shortcut).upper() in environment['bindings'])