From 8c5569ac49233e662a0551e7b4f4fadc9e0b6ad0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 4 Nov 2024 14:34:44 +1000 Subject: [PATCH] Special-case the generic pens for libwacom_get_supported_styli The three generic pens have a vendor-id of 0 so let's special case those for the now-deprecated API. --- libwacom/libwacom.c | 8 ++++++++ libwacom/libwacomint.h | 6 ++++++ test/__init__.py | 9 +++++++-- test/test_libwacom.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c index 61acaef9..ae95295f 100644 --- a/libwacom/libwacom.c +++ b/libwacom/libwacom.c @@ -1600,6 +1600,14 @@ libwacom_stylus_get_for_id (const WacomDeviceDatabase *db, int tool_id) .tool_id = tool_id, }; + switch (tool_id) { + case GENERIC_PEN_WITH_ERASER: + case GENERIC_ERASER: + case GENERIC_PEN_NO_ERASER: + id.vid = 0; + break; + + } return libwacom_stylus_get_for_stylus_id (db, &id); } diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h index 7178777d..a2d9318c 100644 --- a/libwacom/libwacomint.h +++ b/libwacom/libwacomint.h @@ -42,6 +42,12 @@ #define WACOM_DEVICE_INTEGRATED_UNSET (WACOM_DEVICE_INTEGRATED_NONE - 1U) #define WACOM_VENDOR_ID 0x056a +enum GenericStylus { + GENERIC_PEN_WITH_ERASER = 0xfffff, + GENERIC_ERASER = 0xffffe, + GENERIC_PEN_NO_ERASER = 0xffffd, +}; + enum WacomFeature { FEATURE_STYLUS = (1 << 0), FEATURE_TOUCH = (1 << 1), diff --git a/test/__init__.py b/test/__init__.py index 2f8bcad1..45c4f5f2 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -196,8 +196,8 @@ def instance(cls): _Api(name="libwacom_get_num_keys", args=(c_void_p,), return_type=c_int), _Api( name="libwacom_get_supported_styli", - args=(c_void_p, c_void_p), - return_type=c_void_p, + args=(c_void_p, ctypes.POINTER(c_int)), + return_type=ctypes.POINTER(c_int), ), _Api( name="libwacom_get_styli", @@ -558,6 +558,11 @@ class WacomEraserType(enum.IntEnum): class WacomStylus: + class Generic(enum.IntEnum): + PEN_WITH_ERASER = 0xFFFFF + ERASER = 0xFFFFE + PEN_NO_ERASER = 0xFFFFD + def __init__(self, stylus): self.stylus = stylus lib = LibWacom.instance() diff --git a/test/test_libwacom.py b/test/test_libwacom.py index e7f9a7b5..a6bf3aa2 100644 --- a/test/test_libwacom.py +++ b/test/test_libwacom.py @@ -5,6 +5,7 @@ from configparser import ConfigParser from dataclasses import dataclass, field +import ctypes import logging import pytest @@ -15,6 +16,7 @@ WacomDevice, WacomEraserType, WacomStatusLed, + WacomStylus, ) logger = logging.getLogger(__name__) @@ -281,6 +283,32 @@ def test_isdv4_4800(db): assert device.num_buttons == 0 +@pytest.mark.parametrize( + "usbid,expected", + [ + [(0x256C, 0x0067), [WacomStylus.Generic.PEN_NO_ERASER]], + [ + (0x04F3, 0x264C), + [ + WacomStylus.Generic.PEN_WITH_ERASER, + WacomStylus.Generic.ERASER, + WacomStylus.Generic.PEN_NO_ERASER, + ], + ], + ], +) +def test_generic_pens(db, usbid, expected): + # Inspiroy 2 has a generic-pen-no-eraser + device = db.new_from_usbid(*usbid) + assert device is not None + + nstyli = ctypes.c_int() + styli = device.get_supported_styli(ctypes.byref(nstyli)) + s = [WacomStylus.Generic(id) for id in styli[: nstyli.value]] + + assert sorted(s) == sorted(expected) + + @pytest.mark.parametrize( "bus,vid,pid", [