From b29d0e602bb2a989b80a211affbe89dd75a9e9d4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Oct 2024 11:28:13 +1000 Subject: [PATCH] database: support $XDG_CONFIG_HOME/libwacom as additional path This completes the traditional triplet of $XDG_CONFIG_HOME, /etc, and /usr/share for configuration files. Having custom .tablet files in $XDG_CONFIG_HOME makes it easier for immutable systems and also for backups that only back up the user home directory. --- libwacom/libwacom-database.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index bfa12ec4..4077a0df 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -1188,13 +1188,28 @@ libwacom_database_new_for_path (const char *datadir) LIBWACOM_EXPORT WacomDeviceDatabase * libwacom_database_new (void) { + WacomDeviceDatabase *db; + char *xdgdir = NULL; + char *xdg_config_home = g_strdup(g_getenv("XDG_CONFIG_HOME")); + + if (!xdg_config_home) + xdg_config_home = g_strdup_printf("%s/.config/", g_get_home_dir()); + + xdgdir = g_strdup_printf("%s/libwacom", xdg_config_home); + char *datadir[] = { + xdgdir, ETCDIR, DATADIR, NULL, }; - return database_new_for_paths(datadir); + db = database_new_for_paths(datadir); + + free(xdgdir); + free(xdg_config_home); + + return db; } LIBWACOM_EXPORT void