--- gnome-settings-daemon-2.22.1/plugins/keyboard/gsd-keyboard-xkb.c	2008-04-30 22:56:07.000000000 -0400
+++ hacked/plugins/keyboard/gsd-keyboard-xkb.c	2008-04-30 22:55:51.000000000 -0400
@@ -54,6 +54,8 @@
 static const char KNOWN_FILES_KEY[] =
     "/desktop/gnome/peripherals/keyboard/general/known_file_list";
 
+static char *gdm_keyboard_layout = NULL;
+
 #define noGSDKX
 
 #ifdef GSDKX
@@ -137,6 +139,8 @@
 {
         GConfClient       *conf_client;
         GkbdKeyboardConfig current_sys_kbd_config;
+	GSList *l;
+	int i;
 
         if (!inited_ok)
                 return;
@@ -158,6 +162,19 @@
                 g_free (current_kbd_config.model);
                 current_kbd_config.model = g_strdup ("evdev");
         }
+
+	/* Try to keep the same layout from the login screen
+         */  
+	if (gdm_keyboard_layout) {
+		for (i = 0, l = current_kbd_config.layouts_variants; l; i++, l = l->next) {
+			if (strcmp (gdm_keyboard_layout, l->data) == 0) {
+				xkl_engine_lock_group (current_config.engine, i);
+				break;
+			}
+		}
+		gdm_keyboard_layout = NULL;
+	}
+
         /* Activate - only if different! */
         if (!gkbd_keyboard_config_equals
             (&current_kbd_config, &current_sys_kbd_config)) {
@@ -312,6 +329,8 @@
         xkl_set_log_appender (gsd_keyboard_log_appender);
 #endif
 
+	gdm_keyboard_layout = g_getenv ("GDM_KEYBOARD_LAYOUT");
+
         xkl_engine = xkl_engine_get_instance (GDK_DISPLAY ());
         if (xkl_engine) {
                 inited_ok = TRUE;
