From 22667605630041bb654782773182b60d60a039cd Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Thu, 24 Aug 2023 13:03:07 -0500 Subject: [PATCH 02/12] keyboard: write to mru-sources setting if it has never been set before This is a port of: https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1893 In theory, this shouldn't matter during a firstboot scenario as mru-sources should not be touched yet, but gnome-initial-setup may be run in a different ways and it seems useful to be robust here. --- .../pages/keyboard/gis-keyboard-page.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c b/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c index 693bb117..ad48d933 100644 --- a/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c +++ b/gnome-initial-setup/pages/keyboard/gis-keyboard-page.c @@ -17,60 +17,61 @@ * Author: Sergey Udaltsov * Michael Wood * * Based on gnome-control-center cc-region-panel.c */ #define PAGE_ID "keyboard" #include "config.h" #include #include #include #include #include #define GNOME_DESKTOP_USE_UNSTABLE_API #include #include "gis-keyboard-page.h" #include "keyboard-resources.h" #include "cc-input-chooser.h" #include "cc-common-language.h" #include "gis-page-header.h" #define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources" #define KEY_CURRENT_INPUT_SOURCE "current" #define KEY_INPUT_SOURCES "sources" +#define KEY_MRU_SOURCES "mru-sources" struct _GisKeyboardPagePrivate { GtkWidget *input_chooser; GDBusProxy *localed; GCancellable *cancellable; GPermission *permission; GSettings *input_settings; GSList *system_sources; }; typedef struct _GisKeyboardPagePrivate GisKeyboardPagePrivate; G_DEFINE_TYPE_WITH_PRIVATE (GisKeyboardPage, gis_keyboard_page, GIS_TYPE_PAGE); static void gis_keyboard_page_finalize (GObject *object) { GisKeyboardPage *self = GIS_KEYBOARD_PAGE (object); GisKeyboardPagePrivate *priv = gis_keyboard_page_get_instance_private (self); if (priv->cancellable) g_cancellable_cancel (priv->cancellable); g_clear_object (&priv->cancellable); g_clear_object (&priv->permission); g_clear_object (&priv->localed); g_clear_object (&priv->input_settings); g_slist_free_full (priv->system_sources, g_free); @@ -83,63 +84,71 @@ set_input_settings (GisKeyboardPage *self) { GisKeyboardPagePrivate *priv = gis_keyboard_page_get_instance_private (self); const gchar *type; const gchar *id; GVariantBuilder builder; GSList *l; gboolean is_xkb_source = FALSE; type = cc_input_chooser_get_input_type (CC_INPUT_CHOOSER (priv->input_chooser)); id = cc_input_chooser_get_input_id (CC_INPUT_CHOOSER (priv->input_chooser)); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)")); if (g_str_equal (type, "xkb")) { g_variant_builder_add (&builder, "(ss)", type, id); is_xkb_source = TRUE; } for (l = priv->system_sources; l; l = l->next) { const gchar *sid = l->data; if (g_str_equal (id, sid) && g_str_equal (type, "xkb")) continue; g_variant_builder_add (&builder, "(ss)", "xkb", sid); } if (!is_xkb_source) g_variant_builder_add (&builder, "(ss)", type, id); - g_settings_set_value (priv->input_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); + if (type != NULL && id != NULL) { + GVariantBuilder mru_input_source_builder; - g_settings_apply (priv->input_settings); + g_variant_builder_init (&mru_input_source_builder, G_VARIANT_TYPE ("a(ss)")); + g_variant_builder_add (&mru_input_source_builder, "(ss)", type, id); + g_settings_set_value (priv->input_settings, KEY_MRU_SOURCES, g_variant_builder_end (&mru_input_source_builder)); + } + + g_settings_set_value (priv->input_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); + + g_settings_apply (priv->input_settings); } static void set_localed_input (GisKeyboardPage *self) { GisKeyboardPagePrivate *priv = gis_keyboard_page_get_instance_private (self); const gchar *layout, *variant; GString *layouts; GString *variants; GSList *l; if (!priv->localed) return; cc_input_chooser_get_layout (CC_INPUT_CHOOSER (priv->input_chooser), &layout, &variant); if (layout == NULL) layout = ""; if (variant == NULL) variant = ""; layouts = g_string_new (layout); variants = g_string_new (variant); #define LAYOUT(a) (a[0]) #define VARIANT(a) (a[1] ? a[1] : "") for (l = priv->system_sources; l; l = l->next) { const gchar *sid = l->data; gchar **lv = g_strsplit (sid, "+", -1); if (!g_str_equal (LAYOUT (lv), layout) || -- 2.41.0