From 94a096ec4c3ec83cf1864fbe78dc0c9db0044074 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Thu, 20 Oct 2022 12:59:17 +0200 Subject: [PATCH 1/2] composetable: Support non-FHS paths for Compose tables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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; From cf701d5db44ed7c1a532b1106816da7ab1078fa1 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Thu, 20 Oct 2022 16:19:13 +0200 Subject: [PATCH 2/2] imcontextsimple: Document that Compose file support is incomplete And that `include "%L"` does something different as introduced in https://gitlab.gnome.org/GNOME/gtk/-/commit/3b4b1c68781aad61fc6b91c9dff75b5790b4d8e4 Note that user can still use `include "/.%L"` as a workaround. --- gtk/gtkimcontextsimple.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index bd492402ad..c9ff583614 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -46,8 +46,9 @@ * `GtkIMContextSimple` reads compose sequences from the first of the * following files that is found: ~/.config/gtk-4.0/Compose, ~/.XCompose, * /usr/share/X11/locale/$locale/Compose (for locales that have a nontrivial - * Compose file). The syntax of these files is described in the Compose(5) - * manual page. + * Compose file). A subset of the file syntax described in the Compose(5) + * manual page is supported. Additionally, `include "%L"` loads GTK’s built-in + * table of compose sequences rather than the locale-specific one from X11. * * If none of these files is found, `GtkIMContextSimple` uses a built-in table * of compose sequences that is derived from the X11 Compose files.