composetable: Support non-FHS paths for Compose tables
authorJan Tojnar <jtojnar@gmail.com>
Thu, 20 Oct 2022 10:59:17 +0000 (12:59 +0200)
committerJan Tojnar <jtojnar@gmail.com>
Thu, 20 Oct 2022 10:59:17 +0000 (12:59 +0200)
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
gtk/gtkcomposetable.h
gtk/gtkimcontextsimple.c

index c344d947da1f5e3ee3d61413853d02ad47f73cd5..870b07790714dd8666e440a0bd1a4f679c9ae304 100644 (file)
@@ -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] */
index 72c0ed8d152f57441cfd69f5588bd140bf0c8c90..bb7d8c615529b8ef24ae2604b1bf486e19fa1a38 100644 (file)
@@ -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__ */
index 8eede2b2436531a4bdedd012a0340598cd6d032b..bd492402adc3cfe32d0dfe6c31f01eea55d0fdab 100644 (file)
@@ -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;