make fenrir key configurable

This commit is contained in:
chrys
2016-08-11 23:16:44 +02:00
parent b4f01f76f0
commit 794abf26e3
11 changed files with 69 additions and 80 deletions

View File

@ -2,5 +2,4 @@
generalInformation = {
'running': True,
'consumeKey': False,
}

View File

@ -2,6 +2,9 @@
input = {
'currShortcut': {},
'currShortcutString': ''
'currShortcutString': '',
'consumeKey': False,
'fenrirKey': ['82'],
'keyForeward': False,
}

View File

@ -19,25 +19,31 @@ class inputManager():
timeout = False
for fd in r:
for event in self.iDevices[fd].read():
if event.code == 82: # a
environment['generalInformation']['consumeKey'] = True
if not environment['generalInformation']['consumeKey']:
if self.isFenrirKey(environment, event): # a
environment['input']['consumeKey'] = not environment['input']['keyForeward']
if not environment['input']['consumeKey']:
self.uDevices[fd].write_event(event)
self.uDevices[fd].syn()
time.sleep(0.01)
else:
keyString = ''
if self.isFenrirKey(environment, event):
keyString = 'FENRIR'
else:
keyString = str(event.code)
if event.type == evdev.ecodes.EV_KEY:
if event.value != 0:
environment['input']['currShortcut'][str(event.code)] = 1 #event.value
environment['input']['currShortcut'][keyString] = 1 #event.value
else:
try:
del(environment['input']['currShortcut'][str(event.code)])
del(environment['input']['currShortcut'][keyString])
except:
pass
except Exception as e:
self.freeDevices()
time.sleep(0.01)
environment['input']['currShortcutString'] = self.getShortcutString(environment)
environment['generalInformation']['consumeKey'] = environment['input']['currShortcut'] != {}
environment['input']['consumeKey'] = environment['input']['currShortcut'] != {} and environment['input']['consumeKey']
environment['input']['keyForeward'] = environment['input']['keyForeward'] and environment['input']['currShortcut'] == {}
return environment, timeout
def getShortcutString(self, environment):
@ -45,10 +51,12 @@ class inputManager():
return ''
currShortcutStringList = []
for key in environment['input']['currShortcut']:
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
currShortcutStringList = sorted(currShortcutStringList)
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
def isFenrirKey(self,environment, event):
return str(event.code) in environment['input']['fenrirKey']
def getDevices(self):
self.iDevices = map(evdev.InputDevice, (evdev.list_devices()))
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
@ -57,7 +65,6 @@ class inputManager():
dev = self.iDevices[fd]
cap = dev.capabilities()
del cap[0]
print(dev.name)
self.uDevices[fd] = UInput(
cap,
dev.name,

View File

@ -32,6 +32,7 @@ settings = {
'keyboardLayout': "desktop",
'debugLevel': debug.debugLevel.DEACTIVE,
'punctuationLevel': 1,
'fenrirKeys':['82'],
},
'keyboard':{
'device':"all",

View File

@ -30,6 +30,7 @@ class settingsManager():
keys = sepLine[0].replace(" ","").split(',')
currShortcut = []
validKeyString = True
keyIdent = ''
for key in keys:
if len(key) < 3:
validKeyString = False
@ -41,24 +42,28 @@ class settingsManager():
validKeyString = False
break
if key[2:] != '':
keyInt = self.getCodeForKeyID(key[2:])
if key[2:] == 'FENRIR':
keyIdent= 'FENRIR'
else:
keyInt = self.getCodeForKeyID(key[2:])
keyIdent = str(keyInt)
else:
validKeyString = False
break
if keyInt == 0:
if keyIdent == '':
validKeyString = False
break
break
if not validKeyString:
break
else:
currShortcut.append(key[0] + '-' + str(keyInt))
currShortcut.append(key[0] + '-' + keyIdent)
if validKeyString:
keyString = ''
for k in sorted(currShortcut):
if keyString != '':
keyString += ','
keyString += k
environment['bindings'][keyString] = commandString
environment['bindings'][keyString] = commandString
kbConfig.close()
return environment
@ -165,7 +170,20 @@ class settingsManager():
spec.loader.exec_module(driver_mod)
environment['runtime']['screenDriver'] = driver_mod.screen()
return environment
def setFenrirKeys(self, environment, keys):
keyList = keys.split(',')
for key in keyList:
keyID = self.keyIDasString( key)
if keyID != '':
if not keyID in environment['input']['fenrirKey']:
environment['input']['fenrirKey'].append(keyID)
return environment
def keyIDasString(self, key):
try:
KeyID = self.getCodeForKeyID(key)
return str(KeyID)
except:
return ''
def initFenrirConfig(self):
return self.reInitFenrirConfig(environment.environment)
@ -175,6 +193,7 @@ class settingsManager():
environment['runtime']['inputManager'] = inputManager.inputManager()
environment['runtime']['outputManager'] = outputManager.outputManager()
environment = environment['runtime']['settingsManager'].loadSettings(environment)
environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')):
self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout'))
@ -205,4 +224,4 @@ class settingsManager():
environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'))
return environment