Skip to content

Commit

Permalink
Don't set up styli for devices without a stylus
Browse files Browse the repository at this point in the history
If a device explicitly lists Stylus=false don't force it
to the generic styli.
  • Loading branch information
whot committed Nov 7, 2024
1 parent 06d5412 commit f400fbc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
14 changes: 10 additions & 4 deletions libwacom/libwacom-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ libwacom_parse_styli_list(WacomDeviceDatabase *db, WacomDevice *device,
guint i;

array = g_array_new (FALSE, FALSE, sizeof(WacomStylus*));
for (i = 0; ids[i]; i++) {
for (i = 0; ids && ids[i]; i++) {
const char *str = ids[i];

if (g_str_has_prefix(str, "0x")) {
Expand Down Expand Up @@ -949,9 +949,15 @@ libwacom_parse_tablet_keyfile(WacomDeviceDatabase *db,

string_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, "Styli", NULL, NULL);
if (!string_list) {
string_list = g_new0(char*, 3);
string_list[0] = g_strdup_printf("0x0:0x%x", WACOM_ERASER_FALLBACK_ID);
string_list[1] = g_strdup_printf("0x0:0x%x", WACOM_STYLUS_FALLBACK_ID);
GError *error = NULL;
if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "Stylus", &error) ||
g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
string_list = g_new0(char*, 3);
string_list[0] = g_strdup_printf("0x0:0x%x", WACOM_ERASER_FALLBACK_ID);
string_list[1] = g_strdup_printf("0x0:0x%x", WACOM_STYLUS_FALLBACK_ID);
}
if (error)
g_error_free(error);
}
libwacom_parse_styli_list(db, device, string_list);
g_strfreev (string_list);
Expand Down
25 changes: 25 additions & 0 deletions test/test-tablet-validity.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,29 @@ test_styli(gconstpointer data)

}

static void
test_no_styli(gconstpointer data)
{
WacomDevice *device = (WacomDevice*)data;
int nstylus_ids, nstyli;
const WacomStylus **styli;
const int *stylus_ids;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
stylus_ids = libwacom_get_supported_styli(device, &nstylus_ids);
#pragma GCC diagnostic pop
styli = libwacom_get_styli(device, &nstyli);

g_assert_cmpint(nstyli, ==, 0);
g_assert_cmpint(nstylus_ids, ==, 0);
g_assert_nonnull(styli);
g_assert_null(stylus_ids);
g_assert_null(styli[0]); /* NULL-terminated list */
g_free(styli);

}

static void
test_realstylus(gconstpointer data)
{
Expand Down Expand Up @@ -421,6 +444,8 @@ static void setup_tests(WacomDevice *device)
/* FIXME: we force the generic pen for these, should add a test */
if (libwacom_has_stylus(device))
add_test(device, test_styli);
else
add_test(device, test_no_styli);

switch (cls) {
case WCLASS_INTUOS:
Expand Down

0 comments on commit f400fbc

Please sign in to comment.