From 12d16a3070c2ac9de6a0d27addb0c0eed1595105 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 24 Oct 2024 08:42:42 +1000 Subject: [PATCH 1/3] doc: document libwacom_new_for_path() better --- libwacom/libwacom.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h index f07ba5f75..8797e8847 100644 --- a/libwacom/libwacom.h +++ b/libwacom/libwacom.h @@ -354,10 +354,14 @@ WacomDeviceDatabase* libwacom_database_new(void); /** * Loads the Tablet and Stylus databases, to be used - * in libwacom_new_*() functions, from the prefix - * path passes. This is only useful for diagnostics + * in libwacom_new_*() functions, from the datadir + * given in the argument. This is only useful for diagnostics * applications. * + * The datadir must contain the libwacom .tablet files and optionally + * a layouts/ subdirectory for the svg files if any of the .tablet + * files references an svg. + * * @return A new database or NULL on error. * * @ingroup context From 570f4ce0a9e0af3788ff79845fd7086658dd9308 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Oct 2024 11:06:39 +1000 Subject: [PATCH 2/3] Make libwacom_new_for_paths take a null-terminated array Since we're only running through it anyway there's no need to have a size argument. --- libwacom/libwacom-database.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index e107888a7..152b554a6 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -1132,10 +1132,9 @@ stylus_compare(WacomStylusId *a, WacomStylusId *b) } static WacomDeviceDatabase * -database_new_for_paths (size_t npaths, const char **datadirs) +database_new_for_paths (const char **datadirs) { WacomDeviceDatabase *db; - size_t n; const char **datadir; db = g_new0 (WacomDeviceDatabase, 1); @@ -1148,12 +1147,12 @@ database_new_for_paths (size_t npaths, const char **datadirs) (GDestroyNotify) g_free, (GDestroyNotify) stylus_destroy); - for (datadir = datadirs, n = npaths; n--; datadir++) { + for (datadir = datadirs; *datadir; datadir++) { if (!load_stylus_files(db, *datadir)) goto error; } - for (datadir = datadirs, n = npaths; n--; datadir++) { + for (datadir = datadirs; *datadir; datadir++) { if (!load_tablet_files(db, *datadir)) goto error; } @@ -1175,7 +1174,11 @@ database_new_for_paths (size_t npaths, const char **datadirs) LIBWACOM_EXPORT WacomDeviceDatabase * libwacom_database_new_for_path (const char *datadir) { - return database_new_for_paths(1, &datadir); + const char *datadirs[] = { + datadir, + NULL, + }; + return database_new_for_paths(datadirs); } LIBWACOM_EXPORT WacomDeviceDatabase * @@ -1184,9 +1187,10 @@ libwacom_database_new (void) const char *datadir[] = { ETCDIR, DATADIR, + NULL, }; - return database_new_for_paths (2, datadir); + return database_new_for_paths(datadir); } LIBWACOM_EXPORT void From bc95f8d5ccca797edf2afa523ee57b02b5223a59 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Oct 2024 11:16:18 +1000 Subject: [PATCH 3/3] database: allow for multiple entries in a database path Split the given database path by colon, same as PATH behavior, to allow callers to pass multiple database paths. --- libwacom/libwacom-database.c | 20 ++++++++++++-------- libwacom/libwacom.h | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index 152b554a6..bfa12ec4c 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -1132,10 +1132,10 @@ stylus_compare(WacomStylusId *a, WacomStylusId *b) } static WacomDeviceDatabase * -database_new_for_paths (const char **datadirs) +database_new_for_paths (char * const *datadirs) { WacomDeviceDatabase *db; - const char **datadir; + char * const *datadir; db = g_new0 (WacomDeviceDatabase, 1); db->device_ht = g_hash_table_new_full (g_str_hash, @@ -1174,17 +1174,21 @@ database_new_for_paths (const char **datadirs) LIBWACOM_EXPORT WacomDeviceDatabase * libwacom_database_new_for_path (const char *datadir) { - const char *datadirs[] = { - datadir, - NULL, - }; - return database_new_for_paths(datadirs); + WacomDeviceDatabase *db; + char **paths; + + paths = g_strsplit(datadir, ":", 0); + db = database_new_for_paths(paths); + + g_strfreev(paths); + + return db; } LIBWACOM_EXPORT WacomDeviceDatabase * libwacom_database_new (void) { - const char *datadir[] = { + char *datadir[] = { ETCDIR, DATADIR, NULL, diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h index 8797e8847..2882fcff3 100644 --- a/libwacom/libwacom.h +++ b/libwacom/libwacom.h @@ -362,6 +362,8 @@ WacomDeviceDatabase* libwacom_database_new(void); * a layouts/ subdirectory for the svg files if any of the .tablet * files references an svg. * + * datadir may be a colon-separated list of directories. + * * @return A new database or NULL on error. * * @ingroup context