[gnome-initial-setup/wip/pwithnall/misc-fixes: 24/70] keyboard: add us/us+intl default layouts as fallback




commit fdcad1f07c49a14009390ae159e1109708d1f705
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Fri Feb 17 17:27:32 2017 -0800

    keyboard: add us/us+intl default layouts as fallback
    
    When no more specific keyboard layouts have been found, add us and
    us+intl as fallback options, instead of an empty list.
    
    (Rebase 3.38: This could potentially be dropped in future if we update
    cc-input-chooser.c from gnome-control-center; it’s copy/paste code.)
    
    https://phabricator.endlessm.com/T15660

 .../pages/keyboard/cc-input-chooser.c              | 25 ++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/gnome-initial-setup/pages/keyboard/cc-input-chooser.c 
b/gnome-initial-setup/pages/keyboard/cc-input-chooser.c
index f6f24ec7..0d68dfb2 100644
--- a/gnome-initial-setup/pages/keyboard/cc-input-chooser.c
+++ b/gnome-initial-setup/pages/keyboard/cc-input-chooser.c
@@ -324,7 +324,7 @@ no_results_widget_new (void)
         return widget;
 }
 
-static void
+static int
 add_rows_to_list (CcInputChooser  *chooser,
                  GList            *list,
                  const gchar      *type,
@@ -335,6 +335,7 @@ add_rows_to_list (CcInputChooser  *chooser,
        const gchar *id;
        GtkWidget *widget;
        gchar *key;
+       int rows_added = 0;
 
        for (; list; list = list->next) {
                id = (const gchar *) list->data;
@@ -348,15 +349,18 @@ add_rows_to_list (CcInputChooser  *chooser,
                        continue;
                }
                g_hash_table_add (priv->inputs, key);
+               rows_added++;
 
                if (g_hash_table_size (priv->inputs) > MIN_ROWS)
                        is_extra = TRUE;
                widget = input_widget_new (chooser, type, id, is_extra);
                gtk_container_add (GTK_CONTAINER (priv->input_list), widget);
        }
+
+       return rows_added;
 }
 
-static void
+static int
 add_row_to_list (CcInputChooser *chooser,
                 const gchar     *type,
                 const gchar     *id,
@@ -364,7 +368,7 @@ add_row_to_list (CcInputChooser *chooser,
 {
        GList tmp = { 0 };
        tmp.data = (gpointer)id;
-       add_rows_to_list (chooser, &tmp, type, NULL, is_extra);
+       return add_rows_to_list (chooser, &tmp, type, NULL, is_extra);
 }
 
 static void
@@ -375,9 +379,10 @@ get_locale_infos (CcInputChooser *chooser)
        const gchar *id = NULL;
        gchar *lang, *country;
        GList *list;
+       int non_extra_layouts = 0;
 
        if (gnome_get_input_source_from_locale (priv->locale, &type, &id)) {
-                add_row_to_list (chooser, type, id, FALSE);
+                non_extra_layouts += add_row_to_list (chooser, type, id, FALSE);
                if (!priv->id) {
                        priv->id = g_strdup (id);
                        priv->type = g_strdup (type);
@@ -388,15 +393,23 @@ get_locale_infos (CcInputChooser *chooser)
                goto out;
 
        list = gnome_xkb_info_get_layouts_for_language (priv->xkb_info, lang);
-       add_rows_to_list (chooser, list, INPUT_SOURCE_TYPE_XKB, id, FALSE);
+       non_extra_layouts += add_rows_to_list (chooser, list, INPUT_SOURCE_TYPE_XKB, id, FALSE);
        g_list_free (list);
 
        if (country != NULL) {
                list = gnome_xkb_info_get_layouts_for_country (priv->xkb_info, country);
-               add_rows_to_list (chooser, list, INPUT_SOURCE_TYPE_XKB, id, FALSE);
+               non_extra_layouts += add_rows_to_list (chooser, list, INPUT_SOURCE_TYPE_XKB, id, FALSE);
                g_list_free (list);
        }
 
+       /* Add default us and us+intl non-extra layouts in case we could not
+        * find anything more specific.
+        */
+       if (non_extra_layouts == 0) {
+               add_row_to_list (chooser, INPUT_SOURCE_TYPE_XKB, "us", FALSE);
+               add_row_to_list (chooser, INPUT_SOURCE_TYPE_XKB, "us+intl", FALSE);
+       }
+
        list = gnome_xkb_info_get_all_layouts (priv->xkb_info);
        add_rows_to_list (chooser, list, INPUT_SOURCE_TYPE_XKB, id, TRUE);
        g_list_free (list);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]