commit 53ec60d6ae72a13432be8a041e658db907af29e5
Author: Halton Huo <halton.huo@sun.com>
Date:   Fri Nov 20 11:40:45 2009 +0800

    gdm-17-last.diff

diff --git a/common/gdm-common.h b/common/gdm-common.h
index 95c8b91..389c8c8 100644
--- a/common/gdm-common.h
+++ b/common/gdm-common.h
@@ -30,6 +30,10 @@
 #define GDM_SDTLOGIN_DIR "/var/dt/sdtlogin"
 #endif
 
+#define GDM_LAST_LANGUAGE "GDM_LAST_LANGUAGE"
+#define GDM_LAST_LAYOUT   "GDM_LAST_LAYOUT"
+#define GDM_LAST_SESSION  "GDM_LAST_SESSION"
+
 G_BEGIN_DECLS
 
 gboolean       gdm_is_version_unstable            (void);
diff --git a/common/gdm-settings-keys.h b/common/gdm-settings-keys.h
index 293ecb8..1b1dbeb 100644
--- a/common/gdm-settings-keys.h
+++ b/common/gdm-settings-keys.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 #define GDM_KEY_INCLUDE "greeter/Include"
 #define GDM_KEY_EXCLUDE "greeter/Exclude"
 #define GDM_KEY_INCLUDE_ALL "greeter/IncludeAll"
+#define GDM_KEY_SHOW_LAST "greeter/ShowLast"
 
 #define GDM_KEY_XDMCP_ENABLE "xdmcp/Enable"
 #define GDM_KEY_MAX_PENDING "xdmcp/MaxPending"
diff --git a/daemon/gdm-session-direct.c b/daemon/gdm-session-direct.c
index e53d701..801c6f7 100644
--- a/daemon/gdm-session-direct.c
+++ b/daemon/gdm-session-direct.c
@@ -61,6 +61,7 @@
 
 #include "gdm-session-record.h"
 #include "gdm-session-worker-job.h"
+#include "gdm-common.h"
 
 #define GDM_DBUS_NAME                 "org.gnome.DisplayManager"
 #define GDM_DBUS_DISPLAY_INTERFACE    "org.gnome.DisplayManager.Display"
@@ -1181,8 +1182,20 @@ gdm_session_direct_handle_saved_language
         dbus_connection_send (connection, reply, NULL);
         dbus_message_unref (reply);
 
-        if (strcmp (language_name,
-                    get_default_language_name (session)) != 0) {
+        if (strcmp (language_name, GDM_LAST_LANGUAGE) == 0) {
+                /*
+                 * If the user picked "Last" in the language selector, then
+                 * process the change, but do not update the saved default
+                 * language, since it is not a real language.
+                 */
+                _gdm_session_default_language_name_changed (GDM_SESSION (session),
+                                                            language_name);
+        } else if (strcmp (language_name,
+                           get_default_language_name (session)) != 0) {
+                /*
+                 * Update the saved default language, so that subsequent
+                 * requests for it will reflect the user's choice.
+                 */
                 g_free (session->priv->saved_language);
                 session->priv->saved_language = g_strdup (language_name);
 
@@ -1190,7 +1203,6 @@ gdm_session_direct_handle_saved_language
                                                             language_name);
         }
 
-
         return DBUS_HANDLER_RESULT_HANDLED;
 }
 
@@ -1214,8 +1226,20 @@ gdm_session_direct_handle_saved_layout_n
         dbus_connection_send (connection, reply, NULL);
         dbus_message_unref (reply);
 
-        if (strcmp (layout_name,
-                    get_default_layout_name (session)) != 0) {
+        if (strcmp (layout_name, GDM_LAST_LAYOUT) == 0) {
+                /*
+                 * If the user picked "Last" in the layout selector, then
+                 * process the change, but do not update the saved default
+                 * layout, since it is not a real layout.
+                 */
+                _gdm_session_default_layout_name_changed (GDM_SESSION (session),
+                                                          layout_name);
+        } else if (strcmp (layout_name,
+                           get_default_layout_name (session)) != 0) {
+                /*
+                 * Update the saved default layout, so that subsequent requests
+                 * for it will reflect the user's choice.
+                 */
                 g_free (session->priv->saved_layout);
                 session->priv->saved_layout = g_strdup (layout_name);
 
@@ -1223,7 +1247,6 @@ gdm_session_direct_handle_saved_layout_n
                                                           layout_name);
         }
 
-
         return DBUS_HANDLER_RESULT_HANDLED;
 }
 
@@ -1247,23 +1270,32 @@ gdm_session_direct_handle_saved_session_
         dbus_connection_send (connection, reply, NULL);
         dbus_message_unref (reply);
 
-        if (! get_session_command_for_name (session_name, NULL)) {
+        if (strcmp (session_name, GDM_LAST_SESSION) == 0) {
+                /*
+                 * If the user picked "Last" in the session selector, then
+                 * process the change, but do not update the saved default
+                 * session, since it is not a real session.
+                 */
+                _gdm_session_default_session_name_changed (GDM_SESSION (session),
+                                                           session_name);
+        } else if (! get_session_command_for_name (session_name, NULL)) {
                 /* ignore sessions that don't exist */
                 g_debug ("GdmSessionDirect: not using invalid .dmrc session: %s", session_name);
                 g_free (session->priv->saved_session);
                 session->priv->saved_session = NULL;
-                goto out;
-        }
-
-        if (strcmp (session_name,
-                    get_default_session_name (session)) != 0) {
+        } else if (strcmp (session_name,
+                           get_default_session_name (session)) != 0) {
+                /*
+                 * Update the saved default session, so that subsequent
+                 * requests for it will reflect the user's choice.
+                 */
                 g_free (session->priv->saved_session);
                 session->priv->saved_session = g_strdup (session_name);
 
                 _gdm_session_default_session_name_changed (GDM_SESSION (session),
                                                            session_name);
         }
- out:
+
         return DBUS_HANDLER_RESULT_HANDLED;
 }
 
diff --git a/daemon/gdm-session-settings.c b/daemon/gdm-session-settings.c
index 421d87a..856e5a3 100644
--- a/daemon/gdm-session-settings.c
+++ b/daemon/gdm-session-settings.c
@@ -21,6 +21,7 @@
  */
 #include "config.h"
 #include "gdm-session-settings.h"
+#include "gdm-common.h"
 
 #include <errno.h>
 #include <pwd.h>
@@ -268,19 +269,62 @@ gdm_session_settings_is_loaded (GdmSessionSettings  *settings)
 gboolean
 gdm_session_settings_load (GdmSessionSettings  *settings,
                            const char          *username,
+                           gboolean             handle_last,
                            GError             **error)
 {
         GKeyFile *key_file;
         GError   *load_error;
         gboolean  is_loaded;
+        gboolean  skip_session;
+        gboolean  skip_language;
+        gboolean  skip_layout;
         char     *session_name;
         char     *language_name;
         char     *layout_name;
         char     *filename;
 
+        skip_session = FALSE;
+        skip_language = FALSE;
+        skip_layout = FALSE;
+
         g_return_val_if_fail (settings != NULL, FALSE);
         g_return_val_if_fail (username != NULL, FALSE);
-        g_return_val_if_fail (!gdm_session_settings_is_loaded (settings), FALSE);
+
+        if (!handle_last) {
+                g_return_val_if_fail (!gdm_session_settings_is_loaded (settings), FALSE);
+        } else {
+                if (settings->priv->session_name != NULL && 
+                    strcmp (settings->priv->session_name, GDM_LAST_SESSION) == 0) {
+                        g_debug ("Session value is last, loading user value");
+                        g_free (settings->priv->session_name);
+                        settings->priv->session_name = NULL;
+                } else {
+                        skip_session = TRUE;
+                }
+
+                if (settings->priv->language_name != NULL && 
+                    strcmp (settings->priv->language_name, GDM_LAST_LANGUAGE) == 0) {
+                        g_debug ("Language value is last, loading user value");
+                        g_free (settings->priv->language_name);
+                        settings->priv->language_name = NULL;
+                } else {
+                        skip_language = TRUE;
+                }
+
+                if (settings->priv->layout_name != NULL && 
+                    strcmp (settings->priv->layout_name, GDM_LAST_LAYOUT) == 0) {
+                        g_debug ("Layout value is last, loading user value");
+                        g_free (settings->priv->layout_name);
+                        settings->priv->layout_name = NULL;
+                } else {
+                        skip_layout = TRUE;
+                }
+
+                if (skip_session && skip_language && skip_layout) {
+                        is_loaded = TRUE;
+                        goto out;
+                }
+        }
 
         filename = g_build_filename (GDM_CACHE_DIR, username, "dmrc", NULL);
 
@@ -294,46 +340,52 @@ gdm_session_settings_load (GdmSessionSettings  *settings,
                 goto out;
         }
 
-        session_name = g_key_file_get_string (key_file, "Desktop", "Session",
-                                              &load_error);
-
-        if (session_name != NULL) {
-                gdm_session_settings_set_session_name (settings, session_name);
-                g_free (session_name);
-        } else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
-                g_error_free (load_error);
-                load_error = NULL;
-        } else {
-                g_propagate_error (error, load_error);
-                goto out;
+        if (!skip_session) {
+                session_name = g_key_file_get_string (key_file, "Desktop",
+                        "Session", &load_error);
+                if (session_name != NULL) {
+                        g_debug ("Setting value to %s", session_name);
+                        gdm_session_settings_set_session_name (settings, session_name);
+                        g_free (session_name);
+                } else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
+                        g_error_free (load_error);
+                        load_error = NULL;
+                } else {
+                        g_propagate_error (error, load_error);
+                        goto out;
+                }
         }
 
-        language_name = g_key_file_get_string (key_file, "Desktop", "Language",
-                                               &load_error);
-
-        if (language_name != NULL) {
-                gdm_session_settings_set_language_name (settings, language_name);
-                g_free (language_name);
-        } else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
-                g_error_free (load_error);
-                load_error = NULL;
-        } else {
-                g_propagate_error (error, load_error);
-                goto out;
+        if (!skip_language) {
+                language_name = g_key_file_get_string (key_file, "Desktop", "Language",
+                                                       &load_error);
+
+                if (language_name != NULL) {
+                        gdm_session_settings_set_language_name (settings, language_name);
+                        g_free (language_name);
+                } else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
+                        g_error_free (load_error);
+                        load_error = NULL;
+                } else {
+                        g_propagate_error (error, load_error);
+                        goto out;
+                }
         }
 
-        layout_name = g_key_file_get_string (key_file, "Desktop", "Layout",
-                                             &load_error);
-
-        if (layout_name != NULL) {
-                gdm_session_settings_set_layout_name (settings, layout_name);
-                g_free (layout_name);
-        } else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
-                g_error_free (load_error);
-                load_error = NULL;
-        } else {
-                g_propagate_error (error, load_error);
-                goto out;
+        if (!skip_layout) {
+                layout_name = g_key_file_get_string (key_file, "Desktop", "Layout",
+                                                     &load_error);
+
+                if (layout_name != NULL) {
+                        gdm_session_settings_set_layout_name (settings, layout_name);
+                        g_free (layout_name);
+                } else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
+                        g_error_free (load_error);
+                        load_error = NULL;
+                } else {
+                        g_propagate_error (error, load_error);
+                        goto out;
+                }
         }
 
         is_loaded = TRUE;
diff --git a/daemon/gdm-session-settings.h b/daemon/gdm-session-settings.h
index d579d4a..fb02dd1 100644
--- a/daemon/gdm-session-settings.h
+++ b/daemon/gdm-session-settings.h
@@ -55,6 +55,7 @@ GdmSessionSettings *gdm_session_settings_new                (void);
 
 gboolean            gdm_session_settings_load               (GdmSessionSettings  *settings,
                                                              const char          *username,
+                                                             gboolean             handle_last,
                                                              GError             **error);
 gboolean            gdm_session_settings_save               (GdmSessionSettings  *settings,
                                                              const char          *home_directory,
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index 6e42f7d..1b71eb8 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -72,6 +72,8 @@
 
 #include "gdm-session-settings.h"
 #include "gdm-common.h"
+#include "gdm-settings-direct.h"
+#include "gdm-settings-keys.h"
 
 #define GDM_SESSION_WORKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_SESSION_WORKER, GdmSessionWorkerPrivate))
 
@@ -723,10 +725,26 @@ gdm_session_worker_get_username (GdmSess
 
 static void
 attempt_to_load_user_settings (GdmSessionWorker *worker,
-                               const char       *username)
+                               const char       *username,
+                               gboolean          handle_last)
 {
+        gboolean show_last;
+
+        gdm_settings_direct_get_boolean (GDM_KEY_SHOW_LAST, &show_last);
+        if (show_last && !handle_last) {
+                g_debug ("Setting selection options to Last");
+                gdm_session_settings_set_session_name (worker->priv->user_settings,
+                        GDM_LAST_SESSION);
+                gdm_session_settings_set_language_name (worker->priv->user_settings,
+                        GDM_LAST_LANGUAGE);
+                gdm_session_settings_set_layout_name (worker->priv->user_settings,
+                        GDM_LAST_LAYOUT);
+                return;
+        }
+
         gdm_session_settings_load (worker->priv->user_settings,
                                    username,
+                                   handle_last,
                                    NULL);
 }
 
@@ -768,7 +786,9 @@ gdm_session_worker_update_username (GdmS
                  */
                 if (worker->priv->username != NULL &&
                     !gdm_session_settings_is_loaded (worker->priv->user_settings)) {
-                        attempt_to_load_user_settings (worker, worker->priv->username);
+                        attempt_to_load_user_settings (worker,
+                               worker->priv->username,
+                               FALSE);
                 }
         }
 
@@ -1805,12 +1825,16 @@ gdm_session_worker_accredit_user (GdmSes
 {
         gboolean ret;
         gboolean res;
+        gboolean has_last;
         uid_t    uid;
         gid_t    gid;
         char    *shell;
         char    *home;
         char    *path_str;
         int      error_code;
+        char    *session_name;
+        char    *language_name;
+        char    *layout_name;
 
         ret = FALSE;
 
@@ -1884,6 +1908,46 @@ gdm_session_worker_accredit_user (GdmSes
 
         ret = TRUE;
 
+        /*
+         * If the user is using the "Last" session, get the defaults
+         * now, after pam_setcred is complete.
+         */
+        session_name  = gdm_session_settings_get_session_name (
+                worker->priv->user_settings);
+        language_name = gdm_session_settings_get_language_name (
+                worker->priv->user_settings);
+        layout_name   = gdm_session_settings_get_layout_name (
+                worker->priv->user_settings);
+
+        has_last = FALSE;
+        if (session_name != NULL &&
+            strcmp (session_name, GDM_LAST_SESSION) == 0) {
+                g_debug ("Session setting is Last");
+                has_last = TRUE;
+        }
+        if (language_name != NULL &&
+            strcmp (language_name, GDM_LAST_LANGUAGE) == 0) {
+                g_debug ("Language setting is Last");
+                has_last = TRUE;
+        }
+        if (layout_name != NULL &&
+            strcmp (layout_name, GDM_LAST_LAYOUT) == 0) {
+                g_debug ("Layout setting is Last");
+                has_last = TRUE;
+        }
+
+        if (has_last) {
+                g_debug ("Now loading users default settings.");
+
+                /* Now copy user settings to cache and load */
+                gdm_session_worker_cache_userfiles (worker);
+                attempt_to_load_user_settings (worker, worker->priv->username,
+                        TRUE);
+        }
+        g_free (session_name);
+        g_free (language_name);
+        g_free (layout_name);
+
  out:
         g_free (home);
         g_free (shell);
@@ -2535,7 +2599,8 @@ do_setup (GdmSessionWorker *worker)
          */
         if (worker->priv->username != NULL) {
                 attempt_to_load_user_settings (worker,
-                                               worker->priv->username);
+                                               worker->priv->username,
+                                               FALSE);
         }
 
         error = NULL;
diff --git a/data/gdm.schemas.in.in b/data/gdm.schemas.in.in
index 5774b65..ff088d3 100644
--- a/data/gdm.schemas.in.in
+++ b/data/gdm.schemas.in.in
@@ -69,6 +69,11 @@
       <signature>b</signature>
       <default>false</default>
     </schema>
+    <schema>
+      <key>greeter/ShowLast</key>
+      <signature>b</signature>
+      <default>false</default>
+    </schema>
 
     <schema>
       <key>xdmcp/Enable</key>
diff --git a/gui/simple-greeter/Makefile.am b/gui/simple-greeter/Makefile.am
index 1fa87cf..b872e2b 100644
--- a/gui/simple-greeter/Makefile.am
+++ b/gui/simple-greeter/Makefile.am
@@ -187,6 +187,8 @@ test_language_chooser_SOURCES = 	\
 test_language_chooser_LDADD =	\
 	$(GTK_LIBS)		\
 	$(GCONF_LIBS)		\
+	$(top_builddir)/common/libgdmcommon.la \
+	$(COMMON_LIBS)		\
 	$(NULL)
 
 test_layout_chooser_SOURCES = 	\
@@ -211,6 +213,7 @@ test_layout_chooser_LDADD =		\
 	$(GTK_LIBS)			\
 	$(GCONF_LIBS)			\
 	$(LIBXKLAVIER_LIBS)		\
+	$(top_builddir)/common/libgdmcommon.la \
 	$(NULL)
 
 test_languages_SOURCES = 		\
@@ -222,6 +225,8 @@ test_languages_SOURCES = 		\
 
 test_languages_LDADD =		\
 	$(GTK_LIBS)		\
+	$(top_builddir)/common/libgdmcommon.la \
+	$(COMMON_LIBS)		\
 	$(NULL)
 
 test_sessions_SOURCES = 		\
@@ -232,6 +237,8 @@ test_sessions_SOURCES = 		\
 
 test_sessions_LDADD =		\
 	$(GTK_LIBS)		\
+	$(top_builddir)/common/libgdmcommon.la \
+	$(COMMON_LIBS)		\
 	$(NULL)
 
 test_user_chooser_SOURCES = 		\
diff --git a/gui/simple-greeter/gdm-language-option-widget.c b/gui/simple-greeter/gdm-language-option-widget.c
index bb14b68..52d4afb 100644
--- a/gui/simple-greeter/gdm-language-option-widget.c
+++ b/gui/simple-greeter/gdm-language-option-widget.c
@@ -35,6 +35,8 @@
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 
+#include "gdm-common.h"
+#include "gdm-settings-keys.h"
 #include "gdm-profile.h"
 #include "gdm-languages.h"
 #include "gdm-language-option-widget.h"
@@ -184,6 +186,10 @@ gdm_language_option_widget_lookup_item (
         char *lang_tag;
         char *normalized_locale;
 
+        if (strcmp (locale, GDM_LAST_LANGUAGE) == 0) {
+                return NULL;
+        }
+
         normalized_locale = gdm_normalize_language_name (locale);
 
         language = gdm_get_language_from_name (locale, normalized_locale);
@@ -208,6 +214,7 @@ static void
 gdm_language_option_widget_init (GdmLanguageOptionWidget *widget)
 {
         GError *error;
+        gboolean show_last;
 
         widget->priv = GDM_LANGUAGE_OPTION_WIDGET_GET_PRIVATE (widget);
 
@@ -232,6 +239,16 @@ gdm_language_option_widget_init (GdmLang
                                     _("Choose a language from the "
                                       "full list of available languages."),
                                     GDM_OPTION_WIDGET_POSITION_BOTTOM);
+
+
+        gdm_settings_client_get_boolean (GDM_KEY_SHOW_LAST, &show_last);
+        if (show_last) {
+                gdm_option_widget_add_item (GDM_OPTION_WIDGET (widget),
+                                            GDM_LAST_LANGUAGE,
+                                            C_("lastlanguage", "Last"),
+                                            _("Last language"),
+                                            GDM_OPTION_WIDGET_POSITION_TOP);
+        }
 }
 
 static void
diff --git a/gui/simple-greeter/gdm-languages.c b/gui/simple-greeter/gdm-languages.c
index f19c055..3ad321c 100644
--- a/gui/simple-greeter/gdm-languages.c
+++ b/gui/simple-greeter/gdm-languages.c
@@ -37,6 +37,7 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 
+#include "gdm-common.h"
 #include "gdm-languages.h"
 
 #include <langinfo.h>
@@ -246,6 +247,11 @@ gdm_normalize_language_name (const char *name)
                 return NULL;
         }
 
+        if (strcmp (name, GDM_LAST_LANGUAGE) == 0) {
+                normalized_name = g_strdup (name);
+                return normalized_name;
+        }
+
         gdm_parse_language_name (name,
                                  &language_code,
                                  &territory_code,
diff --git a/gui/simple-greeter/gdm-layout-option-widget.c b/gui/simple-greeter/gdm-layout-option-widget.c
index a6eb1b9..e13b085 100644
--- a/gui/simple-greeter/gdm-layout-option-widget.c
+++ b/gui/simple-greeter/gdm-layout-option-widget.c
@@ -35,6 +35,9 @@
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 
+#include "gdm-common.h"
+#include "gdm-settings-client.h"
+#include "gdm-settings-keys.h"
 #include "gdm-profile.h"
 #include "gdm-layouts.h"
 #include "gdm-layout-option-widget.h"
@@ -184,6 +187,10 @@ gdm_layout_option_widget_lookup_item (GdmRecentOptionWidget *widget,
 {
         char *layout;
 
+        if (strcmp (key, GDM_LAST_LAYOUT) == 0) {
+                return NULL;
+        }
+
         layout = gdm_get_layout_from_name (key);
 
         if (layout == NULL) {
@@ -200,6 +207,7 @@ static void
 gdm_layout_option_widget_init (GdmLayoutOptionWidget *widget)
 {
         GError *error;
+        gboolean show_last;
 
         widget->priv = GDM_LAYOUT_OPTION_WIDGET_GET_PRIVATE (widget);
 
@@ -224,6 +232,15 @@ gdm_layout_option_widget_init (GdmLayoutOptionWidget *widget)
                                     _("Choose a keyboard layout from the "
                                       "full list of available layouts."),
                                     GDM_OPTION_WIDGET_POSITION_BOTTOM);
+
+        gdm_settings_client_get_boolean (GDM_KEY_SHOW_LAST, &show_last);
+        if (show_last) {
+                gdm_option_widget_add_item (GDM_OPTION_WIDGET (widget),
+                                            GDM_LAST_LAYOUT,
+                                            C_("lastlayout", "Last"),
+                                            _("Last layout"),
+                                            GDM_OPTION_WIDGET_POSITION_TOP);
+       }
 }
 
 static void
@@ -288,7 +305,10 @@ gdm_layout_option_widget_set_current_layout_name (GdmLayoutOptionWidget *widget,
                                             id, NULL, NULL, NULL)) {
                 gdm_recent_option_widget_add_item (GDM_RECENT_OPTION_WIDGET (widget),
                                                    id);
+        } else if (strcmp (id, GDM_LAST_LAYOUT) == 0) {
+                gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), id);
         }
+
         g_debug ("GdmLayoutOptionWidget: Setting active item: '%s'", id);
         gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), id);
 }
diff --git a/gui/simple-greeter/gdm-session-option-widget.c b/gui/simple-greeter/gdm-session-option-widget.c
index 961ac94..046b5bf 100644
--- a/gui/simple-greeter/gdm-session-option-widget.c
+++ b/gui/simple-greeter/gdm-session-option-widget.c
@@ -36,8 +36,10 @@
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 
+#include "gdm-common.h"
 #include "gdm-session-option-widget.h"
 #include "gdm-sessions.h"
+#include "gdm-settings-keys.h"
 
 #define GDM_SESSION_OPTION_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_SESSION_OPTION_WIDGET, GdmSessionOptionWidgetPrivate))
 
@@ -133,8 +135,19 @@ add_available_sessions (GdmSessionOptionWidget *widget)
 static void
 gdm_session_option_widget_init (GdmSessionOptionWidget *widget)
 {
+        gboolean show_last;
+
         widget->priv = GDM_SESSION_OPTION_WIDGET_GET_PRIVATE (widget);
 
+        gdm_settings_client_get_boolean (GDM_KEY_SHOW_LAST, &show_last);
+        if (show_last) {
+                gdm_option_widget_add_item (GDM_OPTION_WIDGET (widget),
+                                            GDM_LAST_SESSION,
+                                            C_("lastsession", "Last"),
+                                            _("Last session"),
+                                            GDM_OPTION_WIDGET_POSITION_TOP);
+        }
+
         add_available_sessions (widget);
 }
 
@@ -189,5 +202,7 @@ gdm_session_option_widget_set_current_session (GdmSessionOptionWidget *widget,
         } else if (gdm_option_widget_lookup_item (GDM_OPTION_WIDGET (widget), session,
                                             NULL, NULL, NULL)) {
                 gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), session);
+        } else if (strcmp (session, GDM_LAST_SESSION) == 0) {
+                gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), session);
         }
 }
--- gdm-2.29.1/gui/simple-greeter/gdm-layouts.c-orig	2009-12-21 11:54:58.946444139 -0600
+++ gdm-2.29.1/gui/simple-greeter/gdm-layouts.c	2009-12-21 11:56:06.467766896 -0600
@@ -34,6 +34,7 @@
 #include <gconf/gconf-client.h>
 
 #include "gdm-layouts.h"
+#include "gdm-common.h"
 
 typedef struct {
         GSList *list;
@@ -197,6 +198,10 @@ gdm_layout_is_valid (const char *layout_
         char          *variant;
         gboolean       retval;
 
+        if (layout_variant != NULL && strcmp (layout_variant, GDM_LAST_LAYOUT) == 0) {
+                return TRUE;
+        }
+
         layout = g_strdup (layout_variant);
         variant = strchr (layout, '\t');
         if (variant != NULL) {
@@ -245,6 +250,10 @@ gdm_layout_activate (const char *layout)
         XklConfigRec *config;
         char         *p;
 
+        if (layout != NULL && strcmp (layout, GDM_LAST_LAYOUT) == 0) {
+                return;
+        }
+
         init_xkl ();
 
         config = xkl_config_rec_new ();
