compose: add xdg base directory support
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Thu, 16 Jul 2020 10:06:49 +0000 (12:06 +0200)
committerRan Benita <ran@unusedvar.com>
Thu, 23 Jul 2020 06:39:53 +0000 (09:39 +0300)
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.

src/compose/paths.c
src/compose/paths.h
src/compose/table.c
xkbcommon/xkbcommon-compose.h

index 19eafa4..aab4507 100644 (file)
@@ -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;
index 1d719af..53d7415 100644 (file)
@@ -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 *
index bdfb907..1843c46 100644 (file)
@@ -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");
index 1f158bd..f3c367a 100644 (file)
@@ -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.
  *