compose: add xdg base directory support Before reading ~/.XCompose, try to read $XDG_CONFIG_HOME/XCompose (falling back to ~/.config/XCompose). This helps unclutter the home directory of users who want that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
diff --git a/src/compose/paths.c b/src/compose/paths.c
index 19eafa4..aab4507 100644
--- a/src/compose/paths.c
+++ b/src/compose/paths.c
@@ -150,6 +150,23 @@ get_xcomposefile_path(void)
}
char *
+get_xdg_xcompose_file_path(void)
+{
+ const char *xdg_config_home;
+ const char *home;
+
+ xdg_config_home = secure_getenv("XDG_CONFIG_HOME");
+ if (!xdg_config_home || xdg_config_home[0] != '/') {
+ home = secure_getenv("HOME");
+ if (!home)
+ return NULL;
+ return asprintf_safe("%s/.config/XCompose", home);
+ }
+
+ return asprintf_safe("%s/XCompose", xdg_config_home);
+}
+
+char *
get_home_xcompose_file_path(void)
{
const char *home;
diff --git a/src/compose/paths.h b/src/compose/paths.h
index 1d719af..53d7415 100644
--- a/src/compose/paths.h
+++ b/src/compose/paths.h
@@ -34,6 +34,9 @@ const char *
get_xcomposefile_path(void);
char *
+get_xdg_xcompose_file_path(void);
+
+char *
get_home_xcompose_file_path(void);
char *
diff --git a/src/compose/table.c b/src/compose/table.c
index bdfb907..1843c46 100644
--- a/src/compose/table.c
+++ b/src/compose/table.c
@@ -183,6 +183,15 @@ xkb_compose_table_new_from_locale(struct xkb_context *ctx,
goto found_path;
}
+ cpath = path = get_xdg_xcompose_file_path();
+ if (path) {
+ file = fopen(path, "rb");
+ if (file)
+ goto found_path;
+ }
+ free(path);
+ path = NULL;
+
cpath = path = get_home_xcompose_file_path();
if (path) {
file = fopen(path, "rb");
diff --git a/xkbcommon/xkbcommon-compose.h b/xkbcommon/xkbcommon-compose.h
index 1f158bd..f3c367a 100644
--- a/xkbcommon/xkbcommon-compose.h
+++ b/xkbcommon/xkbcommon-compose.h
@@ -204,8 +204,15 @@ enum xkb_compose_format {
* affected by the following environment variables:
*
* 1. `XCOMPOSEFILE` - see Compose(5).
- * 2. `HOME` - see Compose(5).
- * 3. `XLOCALEDIR` - if set, used as the base directory for the system's
+ * 2. `XDG_CONFIG_HOME` - before `$HOME/.XCompose` is checked,
+ * `$XDG_CONFIG_HOME/XCompose` is checked (with a fall back to
+ * `$HOME/.config/XCompose` if `XDG_CONFIG_HOME` is not defined).
+ * This is a libxkbcommon extension to the search procedure in
+ * Compose(5) (since libxkbcommon 0.11.0). Note that other
+ * implementations, such as libX11, might not find a Compose file in
+ * this path.
+ * 3. `HOME` - see Compose(5).
+ * 4. `XLOCALEDIR` - if set, used as the base directory for the system's
* X locale files, e.g. `/usr/share/X11/locale`, instead of the
* preconfigured directory.
*