Skip to content

Commit 0dc5640

Browse files
committed
Add libwacom_stylus_is_generic() to detect generic styli
Huion devices now support and ship with a multitude of styli that are support different features and buttons. We need to add more generic (read: unidentifiable) styli to libwacom but this may require callers to differentiate the UI depending on the stylus. This function allows detection of generic styli. Closes: #953
1 parent 56a0858 commit 0dc5640

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

data/wacom.stylus

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PairedStylusIds=0x0:0xffffe;
66
Buttons=2
77
Axes=Tilt;Pressure;Distance;
88
Type=General
9+
IsGenericStylus=true
910

1011
[0x0:0xffffe]
1112
Name=General Pen Eraser
@@ -15,13 +16,15 @@ EraserType=Invert
1516
Buttons=2
1617
Axes=Tilt;Pressure;Distance;
1718
Type=General
19+
IsGenericStylus=true
1820

1921
[0x0:0xffffd]
2022
Name=General Pen with no Eraser
2123
Group=generic-no-eraser
2224
Buttons=2
2325
Axes=Pressure;
2426
Type=General
27+
IsGenericStylus=true
2528

2629
[0x56a:0x1]
2730
# Lenovo ; VID_NONE | 0x0000 | BAT_SWAP

libwacom/libwacom-database.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,18 @@ libwacom_parse_stylus_keyfile(WacomDeviceDatabase *db,
571571
groups[i],
572572
error->message);
573573
g_clear_error(&error);
574+
stylus->is_generic_stylus = boolean_or_fallback(
575+
keyfile,
576+
groups[i],
577+
"IsGenericStylus",
578+
aliased ? aliased->is_generic_stylus : FALSE,
579+
error);
580+
if (error && error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
581+
g_warning("Stylus %s (%s) %s\n",
582+
stylus->name,
583+
groups[i],
584+
error->message);
585+
g_clear_error(&error);
574586
stylus->num_buttons =
575587
int_or_fallback(keyfile,
576588
groups[i],

libwacom/libwacom.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,12 @@ libwacom_stylus_is_eraser(const WacomStylus *stylus)
18131813
return libwacom_stylus_get_eraser_type(stylus) != WACOM_ERASER_NONE;
18141814
}
18151815

1816+
LIBWACOM_EXPORT int
1817+
libwacom_stylus_is_generic(const WacomStylus *stylus)
1818+
{
1819+
return stylus->is_generic_stylus;
1820+
}
1821+
18161822
LIBWACOM_EXPORT int
18171823
libwacom_stylus_has_lens(const WacomStylus *stylus)
18181824
{

libwacom/libwacom.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,24 @@ libwacom_stylus_has_eraser(const WacomStylus *stylus);
11051105
int
11061106
libwacom_stylus_is_eraser(const WacomStylus *stylus);
11071107

1108+
/**
1109+
* Check if the given stylus is a generic stylus.
1110+
*
1111+
* Generic styli are styli that cannot be uniquely identified by their
1112+
* tool ID. Instead a tool ID is assigned by libwacom but these styli
1113+
* cannot be differentiated at runtime. A device may support multiple
1114+
* generic styli but there is no information which stylus is in use
1115+
* at any time.
1116+
*
1117+
* @param stylus The stylus to query
1118+
* @return Non-zero if the stylus is a generic stylus, zero otherwise
1119+
*
1120+
* @since 2.18
1121+
* @ingroup styli
1122+
*/
1123+
int
1124+
libwacom_stylus_is_generic(const WacomStylus *stylus);
1125+
11081126
/**
11091127
* @param stylus The stylus to query
11101128
* @return Whether the stylus has a lens

libwacom/libwacom.sym

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ LIBWACOM_2.14 {
9898
LIBWACOM_2.15 {
9999
libwacom_get_button_modeswitch_mode;
100100
} LIBWACOM_2.14;
101+
102+
LIBWACOM_2.18 {
103+
libwacom_stylus_is_generic;
104+
} LIBWACOM_2.15;

libwacom/libwacomint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ struct _WacomStylus {
143143
char *group;
144144
int num_buttons;
145145
gboolean has_eraser;
146+
gboolean is_generic_stylus;
146147
GArray *paired_styli; /* [WacomStylus*, ...] */
147148
GArray *deprecated_paired_ids; /* [int, ...] */
148149
GArray *paired_stylus_ids; /* [WacomStylusId, ...], NULL once parsing is

test/test-stylus-validity.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ test_name(gconstpointer data)
256256
g_assert_nonnull(libwacom_stylus_get_name(stylus));
257257
}
258258

259+
static void
260+
test_generic(gconstpointer data)
261+
{
262+
const WacomStylus *stylus = data;
263+
264+
g_assert_true(libwacom_stylus_is_generic(stylus));
265+
}
266+
267+
static void
268+
test_not_generic(gconstpointer data)
269+
{
270+
const WacomStylus *stylus = data;
271+
272+
g_assert_false(libwacom_stylus_is_generic(stylus));
273+
}
274+
259275
static void
260276
test_buttons(gconstpointer data)
261277
{
@@ -352,14 +368,23 @@ static void
352368
setup_emr_tests(const WacomStylus *stylus)
353369
{
354370
switch (libwacom_stylus_get_id(stylus)) {
355-
case 0xffffd:
371+
case 0xfffff: /* GENERIC_PEN_WITH_ERASER */
372+
case 0xffffe: /* GENERIC_ERASER */
373+
add_test(stylus, test_generic);
374+
add_test(stylus, test_pressure);
375+
add_test(stylus, test_distance);
376+
add_test(stylus, test_tilt);
377+
break;
378+
case 0xffffd: /* GENERIC_PEN_NO_ERASER */
379+
add_test(stylus, test_generic);
356380
add_test(stylus, test_pressure);
357381
add_test(stylus, test_no_distance);
358382
add_test(stylus, test_no_tilt);
359383
break;
360384
case 0x006:
361385
case 0x096:
362386
case 0x097:
387+
add_test(stylus, test_not_generic);
363388
add_test(stylus, test_no_pressure);
364389
add_test(stylus, test_distance);
365390
add_test(stylus, test_no_tilt);
@@ -368,18 +393,21 @@ setup_emr_tests(const WacomStylus *stylus)
368393
case 0x017:
369394
case 0x094:
370395
case 0x806:
396+
add_test(stylus, test_not_generic);
371397
add_test(stylus, test_no_pressure);
372398
add_test(stylus, test_distance);
373399
add_test(stylus, test_tilt);
374400
break;
375401
case 0x021:
376402
case 0x8e2:
377403
case 0x862:
404+
add_test(stylus, test_not_generic);
378405
add_test(stylus, test_pressure);
379406
add_test(stylus, test_distance);
380407
add_test(stylus, test_no_tilt);
381408
break;
382409
default:
410+
add_test(stylus, test_not_generic);
383411
add_test(stylus, test_pressure);
384412
add_test(stylus, test_tilt);
385413
add_test(stylus, test_distance);

0 commit comments

Comments
 (0)