[gdm] Correctly handle invalid xkb layout from ~/.dmrc



commit 966a59bf0680152fe92f8f08d4db9b3df7a8eeec
Author: Vincent Untz <vuntz gnome org>
Date:   Tue Jun 9 23:45:54 2009 +0200

    Correctly handle invalid xkb layout from ~/.dmrc
    
    We check that the xkb layout/variant that the daemon gives us is valid,
    and if it's not, we use the default layout/variant (ie, what was set
    when X started).
    
    This is useful for users that have a broken ~/.dmrc.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=585263

 gui/simple-greeter/gdm-greeter-panel.c |   14 +++++++++
 gui/simple-greeter/gdm-layouts.c       |   50 ++++++++++++++++++++++++++++++++
 gui/simple-greeter/gdm-layouts.h       |    8 +++--
 3 files changed, 69 insertions(+), 3 deletions(-)
---
diff --git a/gui/simple-greeter/gdm-greeter-panel.c b/gui/simple-greeter/gdm-greeter-panel.c
index 6aded10..0ae1c54 100644
--- a/gui/simple-greeter/gdm-greeter-panel.c
+++ b/gui/simple-greeter/gdm-greeter-panel.c
@@ -724,6 +724,20 @@ gdm_greeter_panel_set_default_layout_name (GdmGreeterPanel *panel,
         g_return_if_fail (GDM_IS_GREETER_PANEL (panel));
 
         if (layout_name != NULL &&
+            !gdm_layout_is_valid (layout_name)) {
+                const char *default_layout;
+
+                default_layout = gdm_layout_get_default_layout ();
+
+                g_debug ("GdmGreeterPanel: default layout %s is invalid, resetting to: %s",
+                         layout_name, default_layout ? default_layout : "null");
+
+                g_signal_emit (panel, signals[LAYOUT_SELECTED], 0, default_layout);
+
+                layout_name = default_layout;
+        }
+
+        if (layout_name != NULL &&
             !gdm_option_widget_lookup_item (GDM_OPTION_WIDGET (panel->priv->layout_option_widget),
                                             layout_name, NULL, NULL, NULL)) {
                 gdm_recent_option_widget_add_item (GDM_RECENT_OPTION_WIDGET (panel->priv->layout_option_widget),
diff --git a/gui/simple-greeter/gdm-layouts.c b/gui/simple-greeter/gdm-layouts.c
index dc35094..07554e6 100644
--- a/gui/simple-greeter/gdm-layouts.c
+++ b/gui/simple-greeter/gdm-layouts.c
@@ -189,6 +189,56 @@ gdm_get_all_layout_names (void)
 #endif
 }
 
+gboolean
+gdm_layout_is_valid (const char *layout_variant)
+{
+#ifdef HAVE_LIBXKLAVIER
+        XklConfigItem *item;
+        char          *layout;
+        char          *variant;
+        gboolean       retval;
+
+        layout = g_strdup (layout_variant);
+        variant = strchr (layout, '\t');
+        if (variant != NULL) {
+                variant[0] = '\0';
+                variant++;
+        }
+
+        item = xkl_config_item_new ();
+        g_snprintf (item->name, XKL_MAX_CI_NAME_LENGTH, "%s", layout);
+
+        retval = xkl_config_registry_find_layout (config_registry, item);
+
+        if (retval && variant != NULL) {
+                g_snprintf (item->name, XKL_MAX_CI_NAME_LENGTH, "%s", variant);
+                retval = xkl_config_registry_find_variant (config_registry, layout, item);
+        }
+
+        g_object_unref (item);
+        g_free (layout);
+
+        return retval;
+#else
+        return TRUE;
+#endif
+}
+
+const char *
+gdm_layout_get_default_layout (void)
+{
+#ifdef HAVE_LIBXKLAVIER
+        init_xkl ();
+
+        if (initial_config->layouts)
+                return initial_config->layouts[0];
+        else
+                return NULL;
+#else
+        return NULL;
+#endif
+}
+
 void
 gdm_layout_activate (const char *layout)
 {
diff --git a/gui/simple-greeter/gdm-layouts.h b/gui/simple-greeter/gdm-layouts.h
index a87b620..9e1b99b 100644
--- a/gui/simple-greeter/gdm-layouts.h
+++ b/gui/simple-greeter/gdm-layouts.h
@@ -24,9 +24,11 @@
 
 G_BEGIN_DECLS
 
-char *        gdm_get_layout_from_name  (const char *name);
-char **       gdm_get_all_layout_names  (void);
-void          gdm_layout_activate       (const char *layout);
+char *        gdm_get_layout_from_name   (const char *name);
+char **       gdm_get_all_layout_names   (void);
+gboolean      gdm_layout_is_valid        (const char *layout);
+const char *  gdm_layout_get_default_layout (void);
+void          gdm_layout_activate        (const char *layout);
 
 G_END_DECLS
 



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