From a68d0aeb6052ac492b929532e1bc4394014dd374 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Mon, 15 Feb 2021 18:18:36 +0100 Subject: [PATCH] drawing tablet improvements --- keymapper/getdevices.py | 7 ++++++- keymapper/utils.py | 8 ++++++-- tests/testcases/test_dev_utils.py | 2 ++ tests/testcases/test_getdevices.py | 7 ++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/keymapper/getdevices.py b/keymapper/getdevices.py index 2fb6ad31..413e216d 100644 --- a/keymapper/getdevices.py +++ b/keymapper/getdevices.py @@ -28,7 +28,7 @@ import time import asyncio import evdev -from evdev.ecodes import EV_KEY, EV_ABS, KEY_CAMERA +from evdev.ecodes import EV_KEY, EV_ABS, KEY_CAMERA, EV_REL from keymapper.logger import logger @@ -61,6 +61,11 @@ def is_gamepad(device): device : InputDevice """ capabilities = device.capabilities(absinfo=False) + + if EV_REL in capabilities: + # A mouse + return False + abs_capabilities = capabilities.get(EV_ABS) if abs_capabilities is not None: if evdev.ecodes.ABS_MT_TRACKING_ID in abs_capabilities: diff --git a/keymapper/utils.py b/keymapper/utils.py index f3152389..e9579ecb 100644 --- a/keymapper/utils.py +++ b/keymapper/utils.py @@ -46,7 +46,8 @@ STYLUS = [ (EV_ABS, evdev.ecodes.ABS_DISTANCE), (EV_ABS, evdev.ecodes.ABS_TILT_X), (EV_ABS, evdev.ecodes.ABS_TILT_Y), - (EV_KEY, evdev.ecodes.BTN_DIGI) + (EV_KEY, evdev.ecodes.BTN_DIGI), + (EV_ABS, evdev.ecodes.ABS_PRESSURE) ] @@ -135,7 +136,10 @@ def should_map_event_as_btn(event, mapping): return True if event.type == EV_KEY: - # usually all EV_KEY events are allright + # usually all EV_KEY events are allright, except for + if event.code == evdev.ecodes.BTN_TOUCH: + return False + return True return False diff --git a/tests/testcases/test_dev_utils.py b/tests/testcases/test_dev_utils.py index 29d6b5c3..0993d139 100644 --- a/tests/testcases/test_dev_utils.py +++ b/tests/testcases/test_dev_utils.py @@ -82,6 +82,7 @@ class TestDevUtils(unittest.TestCase): self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_MT_SLOT, 1))) self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_MT_TOOL_Y, 1))) self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_MT_POSITION_X, 1))) + self.assertFalse(do(new_event(EV_KEY, ecodes.BTN_TOUCH, 1))) """stylus movements""" @@ -89,6 +90,7 @@ class TestDevUtils(unittest.TestCase): self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_TILT_X, 1))) self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_TILT_Y, 1))) self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_DISTANCE, 1))) + self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_PRESSURE, 1))) """joysticks""" diff --git a/tests/testcases/test_getdevices.py b/tests/testcases/test_getdevices.py index 4565eb77..08339874 100644 --- a/tests/testcases/test_getdevices.py +++ b/tests/testcases/test_getdevices.py @@ -150,6 +150,7 @@ class TestGetDevices(unittest.TestCase): # properly detects if the device is a gamepad EV_ABS = evdev.ecodes.EV_ABS EV_KEY = evdev.ecodes.EV_KEY + EV_REL = evdev.ecodes.EV_REL class FakeDevice: def __init__(self, capabilities): @@ -173,7 +174,7 @@ class TestGetDevices(unittest.TestCase): EV_ABS: [evdev.ecodes.ABS_HAT2X] }))) self.assertFalse(is_gamepad(FakeDevice({ - EV_KEY: [evdev.ecodes.ABS_X] # intentionally ABS_X (0) on EV_KEY + EV_KEY: [0] }))) self.assertFalse(is_gamepad(FakeDevice({ EV_ABS: [evdev.ecodes.ABS_Y], @@ -183,6 +184,10 @@ class TestGetDevices(unittest.TestCase): EV_ABS: [evdev.ecodes.ABS_X], EV_KEY: [evdev.ecodes.BTN_STYLUS] }))) + self.assertFalse(is_gamepad(FakeDevice({ + EV_ABS: [evdev.ecodes.ABS_X], + EV_REL: [evdev.ecodes.REL_X] + }))) if __name__ == "__main__":