← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-session/better-locking into lp:indicator-session

 

Ted Gould has proposed merging lp:~ted/indicator-session/better-locking into lp:indicator-session.

    Requested reviews:
    Indicator Applet Developers (indicator-applet-developers)
Related bugs:
  #444931 indicator-session executes another suspend procedure than gnome-power-manager
  https://bugs.launchpad.net/bugs/444931

-- 
https://code.launchpad.net/~ted/indicator-session/better-locking/+merge/13010
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file 'src/Makefile.am'
--- src/Makefile.am	2009-09-24 17:09:22 +0000
+++ src/Makefile.am	2009-10-07 17:25:21 +0000
@@ -112,7 +112,12 @@
 # Users Stuff
 ###############
 
-indicator_users_service_SOURCES = users-service.c users-service-dbus.c users-service-marshal.c
+indicator_users_service_SOURCES = \
+	lock-helper.c \
+	lock-helper.h \
+	users-service.c \
+	users-service-dbus.c \
+	users-service-marshal.c
 indicator_users_service_CFLAGS = $(USERSSERVICE_CFLAGS) -Wall -Werror
 indicator_users_service_LDADD = $(USERSSERVICE_LIBS)
 
@@ -120,7 +125,11 @@
 # Session Stuff
 #################
 
-indicator_session_service_SOURCES = session-service.c gtk-dialog/gconf-helper.c
+indicator_session_service_SOURCES = \
+	lock-helper.c \
+	lock-helper.h \
+	session-service.c \
+	gtk-dialog/gconf-helper.c
 indicator_session_service_CFLAGS = $(SESSIONSERVICE_CFLAGS) $(GCONF_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" -Wall -Werror
 indicator_session_service_LDADD = $(SESSIONSERVICE_LIBS) $(GCONF_LIBS)
 

=== added file 'src/lock-helper.c'
--- src/lock-helper.c	1970-01-01 00:00:00 +0000
+++ src/lock-helper.c	2009-10-07 17:25:21 +0000
@@ -0,0 +1,326 @@
+/*
+A small helper for locking the screen.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+    Ted Gould <ted@xxxxxxxxxxxxx>
+
+This program is free software: you can redistribute it and/or modify it 
+under the terms of the GNU General Public License version 3, as published 
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but 
+WITHOUT ANY WARRANTY; without even the implied warranties of 
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
+PURPOSE.  See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along 
+with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <dbus/dbus-glib.h>
+#include "lock-helper.h"
+
+static DBusGProxy * gss_proxy = NULL;
+static GMainLoop * gss_mainloop = NULL;
+static guint cookie = 0;
+static DBusGProxyCall * cookie_call = NULL;
+
+static DBusGProxy * gdm_settings_proxy = NULL;
+static gboolean gdm_auto_login = FALSE;
+static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
+
+static gboolean is_guest = FALSE;
+
+static gdm_autologin_cb_t gdm_autologin_cb = NULL;
+
+/* Checks to see if there is an error and reports
+   it.  Not much else we can do. */
+static void
+unthrottle_return (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
+{
+	GError * error = NULL;
+	dbus_g_proxy_end_call(proxy, call, &error,
+	                      G_TYPE_INVALID);
+
+	if (error != NULL) {
+		g_warning("Unable to unthrottle: %s", error->message);
+	}
+	return;
+}
+
+/* Sends an unthrottle if we're throttled. */
+void
+screensaver_unthrottle (void)
+{
+	g_return_if_fail(cookie != 0);
+
+	dbus_g_proxy_begin_call(gss_proxy, "UnThrottle",
+	                        unthrottle_return, NULL,
+	                        NULL,
+	                        G_TYPE_UINT, cookie,
+	                        G_TYPE_INVALID);
+
+	cookie = 0;
+	return;
+}
+
+/* Gets there return cookie from the throttle command
+   and sets things valid */
+static void
+throttle_return (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
+{
+	GError * error = NULL;
+	cookie_call = NULL;
+
+	dbus_g_proxy_end_call(proxy, call, &error,
+	                      G_TYPE_UINT, &cookie,
+	                      G_TYPE_INVALID);
+
+	if (error != NULL) {
+		g_warning("Unable to throttle the screensaver: %s", error->message);
+		return;
+	}
+
+
+	if (cookie == 0) {
+		g_warning("We didn't get a throttle cookie!");
+	}
+
+	return;
+}
+
+/* Throttling the screensaver by using the screen saver
+   command. */
+void
+screensaver_throttle (gchar * reason)
+{
+	g_return_if_fail(cookie_call == NULL);
+	g_return_if_fail(will_lock_screen());
+
+	if (cookie != 0) {
+		screensaver_unthrottle();
+	}
+
+	cookie_call = dbus_g_proxy_begin_call(gss_proxy, "Throttle",
+	                                      throttle_return, NULL,
+	                                      NULL,
+	                                      G_TYPE_STRING, "Session Menu",
+	                                      G_TYPE_STRING, reason,
+	                                      G_TYPE_INVALID);
+
+	return;
+}
+
+/* Setting up a call back */
+void
+lock_screen_gdm_cb_set (gdm_autologin_cb_t cb)
+{
+	if (gdm_autologin_cb) {
+		g_warning("Already had a callback, setting up a new one...");
+	}
+
+	gdm_autologin_cb = cb;
+	return;
+}
+
+/* This is our logic on whether the screen should be locked
+   or not.  It effects everything else. */
+gboolean
+will_lock_screen (void)
+{
+	if (gdm_auto_login) {
+		return FALSE;
+	}
+	if (is_guest) {
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+/* Respond to the signal of autologin changing to see if the
+   setting for timed login changes. */
+static void
+gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)
+{
+	if (g_strcmp0(value, gdm_auto_login_string)) {
+		/* This is not a setting that we care about,
+		   there is only one. */
+		return;
+	}
+	g_debug("GDM Settings change: %s", new);
+
+	if (g_strcmp0(new, "true") == 0) {
+		gdm_auto_login = TRUE;
+	} else {
+		gdm_auto_login = FALSE;
+	}
+
+	if (gdm_autologin_cb != NULL) {
+		gdm_autologin_cb();
+	}
+
+	return;
+}
+
+/* Get back the data from querying to see if there is auto
+   login enabled in GDM */
+static void
+gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
+{
+	GError * error = NULL;
+	gchar * value = NULL;
+
+	if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
+		g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
+		g_error_free(error);
+		return;
+	}
+
+	g_return_if_fail(value != NULL);
+	gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
+
+	return;
+}
+
+/* Sets up the proxy and queries for the setting to know
+   whether we're doing an autologin. */
+static void
+build_gdm_proxy (void)
+{
+	g_return_if_fail(gdm_settings_proxy == NULL);
+
+	/* Grab the system bus */
+	DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
+	g_return_if_fail(bus != NULL);
+
+	/* Get the settings proxy */
+	gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
+	                                                     "org.gnome.DisplayManager",
+	                                                     "/org/gnome/DisplayManager/Settings",
+	                                                     "org.gnome.DisplayManager.Settings", NULL);
+	g_return_if_fail(gdm_settings_proxy != NULL);
+
+	/* Signal for value changed */
+	dbus_g_proxy_add_signal(gdm_settings_proxy,
+	                        "ValueChanged",
+	                        G_TYPE_STRING,
+	                        G_TYPE_STRING,
+	                        G_TYPE_STRING,
+	                        G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(gdm_settings_proxy,
+	                            "ValueChanged",
+	                            G_CALLBACK(gdm_settings_change),
+	                            NULL,
+	                            NULL);
+
+	/* Start to get the initial value */
+	dbus_g_proxy_begin_call(gdm_settings_proxy,
+	                        "GetValue",
+	                        gdm_get_autologin,
+	                        NULL,
+	                        NULL,
+	                        G_TYPE_STRING,
+	                        gdm_auto_login_string,
+	                        G_TYPE_INVALID);
+
+	return;
+}
+
+/* When the screensave go active, if we've got a mainloop
+   running we should quit it. */
+static void
+gss_active_changed (DBusGProxy * proxy, gboolean active, gpointer data)
+{
+	if (active && gss_mainloop != NULL) {
+		g_main_loop_quit(gss_mainloop);
+	}
+
+	return;
+}
+
+/* Build the gss proxy and set up it's signals */
+void
+build_gss_proxy (void)
+{
+	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+	g_return_if_fail(session_bus != NULL);
+
+	gss_proxy = dbus_g_proxy_new_for_name_owner(session_bus,
+	                                            "org.gnome.ScreenSaver",
+	                                            "/",
+	                                            "org.gnome.ScreenSaver",
+	                                            NULL);
+	g_return_if_fail(gss_proxy != NULL);
+
+	dbus_g_proxy_add_signal(gss_proxy, "ActiveChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(gss_proxy, "ActiveChanged", G_CALLBACK(gss_active_changed), NULL, NULL);
+
+	return;
+}
+
+/* This is a timeout, we only want to wait for the screen to
+   lock for a little bit, but not forever. */
+static gboolean
+activate_timeout (gpointer data)
+{
+	guint * address = (guint *)data;
+	*address = 0;
+
+	if (gss_mainloop != NULL) {
+		g_main_loop_quit(gss_mainloop);
+	}
+	
+	return FALSE;
+}
+
+/* A fun little function to actually lock the screen.  If,
+   that's what you want, let's do it! */
+void
+lock_screen (DbusmenuMenuitem * mi, gpointer data)
+{
+	g_debug("Lock Screen");
+	if (!will_lock_screen()) {
+		g_debug("\tGDM set to autologin, blocking lock");
+		return;
+	}
+
+	g_return_if_fail(gss_proxy != NULL);
+
+	dbus_g_proxy_call_no_reply(gss_proxy,
+	                           "Lock",
+	                           G_TYPE_INVALID,
+	                           G_TYPE_INVALID);
+
+	if (gss_mainloop == NULL) {
+		gss_mainloop = g_main_loop_new(NULL, FALSE);
+	}
+
+	guint timer = g_timeout_add_seconds(1, activate_timeout, &timer);
+
+	g_main_loop_run(gss_mainloop);
+
+	if (timer != 0) {
+		g_source_remove(timer);
+	}
+
+	return;
+}
+
+/* Do what it takes to make the lock screen function work
+   and be happy. */
+gboolean
+lock_screen_setup (gpointer data)
+{
+	if (!g_strcmp0(g_get_user_name(), "guest")) {
+		is_guest = TRUE;
+	}
+
+	build_gdm_proxy();
+	build_gss_proxy();
+
+	return FALSE;
+}
+

=== added file 'src/lock-helper.h'
--- src/lock-helper.h	1970-01-01 00:00:00 +0000
+++ src/lock-helper.h	2009-10-07 17:25:21 +0000
@@ -0,0 +1,37 @@
+/*
+A small helper for locking the screen.
+
+Copyright 2009 Canonical Ltd.
+
+Authors:
+    Ted Gould <ted@xxxxxxxxxxxxx>
+
+This program is free software: you can redistribute it and/or modify it 
+under the terms of the GNU General Public License version 3, as published 
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but 
+WITHOUT ANY WARRANTY; without even the implied warranties of 
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
+PURPOSE.  See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along 
+with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef LOCK_HELPER_H__
+#define LOCK_HELPER_H__
+
+#include <libdbusmenu-glib/menuitem.h>
+
+typedef void (*gdm_autologin_cb_t) (void);
+
+void screensaver_throttle (gchar * reason);
+void screensaver_unthrottle (void);
+
+gboolean will_lock_screen (void);
+void lock_screen (DbusmenuMenuitem * mi, gpointer data);
+gboolean lock_screen_setup (gpointer data);
+void lock_screen_gdm_cb_set (gdm_autologin_cb_t cb);
+
+#endif /* LOCK_HELPER_H__ */

=== modified file 'src/session-service.c'
--- src/session-service.c	2009-09-24 16:12:56 +0000
+++ src/session-service.c	2009-10-07 17:25:21 +0000
@@ -35,6 +35,8 @@
 
 #include "gtk-dialog/gconf-helper.h"
 
+#include "lock-helper.h"
+
 #define DKP_ADDRESS    "org.freedesktop.DeviceKit.Power"
 #define DKP_OBJECT     "/org/freedesktop/DeviceKit/Power"
 #define DKP_INTERFACE  "org.freedesktop.DeviceKit.Power"
@@ -44,10 +46,6 @@
 static DBusGProxy * dkp_main_proxy = NULL;
 static DBusGProxy * dkp_prop_proxy = NULL;
 
-static DBusGProxy * gdm_settings_proxy = NULL;
-static gboolean gdm_auto_login = FALSE;
-static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
-
 static DBusGProxyCall * suspend_call = NULL;
 static DBusGProxyCall * hibernate_call = NULL;
 
@@ -57,120 +55,12 @@
 static DbusmenuMenuitem * restart_mi = NULL;
 static DbusmenuMenuitem * shutdown_mi = NULL;
 
-
-/* Respond to the signal of autologin changing to see if the
-   setting for timed login changes. */
-static void
-gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)
-{
-	if (g_strcmp0(value, gdm_auto_login_string)) {
-		/* This is not a setting that we care about,
-		   there is only one. */
-		return;
-	}
-	g_debug("GDM Settings change: %s", new);
-
-	if (g_strcmp0(new, "true") == 0) {
-		gdm_auto_login = TRUE;
-	} else {
-		gdm_auto_login = FALSE;
-	}
-
-	return;
-}
-
-/* Get back the data from querying to see if there is auto
-   login enabled in GDM */
-static void
-gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
-{
-	GError * error = NULL;
-	gchar * value = NULL;
-
-	if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
-		g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
-		g_error_free(error);
-		return;
-	}
-
-	g_return_if_fail(value != NULL);
-	gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
-
-	return;
-}
-
-/* Sets up the proxy and queries for the setting to know
-   whether we're doing an autologin. */
-static gboolean
-build_gdm_proxy (gpointer null_data)
-{
-	g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE);
-
-	/* Grab the system bus */
-	DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
-	g_return_val_if_fail(bus != NULL, FALSE);
-
-	/* Get the settings proxy */
-	gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
-	                                                     "org.gnome.DisplayManager",
-	                                                     "/org/gnome/DisplayManager/Settings",
-	                                                     "org.gnome.DisplayManager.Settings", NULL);
-	g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE);
-
-	/* Signal for value changed */
-	dbus_g_proxy_add_signal(gdm_settings_proxy,
-	                        "ValueChanged",
-	                        G_TYPE_STRING,
-	                        G_TYPE_STRING,
-	                        G_TYPE_STRING,
-	                        G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal(gdm_settings_proxy,
-	                            "ValueChanged",
-	                            G_CALLBACK(gdm_settings_change),
-	                            NULL,
-	                            NULL);
-
-	/* Start to get the initial value */
-	dbus_g_proxy_begin_call(gdm_settings_proxy,
-	                        "GetValue",
-	                        gdm_get_autologin,
-	                        NULL,
-	                        NULL,
-	                        G_TYPE_STRING,
-	                        gdm_auto_login_string,
-	                        G_TYPE_INVALID);
-
-	return FALSE;
-}
-
-/* A fun little function to actually lock the screen.  If,
-   that's what you want, let's do it! */
-static void
-lock_screen (void)
-{
-	g_debug("Lock Screen");
-	if (gdm_auto_login) {
-		g_debug("\tGDM set to autologin, blocking lock");
-		return;
-	}
-
-	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
-	g_return_if_fail(session_bus != NULL);
-
-	DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus,
-	                                                     "org.gnome.ScreenSaver",
-	                                                     "/",
-	                                                     "org.gnome.ScreenSaver",
-	                                                     NULL);
-	g_return_if_fail(proxy != NULL);
-
-	dbus_g_proxy_call_no_reply(proxy,
-	                           "Lock",
-	                           G_TYPE_INVALID,
-	                           G_TYPE_INVALID);
-
-	g_object_unref(proxy);
-
+/* A return from the command to sleep the system.  Make sure
+   that we unthrottle the screensaver. */
+static void
+sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
+{
+	screensaver_unthrottle();
 	return;
 }
 
@@ -185,12 +75,15 @@
 		g_warning("Can not %s as no DeviceKit Power Proxy", type);
 	}
 
-	lock_screen();
+	screensaver_throttle(type);
+	lock_screen(NULL, NULL);
 
-	dbus_g_proxy_call_no_reply(dkp_main_proxy,
-	                           type,
-	                           G_TYPE_INVALID,
-	                           G_TYPE_INVALID);
+	dbus_g_proxy_begin_call(dkp_main_proxy,
+	                        type,
+	                        sleep_response,
+	                        NULL,
+	                        NULL,
+	                        G_TYPE_INVALID);
 
 	return;
 }
@@ -427,7 +320,7 @@
         return 1;
     }   
 
-	g_idle_add(build_gdm_proxy, NULL);
+	g_idle_add(lock_screen_setup, NULL);
 
     root_menuitem = dbusmenu_menuitem_new();
 	g_debug("Root ID: %d", dbusmenu_menuitem_get_id(root_menuitem));

=== modified file 'src/users-service.c'
--- src/users-service.c	2009-10-05 20:38:14 +0000
+++ src/users-service.c	2009-10-07 17:25:21 +0000
@@ -35,6 +35,7 @@
 
 #include "dbus-shared-names.h"
 #include "users-service-dbus.h"
+#include "lock-helper.h"
 
 #define GUEST_SESSION_LAUNCHER  "/usr/share/gdm/guest-session/guest-session-launch"
 
@@ -54,11 +55,6 @@
 static UsersServiceDbus  *dbus_interface = NULL;
 
 static DbusmenuMenuitem  *lock_menuitem = NULL;
-static gboolean is_guest = FALSE;
-
-static DBusGProxy * gdm_settings_proxy = NULL;
-static gboolean gdm_auto_login = FALSE;
-static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable";
 
 static gint   count;
 static GList *users;
@@ -66,94 +62,15 @@
 /* Respond to the signal of autologin changing to see if the
    setting for timed login changes. */
 static void
-gdm_settings_change (DBusGProxy * proxy, const gchar * value, const gchar * old, const gchar * new, gpointer data)
+gdm_settings_change (void)
 {
-	if (g_strcmp0(value, gdm_auto_login_string)) {
-		/* This is not a setting that we care about,
-		   there is only one. */
-		return;
-	}
-	g_debug("GDM Settings change: %s", new);
-
-	if (g_strcmp0(new, "true") == 0) {
-		gdm_auto_login = TRUE;
+	if (!will_lock_screen()) {
+		dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");
 	} else {
-		gdm_auto_login = FALSE;
-	}
-
-	if (lock_menuitem != NULL) {
-		if (gdm_auto_login || is_guest) {
-			dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");
-		} else {
-			dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");
-		}
-	}
-
-	return;
-}
-
-/* Get back the data from querying to see if there is auto
-   login enabled in GDM */
-static void
-gdm_get_autologin (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data)
-{
-	GError * error = NULL;
-	gchar * value = NULL;
-
-	if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_STRING, &value, G_TYPE_INVALID)) {
-		g_warning("Unable to get autologin setting: %s", error != NULL ? error->message : "null");
-		g_error_free(error);
-		return;
-	}
-
-	g_return_if_fail(value != NULL);
-	gdm_settings_change(proxy, gdm_auto_login_string, NULL, value, NULL);
-
-	return;
-}
-
-/* Sets up the proxy and queries for the setting to know
-   whether we're doing an autologin. */
-static gboolean
-build_gdm_proxy (gpointer null_data)
-{
-	g_return_val_if_fail(gdm_settings_proxy == NULL, FALSE);
-
-	/* Grab the system bus */
-	DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
-	g_return_val_if_fail(bus != NULL, FALSE);
-
-	/* Get the settings proxy */
-	gdm_settings_proxy = dbus_g_proxy_new_for_name_owner(bus,
-	                                                     "org.gnome.DisplayManager",
-	                                                     "/org/gnome/DisplayManager/Settings",
-	                                                     "org.gnome.DisplayManager.Settings", NULL);
-	g_return_val_if_fail(gdm_settings_proxy != NULL, FALSE);
-
-	/* Signal for value changed */
-	dbus_g_proxy_add_signal(gdm_settings_proxy,
-	                        "ValueChanged",
-	                        G_TYPE_STRING,
-	                        G_TYPE_STRING,
-	                        G_TYPE_STRING,
-	                        G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal(gdm_settings_proxy,
-	                            "ValueChanged",
-	                            G_CALLBACK(gdm_settings_change),
-	                            NULL,
-	                            NULL);
-
-	/* Start to get the initial value */
-	dbus_g_proxy_begin_call(gdm_settings_proxy,
-	                        "GetValue",
-	                        gdm_get_autologin,
-	                        NULL,
-	                        NULL,
-	                        G_TYPE_STRING,
-	                        gdm_auto_login_string,
-	                        G_TYPE_INVALID);
-
-	return FALSE;
+		dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");
+	}
+
+	return;
 }
 
 static gboolean
@@ -222,37 +139,6 @@
 	return;
 }
 
-/* A fun little function to actually lock the screen.  If,
-   that's what you want, let's do it! */
-static void
-lock_screen (DbusmenuMenuitem * mi, gpointer data)
-{
-	g_debug("Lock Screen");
-	if (gdm_auto_login) {
-		g_debug("\tGDM set to autologin, blocking lock");
-		return;
-	}
-
-	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
-	g_return_if_fail(session_bus != NULL);
-
-	DBusGProxy * proxy = dbus_g_proxy_new_for_name_owner(session_bus,
-	                                                     "org.gnome.ScreenSaver",
-	                                                     "/",
-	                                                     "org.gnome.ScreenSaver",
-	                                                     NULL);
-	g_return_if_fail(proxy != NULL);
-
-	dbus_g_proxy_call_no_reply(proxy,
-	                           "Lock",
-	                           G_TYPE_INVALID,
-	                           G_TYPE_INVALID);
-
-	g_object_unref(proxy);
-
-	return;
-}
-
 static void
 activate_user_session (DbusmenuMenuitem *mi, gpointer user_data)
 {
@@ -292,7 +178,7 @@
   dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen"));
   g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL);
   dbusmenu_menuitem_child_append(root, lock_menuitem);
-  if (gdm_auto_login || is_guest) {
+  if (!will_lock_screen()) {
     dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "false");
   } else {
     dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, "true");
@@ -410,11 +296,8 @@
         return 1;
     }
 
-	if (!g_strcmp0(g_get_user_name(), "guest")) {
-		is_guest = TRUE;
-	}
-
-	g_idle_add(build_gdm_proxy, NULL);
+	g_idle_add(lock_screen_setup, NULL);
+	lock_screen_gdm_cb_set(gdm_settings_change);
 
     dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL);
 


Follow ups