From: Ubuntu Desktop Team Date: Thu, 26 Jul 2018 16:19:06 +0100 Subject: keyboard: Use ibus sources from locale Restore the code that configure the input method according to the locale, upstream removed it because they use an intial setup but we don't Bug: https://bugs.launchpad.net/bugs/1719938 Forwarded: not-needed --- plugins/keyboard/gsd-keyboard-manager.c | 69 ++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/plugins/keyboard/gsd-keyboard-manager.c b/plugins/keyboard/gsd-keyboard-manager.c index 15247c7..7478033 100644 --- a/plugins/keyboard/gsd-keyboard-manager.c +++ b/plugins/keyboard/gsd-keyboard-manager.c @@ -131,6 +131,63 @@ schema_is_installed (const char *schema) return installed; } +static const gchar * +engine_from_locale (void) +{ +/* These are languages for which we automatically configure an IBus input + * method at installation. Each language in the list should: + * - have an entry in pkg_depends so the corresponding IM package is pulled, + * - be selectable in the installer, and + * - be represented by a set of language packs. + */ + const gchar *locale; + const gchar *locale_engine[][2] = { + { "as_IN", "m17n:as:phonetic" }, + { "bn_IN", "m17n:bn:inscript" }, + { "gu_IN", "m17n:gu:inscript" }, + { "hi_IN", "m17n:hi:inscript" }, + { "ja_JP", "mozc-jp" }, + { "kn_IN", "m17n:kn:kgp" }, + { "ko_KR", "hangul" }, + { "ml_IN", "m17n:ml:inscript" }, + { "mr_IN", "m17n:mr:inscript" }, + { "or_IN", "m17n:or:inscript" }, + { "pa_IN", "m17n:pa:inscript" }, + { "si_LK", "m17n:si:wijesekera" }, + { "ta_IN", "m17n:ta:tamil99" }, + { "te_IN", "m17n:te:inscript" }, + { "zh_CN", "libpinyin" }, + { "zh_HK", "cangjie3" }, + { "zh_TW", "chewing" }, + }; + gint i; + + locale = setlocale (LC_CTYPE, NULL); + if (!locale) + return NULL; + + for (i = 0; i < G_N_ELEMENTS (locale_engine); ++i) + if (g_str_has_prefix (locale, locale_engine[i][0])) + return locale_engine[i][1]; + + return NULL; +} + +static void +add_ibus_sources_from_locale (GSettings *settings) +{ + const gchar *locale_engine; + GVariantBuilder builder; + + locale_engine = engine_from_locale (); + if (!locale_engine) + return; + + init_builder_with_sources (&builder, settings); + g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_IBUS, locale_engine); + g_settings_set_value (settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); +} + static void apply_bell (GsdKeyboardManager *manager) { @@ -356,7 +413,7 @@ convert_libgnomekbd_layouts (GSettings *settings) g_object_unref (libgnomekbd_settings); } -static void +static gboolean maybe_convert_old_settings (GSettings *settings) { GVariant *sources; @@ -364,6 +421,7 @@ maybe_convert_old_settings (GSettings *settings) gchar *stamp_dir_path = NULL; gchar *stamp_file_path = NULL; GError *error = NULL; + gboolean is_first_run = FALSE; stamp_dir_path = g_build_filename (g_get_user_data_dir (), PACKAGE_NAME, NULL); if (g_mkdir_with_parents (stamp_dir_path, 0755)) { @@ -375,6 +433,8 @@ maybe_convert_old_settings (GSettings *settings) if (g_file_test (stamp_file_path, G_FILE_TEST_EXISTS)) goto out; + is_first_run = TRUE; + sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); if (g_variant_n_children (sources) < 1) { convert_libgnomekbd_layouts (settings); @@ -393,6 +453,8 @@ maybe_convert_old_settings (GSettings *settings) out: g_free (stamp_file_path); g_free (stamp_dir_path); + + return is_first_run; } static void @@ -407,7 +469,7 @@ maybe_create_initial_settings (GsdKeyboardManager *manager) if (g_getenv ("RUNNING_UNDER_GDM")) return; - maybe_convert_old_settings (settings); + gboolean is_first_run = maybe_convert_old_settings (settings); /* if we still don't have anything do some educated guesses */ sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); @@ -415,6 +477,9 @@ maybe_create_initial_settings (GsdKeyboardManager *manager) get_sources_from_xkb_config (manager); g_variant_unref (sources); + if (is_first_run) + add_ibus_sources_from_locale (settings); + options = g_settings_get_strv (settings, KEY_KEYBOARD_OPTIONS); if (g_strv_length (options) < 1) get_options_from_xkb_config (manager);