diff -urN lxsession-0.4.4.orig/lxsession-logout/lxsession-logout.c lxsession-0.4.4/lxsession-logout/lxsession-logout.c --- lxsession-0.4.4.orig/lxsession-logout/lxsession-logout.c 2010-03-31 18:28:50.000000000 +0200 +++ lxsession-0.4.4/lxsession-logout/lxsession-logout.c 2010-07-17 11:23:57.000000000 +0200 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,7 @@ int ltsp : 1; /* under LTSP environment */ } HandlerContext; +static gboolean lock_screen(void); static gboolean verify_running(char * display_manager, char * executable); static void logout_clicked(GtkButton * button, HandlerContext * handler_context); static void shutdown_clicked(GtkButton * button, HandlerContext * handler_context); @@ -83,6 +85,46 @@ static GtkPositionType get_banner_position(void); static GdkPixbuf * get_background_pixbuf(void); +/* Try to lock the screen, return TRUE on success, FALSE if no suitable + * screensaver was found or the screensaver command exited abnormally. + */ +static gboolean lock_screen(void) +{ + gint i; + gint argcp; + gchar **argvp; + gint exit_status; + gchar *locking_commands[] = { + "xscreensaver-command -lock", + "gnome-screensaver-command --lock", + "xlock -mode blank", + NULL + }; + + for (i = 0; locking_commands[i] != NULL; ++i) + { + g_shell_parse_argv(locking_commands[i], &argcp, &argvp, NULL); + g_spawn_sync(NULL, + argvp, + NULL, + G_SPAWN_SEARCH_PATH|G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL, + NULL, + NULL, + NULL, + NULL, + &exit_status, + NULL); + g_strfreev (argvp); + + if (WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == 0) + { + return TRUE; + } + } + + return FALSE; +} + /* Verify that a program is running and that an executable is available. */ static gboolean verify_running(char * display_manager, char * executable) { @@ -187,6 +229,7 @@ /* Handler for "clicked" signal on Suspend button. */ static void suspend_clicked(GtkButton * button, HandlerContext * handler_context) { + lock_screen(); if (handler_context->suspend_DeviceKit) dbus_DeviceKit_Suspend(); else if (handler_context->suspend_HAL) @@ -197,6 +240,7 @@ /* Handler for "clicked" signal on Hibernate button. */ static void hibernate_clicked(GtkButton * button, HandlerContext * handler_context) { + lock_screen(); if (handler_context->hibernate_DeviceKit) dbus_DeviceKit_Hibernate(); else if (handler_context->hibernate_HAL) @@ -207,6 +251,7 @@ /* Handler for "clicked" signal on Switch User button. */ static void switch_user_clicked(GtkButton * button, HandlerContext * handler_context) { + lock_screen(); if (handler_context->switch_user_GDM) g_spawn_command_line_sync("gdmflexiserver --startnew", NULL, NULL, NULL, NULL); else if (handler_context->switch_user_KDM)