From f400fbcce2249bd8c48630a5cae1061175bffdfa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 7 Nov 2024 15:08:39 +1000 Subject: [PATCH] Don't set up styli for devices without a stylus If a device explicitly lists Stylus=false don't force it to the generic styli. --- libwacom/libwacom-database.c | 14 ++++++++++---- test/test-tablet-validity.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index dee03252..d93e134d 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -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")) { @@ -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); diff --git a/test/test-tablet-validity.c b/test/test-tablet-validity.c index a277c953..03742d77 100644 --- a/test/test-tablet-validity.c +++ b/test/test-tablet-validity.c @@ -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) { @@ -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: