From d01ea18dc3a9acc98fc133ddb53ddc838e4e18f9 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 12 Nov 2015 20:20:36 +0800 Subject: gtkimcontextsimple.c: Use X11_DATA_PREFIX only on X11/Wayland Only use the hard-coded build-time path given by X11_PREFIX on X11 and Wayland where a X11 package is normally available. On other platforms, get the datadir of the running system and mimic the behavior by constructing the path dynamically. This avoids hardcoding the path for searching for compose tables where we want to have relocatability. This fixes the build on Windows/MSVC as well, where we don't normally have any X11 packages available. https://bugzilla.gnome.org/show_bug.cgi?id=757984 --- gtk/gtkimcontextsimple.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'gtk/gtkimcontextsimple.c') diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c index 82c5221e64..41199f628a 100644 --- a/gtk/gtkimcontextsimple.c +++ b/gtk/gtkimcontextsimple.c @@ -61,9 +61,6 @@ * G WITH CEDILLA, i.e. ģ. */ - -#define X11_DATADIR X11_DATA_PREFIX "/share/X11/locale" - struct _GtkIMContextSimplePrivate { guint16 compose_buffer[GTK_MAX_COMPOSE_LEN + 1]; @@ -133,6 +130,23 @@ gtk_im_context_simple_class_init (GtkIMContextSimpleClass *class) gobject_class->finalize = gtk_im_context_simple_finalize; } +static gchar* +get_x11_compose_file_dir (void) +{ + gchar* compose_file_dir; + gchar* datadir = NULL; + +#if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WAYLAND) + compose_file_dir = g_strdup (X11_DATA_PREFIX "/share/X11/locale"); +#else + datadir = g_strdup (_gtk_get_datadir ()); + compose_file_dir = g_build_filename (datadir, "X11", "locale", NULL); + g_free (datadir); +#endif + + return compose_file_dir; +} + static void gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) { @@ -143,6 +157,7 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) gchar **lang = NULL; gchar * const sys_langs[] = { "el_gr", "fi_fi", "pt_br", NULL }; gchar * const *sys_lang = NULL; + gchar *x11_compose_file_dir = get_x11_compose_file_dir (); path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "Compose", NULL); if (g_file_test (path, G_FILE_TEST_EXISTS)) @@ -189,7 +204,7 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) { if (g_ascii_strncasecmp (*lang, *sys_lang, strlen (*sys_lang)) == 0) { - path = g_build_filename (X11_DATADIR, *lang, "Compose", NULL); + path = g_build_filename (x11_compose_file_dir, *lang, "Compose", NULL); break; } } @@ -203,6 +218,7 @@ gtk_im_context_simple_init_compose_table (GtkIMContextSimple *im_context_simple) path = NULL; } + g_free (x11_compose_file_dir); g_strfreev (langs); if (path != NULL) -- cgit v1.2.1