Skip to content
Open
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
3 changes: 3 additions & 0 deletions data/wacom.stylus
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PairedStylusIds=0x0:0xffffe;
Buttons=2
Axes=Tilt;Pressure;Distance;
Type=General
IsGenericStylus=true

[0x0:0xffffe]
Name=General Pen Eraser
Expand All @@ -15,13 +16,15 @@ EraserType=Invert
Buttons=2
Axes=Tilt;Pressure;Distance;
Type=General
IsGenericStylus=true

[0x0:0xffffd]
Name=General Pen with no Eraser
Group=generic-no-eraser
Buttons=2
Axes=Pressure;
Type=General
IsGenericStylus=true

[0x56a:0x1]
# Lenovo ; VID_NONE | 0x0000 | BAT_SWAP
Expand Down
12 changes: 12 additions & 0 deletions libwacom/libwacom-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,18 @@ libwacom_parse_stylus_keyfile(WacomDeviceDatabase *db,
groups[i],
error->message);
g_clear_error(&error);
stylus->is_generic_stylus = boolean_or_fallback(
keyfile,
groups[i],
"IsGenericStylus",
aliased ? aliased->is_generic_stylus : FALSE,
error);
if (error && error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
g_warning("Stylus %s (%s) %s\n",
stylus->name,
groups[i],
error->message);
g_clear_error(&error);
stylus->num_buttons =
int_or_fallback(keyfile,
groups[i],
Expand Down
6 changes: 6 additions & 0 deletions libwacom/libwacom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,12 @@ libwacom_stylus_is_eraser(const WacomStylus *stylus)
return libwacom_stylus_get_eraser_type(stylus) != WACOM_ERASER_NONE;
}

LIBWACOM_EXPORT int
libwacom_stylus_is_generic(const WacomStylus *stylus)
{
return stylus->is_generic_stylus;
}

LIBWACOM_EXPORT int
libwacom_stylus_has_lens(const WacomStylus *stylus)
{
Expand Down
18 changes: 18 additions & 0 deletions libwacom/libwacom.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,24 @@ libwacom_stylus_has_eraser(const WacomStylus *stylus);
int
libwacom_stylus_is_eraser(const WacomStylus *stylus);

/**
* Check if the given stylus is a generic stylus.
*
* Generic styli are styli that cannot be uniquely identified by their
* tool ID. Instead a tool ID is assigned by libwacom but these styli
* cannot be differentiated at runtime. A device may support multiple
* generic styli but there is no information which stylus is in use
* at any time.
*
* @param stylus The stylus to query
* @return Non-zero if the stylus is a generic stylus, zero otherwise
*
* @since 2.18
* @ingroup styli
*/
int
libwacom_stylus_is_generic(const WacomStylus *stylus);

/**
* @param stylus The stylus to query
* @return Whether the stylus has a lens
Expand Down
4 changes: 4 additions & 0 deletions libwacom/libwacom.sym
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ LIBWACOM_2.14 {
LIBWACOM_2.15 {
libwacom_get_button_modeswitch_mode;
} LIBWACOM_2.14;

LIBWACOM_2.18 {
libwacom_stylus_is_generic;
} LIBWACOM_2.15;
1 change: 1 addition & 0 deletions libwacom/libwacomint.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct _WacomStylus {
char *group;
int num_buttons;
gboolean has_eraser;
gboolean is_generic_stylus;
GArray *paired_styli; /* [WacomStylus*, ...] */
GArray *deprecated_paired_ids; /* [int, ...] */
GArray *paired_stylus_ids; /* [WacomStylusId, ...], NULL once parsing is
Expand Down
30 changes: 29 additions & 1 deletion test/test-stylus-validity.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ test_name(gconstpointer data)
g_assert_nonnull(libwacom_stylus_get_name(stylus));
}

static void
test_generic(gconstpointer data)
{
const WacomStylus *stylus = data;

g_assert_true(libwacom_stylus_is_generic(stylus));
}

static void
test_not_generic(gconstpointer data)
{
const WacomStylus *stylus = data;

g_assert_false(libwacom_stylus_is_generic(stylus));
}

static void
test_buttons(gconstpointer data)
{
Expand Down Expand Up @@ -352,14 +368,23 @@ static void
setup_emr_tests(const WacomStylus *stylus)
{
switch (libwacom_stylus_get_id(stylus)) {
case 0xffffd:
case 0xfffff: /* GENERIC_PEN_WITH_ERASER */
case 0xffffe: /* GENERIC_ERASER */
add_test(stylus, test_generic);
add_test(stylus, test_pressure);
add_test(stylus, test_distance);
add_test(stylus, test_tilt);
break;
case 0xffffd: /* GENERIC_PEN_NO_ERASER */
add_test(stylus, test_generic);
add_test(stylus, test_pressure);
add_test(stylus, test_no_distance);
add_test(stylus, test_no_tilt);
break;
case 0x006:
case 0x096:
case 0x097:
add_test(stylus, test_not_generic);
add_test(stylus, test_no_pressure);
add_test(stylus, test_distance);
add_test(stylus, test_no_tilt);
Expand All @@ -368,18 +393,21 @@ setup_emr_tests(const WacomStylus *stylus)
case 0x017:
case 0x094:
case 0x806:
add_test(stylus, test_not_generic);
add_test(stylus, test_no_pressure);
add_test(stylus, test_distance);
add_test(stylus, test_tilt);
break;
case 0x021:
case 0x8e2:
case 0x862:
add_test(stylus, test_not_generic);
add_test(stylus, test_pressure);
add_test(stylus, test_distance);
add_test(stylus, test_no_tilt);
break;
default:
add_test(stylus, test_not_generic);
add_test(stylus, test_pressure);
add_test(stylus, test_tilt);
add_test(stylus, test_distance);
Expand Down