drawing tablet improvements

This commit is contained in:
sezanzeb 2021-02-15 18:18:36 +01:00 committed by sezanzeb
parent 58e3526a6e
commit a68d0aeb60
4 changed files with 20 additions and 4 deletions

View File

@ -28,7 +28,7 @@ import time
import asyncio import asyncio
import evdev 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 from keymapper.logger import logger
@ -61,6 +61,11 @@ def is_gamepad(device):
device : InputDevice device : InputDevice
""" """
capabilities = device.capabilities(absinfo=False) capabilities = device.capabilities(absinfo=False)
if EV_REL in capabilities:
# A mouse
return False
abs_capabilities = capabilities.get(EV_ABS) abs_capabilities = capabilities.get(EV_ABS)
if abs_capabilities is not None: if abs_capabilities is not None:
if evdev.ecodes.ABS_MT_TRACKING_ID in abs_capabilities: if evdev.ecodes.ABS_MT_TRACKING_ID in abs_capabilities:

View File

@ -46,7 +46,8 @@ STYLUS = [
(EV_ABS, evdev.ecodes.ABS_DISTANCE), (EV_ABS, evdev.ecodes.ABS_DISTANCE),
(EV_ABS, evdev.ecodes.ABS_TILT_X), (EV_ABS, evdev.ecodes.ABS_TILT_X),
(EV_ABS, evdev.ecodes.ABS_TILT_Y), (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 return True
if event.type == EV_KEY: 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 True
return False return False

View File

@ -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_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_TOOL_Y, 1)))
self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_MT_POSITION_X, 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""" """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_X, 1)))
self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_TILT_Y, 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_DISTANCE, 1)))
self.assertFalse(do(new_event(EV_ABS, ecodes.ABS_PRESSURE, 1)))
"""joysticks""" """joysticks"""

View File

@ -150,6 +150,7 @@ class TestGetDevices(unittest.TestCase):
# properly detects if the device is a gamepad # properly detects if the device is a gamepad
EV_ABS = evdev.ecodes.EV_ABS EV_ABS = evdev.ecodes.EV_ABS
EV_KEY = evdev.ecodes.EV_KEY EV_KEY = evdev.ecodes.EV_KEY
EV_REL = evdev.ecodes.EV_REL
class FakeDevice: class FakeDevice:
def __init__(self, capabilities): def __init__(self, capabilities):
@ -173,7 +174,7 @@ class TestGetDevices(unittest.TestCase):
EV_ABS: [evdev.ecodes.ABS_HAT2X] EV_ABS: [evdev.ecodes.ABS_HAT2X]
}))) })))
self.assertFalse(is_gamepad(FakeDevice({ 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({ self.assertFalse(is_gamepad(FakeDevice({
EV_ABS: [evdev.ecodes.ABS_Y], EV_ABS: [evdev.ecodes.ABS_Y],
@ -183,6 +184,10 @@ class TestGetDevices(unittest.TestCase):
EV_ABS: [evdev.ecodes.ABS_X], EV_ABS: [evdev.ecodes.ABS_X],
EV_KEY: [evdev.ecodes.BTN_STYLUS] 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__": if __name__ == "__main__":