improved device detection

xkb
sezanzeb 4 years ago committed by sezanzeb
parent fc769c804d
commit 6bf89a89d9

@ -109,13 +109,16 @@ class _GetDevices(threading.Thread):
is_gamepad = map_abs_to_rel(capabilities)
usb = device.phys.split('/')[0]
if grouped.get(usb) is None:
grouped[usb] = []
name = device.name
path = device.path
logger.spam('Found "%s", %s, %s', device.name, device.path, usb)
info = str(device.info)
if grouped.get(info) is None:
grouped[info] = []
grouped[usb].append((device.name, device.path, is_gamepad))
logger.spam('Found "%s", "%s", "%s"', info, path, name)
grouped[info].append((name, path, is_gamepad))
# now write down all the paths of that group
result = {}

@ -121,7 +121,7 @@ class Row(Gtk.ListBoxRow):
# keycode is already set by some other row
existing = custom_mapping.get_character(new_key)
if existing is not None:
msg = f'"{to_string(*new_key)}" already mapped to {existing}"'
msg = f'"{to_string(*new_key)}" already mapped to "{existing}"'
logger.info(msg)
self.window.get('status_bar').push(CTX_KEYCODE, msg)
return

@ -73,26 +73,33 @@ pending_events = {}
# key-mapper is only interested in devices that have EV_KEY, add some
# random other stuff to test that they are ignored.
phys_1 = 'usb-0000:03:00.0-1/input2'
info_1 = 'bus: 0001, vendor 0001, product 0001, version 0001'
fixtures = {
# device 1
'/dev/input/event11': {
'capabilities': {evdev.ecodes.EV_KEY: [], evdev.ecodes.EV_REL: []},
'phys': 'usb-0000:03:00.0-1/input2',
'phys': f'{phys_1}/input2',
'info': info_1,
'name': 'device 1 foo'
},
'/dev/input/event10': {
'capabilities': {evdev.ecodes.EV_KEY: list(evdev.ecodes.keys.keys())},
'phys': 'usb-0000:03:00.0-1/input3',
'phys': f'{phys_1}/input3',
'info': info_1,
'name': 'device 1'
},
'/dev/input/event13': {
'capabilities': {evdev.ecodes.EV_KEY: [], evdev.ecodes.EV_SYN: []},
'phys': 'usb-0000:03:00.0-1/input1',
'phys': f'{phys_1}/input1',
'info': info_1,
'name': 'device 1'
},
'/dev/input/event14': {
'capabilities': {evdev.ecodes.EV_SYN: []},
'phys': 'usb-0000:03:00.0-1/input0',
'phys': f'{phys_1}/input0',
'info': info_1,
'name': 'device 1 qux'
},
@ -100,6 +107,7 @@ fixtures = {
'/dev/input/event20': {
'capabilities': {evdev.ecodes.EV_KEY: list(evdev.ecodes.keys.keys())},
'phys': 'usb-0000:03:00.0-2/input1',
'info': 'bus: 0002, vendor 0001, product 0002, version 0001',
'name': 'device 2'
},
@ -118,6 +126,7 @@ fixtures = {
]
},
'phys': 'usb-0000:03:00.0-3/input1',
'info': 'bus: 0003, vendor 0001, product 0003, version 0001',
'name': 'gamepad'
},
@ -125,6 +134,7 @@ fixtures = {
'/dev/input/event31': {
'capabilities': {evdev.ecodes.EV_SYN: []},
'phys': 'usb-0000:03:00.0-4/input1',
'info': 'bus: 0004, vendor 0001, product 0004, version 0001',
'name': 'Power Button'
},
@ -133,6 +143,7 @@ fixtures = {
'/dev/input/event40': {
'capabilities': {evdev.ecodes.EV_KEY: list(evdev.ecodes.keys.keys())},
'phys': 'key-mapper/input1',
'info': 'bus: 0005, vendor 0001, product 0005, version 0001',
'name': 'key-mapper device 2'
},
}
@ -227,6 +238,7 @@ class InputDevice:
self.path = path
self.phys = fixtures[path]['phys']
self.info = fixtures[path]['info']
self.name = fixtures[path]['name']
self.fd = self.name

@ -203,6 +203,7 @@ class TestDaemon(unittest.TestCase):
fixtures[self.new_fixture] = {
'capabilities': {evdev.ecodes.EV_KEY: [ev[1]]},
'phys': '9876 phys',
'info': 'abcd',
'name': device
}

@ -185,6 +185,7 @@ class TestInjector(unittest.TestCase):
fixtures[path] = {
'name': 'gamepad 2',
'phys': 'abcd',
'info': '1234',
'capabilities': gamepad_template['capabilities']
}
del fixtures[path]['capabilities'][EV_KEY]

Loading…
Cancel
Save