Skip to content

Commit

Permalink
Special-case the generic pens for libwacom_get_supported_styli
Browse files Browse the repository at this point in the history
The three generic pens have a vendor-id of 0 so let's special case those
for the now-deprecated API.
  • Loading branch information
whot committed Nov 5, 2024
1 parent dce3c18 commit 19b3b92
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
8 changes: 8 additions & 0 deletions libwacom/libwacom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions libwacom/libwacomint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 7 additions & 2 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
28 changes: 28 additions & 0 deletions test/test_libwacom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from configparser import ConfigParser
from dataclasses import dataclass, field

import ctypes
import logging
import pytest

Expand All @@ -15,6 +16,7 @@
WacomDevice,
WacomEraserType,
WacomStatusLed,
WacomStylus,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -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",
[
Expand Down

0 comments on commit 19b3b92

Please sign in to comment.