[gtk/wip/jtojnar/compose-consistent-system] composetable: Support non-FHS paths for Compose tables




commit 94a096ec4c3ec83cf1864fbe78dc0c9db0044074
Author: Jan Tojnar <jtojnar gmail com>
Date:   Thu Oct 20 12:59:17 2022 +0200

    composetable: Support non-FHS paths for Compose tables
    
    On platforms like NixOS, the libX11 installation prefix may differ from /usr/share,
    breaking the hardcoded placeholders. Let’s re-use the X11 path definition from imcontextsimple.

 gtk/gtkcomposetable.c    | 27 +++++++++++++++++++++++++--
 gtk/gtkcomposetable.h    |  2 ++
 gtk/gtkimcontextsimple.c | 16 +---------------
 3 files changed, 28 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkcomposetable.c b/gtk/gtkcomposetable.c
index c344d947da..870b077907 100644
--- a/gtk/gtkcomposetable.c
+++ b/gtk/gtkcomposetable.c
@@ -284,6 +284,20 @@ fail:
 static void parser_parse_file (GtkComposeParser *parser,
                                const char       *path);
 
+char *
+gtk_compose_table_get_x11_compose_file_dir (void)
+{
+  char * compose_file_dir;
+
+#if defined (X11_DATA_PREFIX)
+  compose_file_dir = g_strdup (X11_DATA_PREFIX "/share/X11/locale");
+#else
+  compose_file_dir = g_build_filename (_gtk_get_datadir (), "X11", "locale", NULL);
+#endif
+
+  return compose_file_dir;
+}
+
 /* Substitute %H, %L and %S */
 static char *
 handle_substitutions (const char *start,
@@ -305,6 +319,9 @@ handle_substitutions (const char *start,
         }
       else
         {
+          char *x11_compose_file_dir;
+          char *path;
+
           switch (p[1])
             {
             case 'H':
@@ -313,11 +330,17 @@ handle_substitutions (const char *start,
               break;
             case 'L':
               p++;
-              g_string_append_printf (s, "/usr/share/X11/locale/%s/Compose", locale_name);
+              x11_compose_file_dir = gtk_compose_table_get_x11_compose_file_dir ();
+              path = g_build_filename (x11_compose_file_dir, locale_name, "Compose", NULL);
+              g_string_append (s, path);
+              g_free (path);
+              g_free (x11_compose_file_dir);
               break;
             case 'S':
               p++;
-              g_string_append (s, "/usr/share/X11/locale");
+              x11_compose_file_dir = gtk_compose_table_get_x11_compose_file_dir ();
+              g_string_append (s, x11_compose_file_dir);
+              g_free (x11_compose_file_dir);
               break;
             default: ;
               /* do nothing, next iteration handles p[1] */
diff --git a/gtk/gtkcomposetable.h b/gtk/gtkcomposetable.h
index 72c0ed8d15..bb7d8c6155 100644
--- a/gtk/gtkcomposetable.h
+++ b/gtk/gtkcomposetable.h
@@ -93,6 +93,8 @@ guint32           gtk_compose_table_data_hash (const guint16 *data,
                                                int            max_seq_len,
                                                int            n_seqs);
 
+char *            gtk_compose_table_get_x11_compose_file_dir (void);
+
 G_END_DECLS
 
 #endif /* __GTK_COMPOSETABLE_H__ */
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index 8eede2b243..bd492402ad 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -180,20 +180,6 @@ gtk_im_context_simple_class_init (GtkIMContextSimpleClass *class)
   init_compose_table_async (NULL, NULL, NULL);
 }
 
-static char *
-get_x11_compose_file_dir (void)
-{
-  char * compose_file_dir;
-
-#if defined (X11_DATA_PREFIX)
-  compose_file_dir = g_strdup (X11_DATA_PREFIX "/share/X11/locale");
-#else
-  compose_file_dir = g_build_filename (_gtk_get_datadir (), "X11", "locale", NULL);
-#endif
-
-  return compose_file_dir;
-}
-
 static int
 gtk_compose_table_find (gconstpointer data1,
                         gconstpointer data2)
@@ -321,7 +307,7 @@ gtk_im_context_simple_init_compose_table (void)
         {
           if (g_ascii_strncasecmp (*lang, *sys_lang, strlen (*sys_lang)) == 0)
             {
-              char *x11_compose_file_dir = get_x11_compose_file_dir ();
+              char *x11_compose_file_dir = gtk_compose_table_get_x11_compose_file_dir ();
               path = g_build_filename (x11_compose_file_dir, *lang, "Compose", NULL);
               g_free (x11_compose_file_dir);
               break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]