|
|
@ -23,7 +23,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import multiprocessing
|
|
|
|
import multiprocessing
|
|
|
|
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
import evdev
|
|
|
|
import evdev
|
|
|
|
|
|
|
|
|
|
|
@ -33,14 +35,12 @@ from keymapper.logger import logger
|
|
|
|
_devices = None
|
|
|
|
_devices = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _GetDevicesProcess(multiprocessing.Process):
|
|
|
|
class _GetDevices(threading.Thread):
|
|
|
|
"""Process to get the devices that can be worked with.
|
|
|
|
"""Process to get the devices that can be worked with.
|
|
|
|
|
|
|
|
|
|
|
|
Since InputDevice destructors take quite some time, do this
|
|
|
|
Since InputDevice destructors take quite some time, do this
|
|
|
|
asynchronously so that they can take as much time as they want without
|
|
|
|
asynchronously so that they can take as much time as they want without
|
|
|
|
slowing down the initialization. To avoid evdevs asyncio stuff spamming
|
|
|
|
slowing down the initialization.
|
|
|
|
errors, do this with multiprocessing and not multithreading.
|
|
|
|
|
|
|
|
TODO to threading, make eventloop
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def __init__(self, pipe):
|
|
|
|
def __init__(self, pipe):
|
|
|
|
"""Construct the process.
|
|
|
|
"""Construct the process.
|
|
|
@ -55,6 +55,9 @@ class _GetDevicesProcess(multiprocessing.Process):
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
def run(self):
|
|
|
|
"""Do what get_devices describes."""
|
|
|
|
"""Do what get_devices describes."""
|
|
|
|
|
|
|
|
# evdev needs asyncio to work
|
|
|
|
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
logger.debug('Discovering device paths')
|
|
|
|
logger.debug('Discovering device paths')
|
|
|
|
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
|
|
|
|
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
|
|
|
|
|
|
|
|
|
|
|
@ -62,6 +65,9 @@ class _GetDevicesProcess(multiprocessing.Process):
|
|
|
|
# "Logitech USB Keyboard" and "Logitech USB Keyboard Consumer Control"
|
|
|
|
# "Logitech USB Keyboard" and "Logitech USB Keyboard Consumer Control"
|
|
|
|
grouped = {}
|
|
|
|
grouped = {}
|
|
|
|
for device in devices:
|
|
|
|
for device in devices:
|
|
|
|
|
|
|
|
if device.name == 'Power Button':
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
# only keyboard devices
|
|
|
|
# only keyboard devices
|
|
|
|
# https://www.kernel.org/doc/html/latest/input/event-codes.html
|
|
|
|
# https://www.kernel.org/doc/html/latest/input/event-codes.html
|
|
|
|
capabilities = device.capabilities().keys()
|
|
|
|
capabilities = device.capabilities().keys()
|
|
|
@ -122,7 +128,7 @@ def get_devices(include_keymapper=False):
|
|
|
|
global _devices
|
|
|
|
global _devices
|
|
|
|
if _devices is None:
|
|
|
|
if _devices is None:
|
|
|
|
pipe = multiprocessing.Pipe()
|
|
|
|
pipe = multiprocessing.Pipe()
|
|
|
|
_GetDevicesProcess(pipe[1]).start()
|
|
|
|
_GetDevices(pipe[1]).start()
|
|
|
|
# block until devices are available
|
|
|
|
# block until devices are available
|
|
|
|
_devices = pipe[0].recv()
|
|
|
|
_devices = pipe[0].recv()
|
|
|
|
if len(_devices) == 0:
|
|
|
|
if len(_devices) == 0:
|
|
|
|