Description: when suspending or hibernating, use the new ubuntu-lock-on-suspend preference.
Author: Marc Deslauriers <marc.deslauriers@canonical.com>
Forwarded: no, likely a Ubuntu-specific preference
Bug-Ubuntu: https://bugs.launchpad.net/bugs/938076
Bug-Ubuntu: https://bugs.launchpad.net/bugs/847814

Index: gnome-settings-daemon-3.3.92/plugins/power/gsd-power-manager.c
===================================================================
--- gnome-settings-daemon-3.3.92.orig/plugins/power/gsd-power-manager.c	2012-03-20 08:30:29.810357813 -0400
+++ gnome-settings-daemon-3.3.92/plugins/power/gsd-power-manager.c	2012-03-20 08:38:54.686352998 -0400
@@ -2301,9 +2301,6 @@
                          CA_PROP_EVENT_DESCRIPTION, _("Lid has been closed"),
                          NULL);
 
-        /* maybe lock the screen if the lid is closed */
-        lock_screensaver (manager);
-
         /* we have different settings depending on AC state */
         if (up_client_get_on_battery (manager->priv->up_client)) {
                 action_type = g_settings_get_enum (manager->priv->settings,
@@ -2320,6 +2317,9 @@
                         g_warning ("to prevent damage, now forcing suspend");
                         do_power_action_type (manager, GSD_POWER_ACTION_SUSPEND);
                         return;
+                } else {
+                        /* maybe lock the screen if the lid is closed */
+                        lock_screensaver (manager);
                 }
         }
 
@@ -3559,7 +3559,31 @@
                         UpSleepKind sleep_kind,
                         GsdPowerManager *manager)
 {
-        lock_screensaver (manager);
+        gboolean do_lock;
+
+        do_lock = g_settings_get_boolean (manager->priv->settings_screensaver,
+                                          "ubuntu-lock-on-suspend");
+        if (!do_lock)
+                return;
+
+        if (manager->priv->screensaver_proxy != NULL) {
+                g_debug ("doing gnome-screensaver lock");
+                g_dbus_proxy_call (manager->priv->screensaver_proxy,
+                                   "Lock",
+                                   NULL, G_DBUS_CALL_FLAGS_NONE, -1,
+                                   NULL, NULL, NULL);
+        } else {
+                /* connect to the screensaver first */
+                g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+                                          G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                                          NULL,
+                                          GS_DBUS_NAME,
+                                          GS_DBUS_PATH,
+                                          GS_DBUS_INTERFACE,
+                                          NULL,
+                                          sleep_cb_screensaver_proxy_ready_cb,
+                                          manager);
+        }
 }
 
 static void
