From 3802c89e6784b958a9c3c6eeb6e97a093b1cd36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Correa=20G=C3=B3mez?= Date: Sun, 6 Jun 2021 19:53:34 +0200 Subject: [PATCH] feedback-manager: Search for default theme under XDG_CONFIG_HOME first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This would allow users to create their own feedback profiles without editing system files or using root privileges Signed-off-by: Pablo Correa Gómez --- README.md | 5 ++++- src/fbd-feedback-manager.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b8a12c..dad8d90 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,10 @@ You can add your own themes in one of two ways: 1. By exporting an environment variable `FEEDBACK_THEME` with a path to a valid theme file (not recommended, use for testing only), or -2. By adding your theme file to one of the folders in the `XDG_DATA_DIRS` +2. By creating a theme file under `$XDG_CONFIG_HOME/feedbackd/themes/default.json`. + If `XDG_CONFIG_HOME` environment variable is not set or empty, it will + default to `$HOME/.config`, or +3. By adding your theme file to one of the folders in the `XDG_DATA_DIRS` environment variable, appended with `feedbackd/themes/`. This folder isn't created automatically, so you have to create it yourself. Here's an example: ```bash diff --git a/src/fbd-feedback-manager.c b/src/fbd-feedback-manager.c index c592f86..97052c5 100644 --- a/src/fbd-feedback-manager.c +++ b/src/fbd-feedback-manager.c @@ -437,9 +437,18 @@ find_themefile (void) const gchar *comp; g_autoptr (GError) err = NULL; + g_autofree gchar *user_config_path = NULL; gchar **xdg_data_dirs = (gchar **) g_get_system_data_dirs (); g_autofree gchar *compatibles = NULL; + // First look for a default file under $XDG_DATA_HOME + user_config_path = g_build_filename (g_get_user_config_dir (), "feedbackd", + "themes", "default.json", NULL); + if (g_file_test (user_config_path, (G_FILE_TEST_EXISTS))) { + g_debug ("Found user themefile at: %s", user_config_path); + return g_steal_pointer (&user_config_path); + } + // Try to read the device name if (g_file_test (DEVICE_TREE_PATH, (G_FILE_TEST_EXISTS))) { g_debug ("Found device tree device compatible at %s", DEVICE_TREE_PATH); @@ -465,7 +474,7 @@ find_themefile (void) // Check if file exist if (g_file_test (config_path, (G_FILE_TEST_EXISTS))) { g_debug ("Found themefile for this device at: %s", config_path); - return g_strdup (config_path); + return g_steal_pointer (&config_path); } }