Ubuntu hal patch translated to libxklavier.
Always overrides keyboard layout variants: https://bugzilla.gnome.org/show_bug.cgi?id=572765
diff -Nur -x '*.orig' -x '*~' gdm-2.28.1/daemon/gdm-session-direct.c gdm-2.28.1.new/daemon/gdm-session-direct.c
--- gdm-2.28.1/daemon/gdm-session-direct.c	2009-10-20 00:12:45.000000000 +0200
+++ gdm-2.28.1.new/daemon/gdm-session-direct.c	2009-11-27 08:56:30.357591406 +0100
@@ -42,6 +42,9 @@
 #include <glib/gstdio.h>
 #include <glib-object.h>
 
+#include <libxklavier/xklavier.h>
+#include <X11/Xlib.h> /* for Display */
+
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
@@ -598,14 +601,44 @@
     return setlocale (LC_MESSAGES, NULL);
 }
 
+static char *
+get_system_default_layout (GdmSessionDirect *session)
+{
+    char *result;
+    Display *display;
+    
+    result = NULL;    
+    display = XOpenDisplay (session->priv->display_name);
+    if (display) {
+        XklConfigRec *config;
+        XklEngine *engine = xkl_engine_get_instance (display);
+        if (engine)
+        {
+            XklConfigRec *config = xkl_config_rec_new ();
+            if (xkl_config_rec_get_from_server (config, engine) && config->layouts && config->layouts[0]) {
+                    if (config->variants && config->variants[0] && config->variants[0][0])
+			    result = g_strdup_printf("%s\t%s", config->layouts[0], config->variants[0]);
+                    else
+			    result = g_strdup (config->layouts[0]);
+            }
+            g_object_unref (config);
+        }
+        XCloseDisplay (display);
+    }
+
+    if (!result)
+        result = g_strdup ("us");    
+    return result;
+}
+
 static const char *
 get_default_layout_name (GdmSessionDirect *session)
 {
-    if (session->priv->saved_layout != NULL) {
-                return session->priv->saved_layout;
+    if (!session->priv->saved_layout) {
+        session->priv->saved_layout = get_system_default_layout (session);
     }
 
-    return "us";
+    return session->priv->saved_layout;
 }
 
 static char *
diff -Nur -x '*.orig' -x '*~' gdm-2.28.1/daemon/Makefile.am gdm-2.28.1.new/daemon/Makefile.am
--- gdm-2.28.1/daemon/Makefile.am	2009-10-20 00:12:45.000000000 +0200
+++ gdm-2.28.1.new/daemon/Makefile.am	2009-11-27 08:55:14.640057134 +0100
@@ -105,6 +105,7 @@
 	$(EXTRA_DAEMON_LIBS)	\
 	$(DAEMON_LIBS)		\
 	$(PAM_LIBS)		\
+	$(LIBXKLAVIER_LIBS)	\
 	$(NULL)
 
 libexec_PROGRAMS = 			\
@@ -151,6 +152,7 @@
 	$(XLIB_LIBS)				\
 	$(DAEMON_LIBS)				\
 	$(EXTRA_DAEMON_LIBS)                    \
+	$(LIBXKLAVIER_LIBS)			\
 	$(NULL)
 
 gdm_factory_slave_SOURCES = 		\
@@ -214,6 +216,7 @@
 	$(XLIB_LIBS)				\
 	$(DAEMON_LIBS)				\
 	$(EXTRA_DAEMON_LIBS)                    \
+	$(LIBXKLAVIER_LIBS)			\
 	$(NULL)
 
 gdm_xdmcp_chooser_slave_SOURCES = 		\
