Skip to content

Commit

Permalink
Do not exclude buttonless devices that have axes (sezanzeb#956)
Browse files Browse the repository at this point in the history
* Do not exclude buttonless devices that have axes

* Fix linting issue

* Correct tests to not exclude axis-only devices

* Removed unnecessary test, fixed whitespace lint

* Reverting the lint now there's less conditions
  • Loading branch information
StelardActek authored Oct 1, 2024
1 parent 530e70a commit 7586ad9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions inputremapper/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,11 @@ def run(self):
capabilities = device.capabilities(absinfo=False)

key_capa = capabilities.get(EV_KEY)
abs_capa = capabilities.get(EV_ABS)
rel_capa = capabilities.get(EV_REL)

if key_capa is None and device_type != DeviceType.GAMEPAD:
# skip devices that don't provide buttons that can be mapped
if key_capa is None and abs_capa is None and rel_capa is None:
# skip devices that don't provide buttons or axes that can be mapped
logger.debug('"%s" has no useful capabilities', device.name)
continue

Expand Down
20 changes: 13 additions & 7 deletions tests/unit/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ def test_skip_camera(self):
self.assertIsNotNone(groups.find(name="gamepad"))

def test_device_with_only_ev_abs(self):
# could be anything, a lot of devices have ABS_X capabilities,
# so it is not treated as gamepad joystick and since it also
# doesn't have key capabilities, there is nothing to map.
# As Input Mapper can now map axes to buttons,
# a single EV_ABS device is valid for mapping.
fixtures["/foo/bar"] = {
"name": "qux",
"phys": "abcd2",
Expand All @@ -192,12 +191,19 @@ def test_device_with_only_ev_abs(self):

groups.refresh()
self.assertIsNotNone(groups.find(name="gamepad"))
self.assertIsNone(groups.find(name="qux"))
self.assertIsNotNone(groups.find(name="qux"))

def test_device_with_no_capabilities(self):
fixtures["/foo/bar"] = {
"name": "nulcap",
"phys": "abcd3",
"info": evdev.DeviceInfo(1, 2, 3, 4),
"capabilities": {},
}

# verify this test even works at all
fixtures["/foo/bar"].capabilities[EV_KEY] = [KEY_A]
groups.refresh()
self.assertIsNotNone(groups.find(name="qux"))
self.assertIsNotNone(groups.find(name="gamepad"))
self.assertIsNone(groups.find(name="nulcap"))

def test_duplicate_device(self):
fixtures["/dev/input/event100"] = {
Expand Down

0 comments on commit 7586ad9

Please sign in to comment.