From fe26aecaf10b641a24a07b0348db6f4d7f1a89f7 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sat, 26 Aug 2023 10:17:22 -0400 Subject: [PATCH] Improve APIs for finding default input sources --- ...nctions-for-getting-default-input-so.patch | 89 ++++++++++++++----- 1 file changed, 66 insertions(+), 23 deletions(-) diff --git a/0004-languages-Add-functions-for-getting-default-input-so.patch b/0004-languages-Add-functions-for-getting-default-input-so.patch index 23bfbd1..dd2fa45 100644 --- a/0004-languages-Add-functions-for-getting-default-input-so.patch +++ b/0004-languages-Add-functions-for-getting-default-input-so.patch @@ -1,4 +1,4 @@ -From 38c1d2a3c70ba3785cfb22b0baf1f5d97b63b90a Mon Sep 17 00:00:00 2001 +From 9f93dd73c5ed57bb2fb1b572c9282d499d1c7fd7 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 24 Aug 2023 19:58:17 -0400 Subject: [PATCH 4/4] languages: Add functions for getting default input @@ -17,15 +17,15 @@ gnome_get_default_input_sources_finish Note, these functions don't provide change notification, so there is still some redundancy needed by callers. --- - libgnome-desktop/gnome-languages.c | 234 +++++++++++++++++++++++++++++ - libgnome-desktop/gnome-languages.h | 9 ++ - 2 files changed, 243 insertions(+) + libgnome-desktop/gnome-languages.c | 256 +++++++++++++++++++++++++++++ + libgnome-desktop/gnome-languages.h | 10 ++ + 2 files changed, 266 insertions(+) diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c -index cc9bd005..65ea2845 100644 +index cc9bd005..072e1b07 100644 --- a/libgnome-desktop/gnome-languages.c +++ b/libgnome-desktop/gnome-languages.c -@@ -17,60 +17,62 @@ +@@ -17,80 +17,87 @@ * along with this program; if not, see . * * Written by : William Jon McCann @@ -78,6 +78,11 @@ index cc9bd005..65ea2845 100644 char *modifier; } GnomeLocale; ++typedef struct _GnomeInputSourceDefaults { ++ InputSource **input_sources; ++ char **options; ++} GnomeInputSourceDefaults; ++ static GHashTable *gnome_languages_map; static GHashTable *gnome_territories_map; static GHashTable *gnome_available_locales_map; @@ -88,7 +93,27 @@ index cc9bd005..65ea2845 100644 const char *territory, const char *codeset, const char *modifier); -@@ -1440,30 +1442,262 @@ gnome_get_input_source_from_locale (const char *locale, + + static gboolean language_name_is_valid (const char *language_name); + + static void + gnome_locale_free (GnomeLocale *locale) + { + if (locale == NULL) { + return; + } + + g_free (locale->id); + g_free (locale->name); + g_free (locale->codeset); + g_free (locale->modifier); + g_free (locale->language_code); + g_free (locale->territory_code); + g_free (locale); + } + + static char * +@@ -1440,30 +1447,279 @@ gnome_get_input_source_from_locale (const char *locale, } /** @@ -172,16 +197,18 @@ index cc9bd005..65ea2845 100644 +} + +static void -+input_sources_free (InputSource **input_sources) ++gnome_input_source_defaults_free (GnomeInputSourceDefaults *defaults) +{ + size_t i; + -+ for (i = 0; input_sources[i] != NULL; i++) { -+ g_free (input_sources[i]->type); -+ g_free (input_sources[i]->id); -+ g_free (input_sources[i]); ++ for (i = 0; defaults->input_sources[i] != NULL; i++) { ++ g_free (defaults->input_sources[i]->type); ++ g_free (defaults->input_sources[i]->id); ++ g_free (defaults->input_sources[i]); + } -+ g_free (input_sources); ++ g_free (defaults->input_sources); ++ g_strfreev (defaults->options); ++ g_free (defaults); +} + +static void @@ -198,12 +225,15 @@ index cc9bd005..65ea2845 100644 + g_autofree char *system_locale = NULL; + g_autofree char *layouts_string = NULL; + g_autofree char *variants_string = NULL; ++ g_autofree char *options_string = NULL; + g_auto(GStrv) layouts = NULL; + size_t number_of_layouts = 0; + g_auto(GStrv) variants = NULL; + size_t number_of_variants = 0; ++ g_auto(GStrv) options = NULL; + const char *type = NULL, *id = NULL; + size_t i; ++ GnomeInputSourceDefaults *defaults; + + proxy = g_task_propagate_pointer (G_TASK (result), &error); + @@ -237,6 +267,7 @@ index cc9bd005..65ea2845 100644 + + layouts_string = sd_dbus_locale1_dup_x11_layout (proxy); + variants_string = sd_dbus_locale1_dup_x11_variant (proxy); ++ options_string = sd_dbus_locale1_dup_x11_options (proxy); + + layouts = g_strsplit (layouts_string, ",", -1); + @@ -246,6 +277,8 @@ index cc9bd005..65ea2845 100644 + variants = g_strdupv ((char *[]) { "", NULL }); + } + ++ options = g_strsplit (options_string, ",", -1); ++ + number_of_layouts = g_strv_length (layouts); + number_of_variants = g_strv_length (variants); + @@ -279,7 +312,11 @@ index cc9bd005..65ea2845 100644 + } + g_ptr_array_add (input_sources, NULL); + -+ g_task_return_pointer (main_task, g_ptr_array_steal (input_sources, NULL), (GDestroyNotify) input_sources_free); ++ defaults = g_new0 (GnomeInputSourceDefaults, 1); ++ defaults->input_sources = (InputSource **) g_ptr_array_steal (input_sources, NULL); ++ defaults->options = g_steal_pointer (&options); ++ ++ g_task_return_pointer (main_task, defaults, (GDestroyNotify) gnome_input_source_defaults_free); +} + +/** @@ -314,7 +351,8 @@ index cc9bd005..65ea2845 100644 +/** + * gnome_get_default_input_sources_finish: + * @result: a #GAsyncResult -+ * @types: (transfer full): an array of types (either "xkb" or "ibus") ++ * @types: (out) (transfer full): an array of types (either "xkb" or "ibus") ++ * @options: (out) (transfer full): an options string to use with all input sources + * @error: a #GError + * + * Returns: (transfer full): a list of default input sources based on locale and system @@ -326,36 +364,40 @@ index cc9bd005..65ea2845 100644 +char ** +gnome_get_default_input_sources_finish (GAsyncResult *result, + char ***types, ++ char ***options, + GError **error) +{ -+ InputSource **input_sources = NULL; ++ GnomeInputSourceDefaults *defaults = NULL; + size_t i; + g_autoptr (GStrvBuilder) ids_builder = NULL; + g_autoptr (GStrvBuilder) types_builder = NULL; + -+ input_sources = g_task_propagate_pointer (G_TASK (result), error); ++ defaults = g_task_propagate_pointer (G_TASK (result), error); + -+ if (input_sources == NULL) { ++ if (defaults == NULL) { + return NULL; + } + + ids_builder = g_strv_builder_new (); + types_builder = g_strv_builder_new (); + -+ for (i = 0; input_sources[i] != NULL; i++) { -+ g_strv_builder_add (types_builder, input_sources[i]->type); -+ g_strv_builder_add (ids_builder, input_sources[i]->id); ++ for (i = 0; defaults->input_sources[i] != NULL; i++) { ++ g_strv_builder_add (types_builder, defaults->input_sources[i]->type); ++ g_strv_builder_add (ids_builder, defaults->input_sources[i]->id); + } + + if (types != NULL) + *types = g_strv_builder_end (types_builder); ++ ++ if (options != NULL) ++ *options = g_strdupv (defaults->options); + return g_strv_builder_end (ids_builder); +} diff --git a/libgnome-desktop/gnome-languages.h b/libgnome-desktop/gnome-languages.h -index ed9242e7..6876a0bb 100644 +index ed9242e7..e2cffa62 100644 --- a/libgnome-desktop/gnome-languages.h +++ b/libgnome-desktop/gnome-languages.h -@@ -1,61 +1,70 @@ +@@ -1,61 +1,71 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright 2008 Red Hat, Inc. @@ -422,6 +464,7 @@ index ed9242e7..6876a0bb 100644 + +char ** gnome_get_default_input_sources_finish (GAsyncResult *result, + char ***types, ++ char ***options, + GError **error); G_END_DECLS