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

Don't set up styli for devices without a stylus #826

Merged
merged 3 commits into from
Nov 7, 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
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
26 changes: 25 additions & 1 deletion 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 @@ -406,7 +429,6 @@ static void setup_tests(WacomDevice *device)
add_test(device, test_matches);
add_test(device, test_matches_vidpid);
add_test(device, test_buttons);
add_test(device, test_styli);
add_test(device, test_rings);
add_test(device, test_strips);
add_test(device, test_dials);
Expand All @@ -421,6 +443,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
2 changes: 1 addition & 1 deletion tools/list-local-devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ tablet_print_yaml(gpointer data, gpointer user_data)
g_list_foreach(d->nodes, print_devnode, NULL);

styli = libwacom_get_styli(d->dev, &nstyli);
printf(" styli:%s\n", nstyli > 0 ? "" : "[]");
printf(" styli:%s\n", nstyli > 0 ? "" : " []");
for (int i = 0; i < nstyli; i++) {
const WacomStylus *stylus = styli[i];
const char *type = "invalid";
Expand Down