mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-04 12:00:16 +00:00
ignoring Power Button
This commit is contained in:
parent
20e1e8906c
commit
b2fed7887f
@ -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:
|
||||||
|
@ -70,12 +70,17 @@ fixtures = {
|
|||||||
'name': 'device 2'
|
'name': 'device 2'
|
||||||
},
|
},
|
||||||
|
|
||||||
# something that is completely ignored
|
# devices that are completely ignored
|
||||||
'/dev/input/event30': {
|
'/dev/input/event30': {
|
||||||
'capabilities': {evdev.ecodes.EV_SYN: []},
|
'capabilities': {evdev.ecodes.EV_SYN: []},
|
||||||
'phys': 'usb-0000:03:00.0-3/input1',
|
'phys': 'usb-0000:03:00.0-3/input1',
|
||||||
'name': 'device 3'
|
'name': 'device 3'
|
||||||
},
|
},
|
||||||
|
'/dev/input/event31': {
|
||||||
|
'capabilities': {evdev.ecodes.EV_SYN: []},
|
||||||
|
'phys': 'usb-0000:03:00.0-4/input1',
|
||||||
|
'name': 'Power Button'
|
||||||
|
},
|
||||||
|
|
||||||
# key-mapper devices are not displayed in the ui, some instance
|
# key-mapper devices are not displayed in the ui, some instance
|
||||||
# of key-mapper started injecting apparently.
|
# of key-mapper started injecting apparently.
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from keymapper.getdevices import _GetDevicesProcess, get_devices
|
from keymapper.getdevices import _GetDevices, get_devices
|
||||||
|
|
||||||
|
|
||||||
class FakePipe:
|
class FakePipe:
|
||||||
@ -36,7 +36,7 @@ class TestGetDevices(unittest.TestCase):
|
|||||||
# don't actually start the process, just use the `run` function.
|
# don't actually start the process, just use the `run` function.
|
||||||
# otherwise the coverage tool can't keep track.
|
# otherwise the coverage tool can't keep track.
|
||||||
pipe = FakePipe()
|
pipe = FakePipe()
|
||||||
_GetDevicesProcess(pipe).run()
|
_GetDevices(pipe).run()
|
||||||
self.assertDictEqual(pipe.devices, {
|
self.assertDictEqual(pipe.devices, {
|
||||||
'device 1': {
|
'device 1': {
|
||||||
'paths': [
|
'paths': [
|
||||||
|
Loading…
Reference in New Issue
Block a user