Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special-case the generic pens for libwacom_get_supported_styli #822

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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