aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lock-helper.c159
-rw-r--r--src/lock-helper.h12
-rw-r--r--src/users-service.c134
3 files changed, 180 insertions, 125 deletions
diff --git a/src/lock-helper.c b/src/lock-helper.c
index e69de29..0df840e 100644
--- a/src/lock-helper.c
+++ b/src/lock-helper.c
@@ -0,0 +1,159 @@
+
+#include <dbus/dbus-glib.h>
+#include "lock-helper.h"
+
+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;
+
+/* 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;
+}
+
+/* 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;
+ }
+
+ 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;
+}
+
+gboolean
+lock_screen_setup (gpointer data)
+{
+ if (!g_strcmp0(g_get_user_name(), "guest")) {
+ is_guest = TRUE;
+ }
+
+ build_gdm_proxy();
+
+ return FALSE;
+}
+
diff --git a/src/lock-helper.h b/src/lock-helper.h
index e69de29..5103242 100644
--- a/src/lock-helper.h
+++ b/src/lock-helper.h
@@ -0,0 +1,12 @@
+#ifndef LOCK_HELPER_H__
+#define LOCK_HELPER_H__
+
+#include <libdbusmenu-glib/menuitem.h>
+
+typedef void (*gdm_autologin_cb_t) (void);
+
+gboolean will_lock_screen (void);
+void lock_screen (DbusmenuMenuitem * mi, gpointer data);
+gboolean lock_screen_setup (gpointer data);
+
+#endif /* LOCK_HELPER_H__ */
diff --git a/src/users-service.c b/src/users-service.c
index 5a189c8..576574b 100644
--- a/src/users-service.c
+++ b/src/users-service.c
@@ -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,107 +55,25 @@ static GMainLoop *mainloop = NULL;
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;
+#if 0
/* 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 (gboolean autologin)
{
- 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 (autologin) {
+ 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");
- }
+ 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;
-}
+#endif
static gboolean
check_guest_session (void)
@@ -222,37 +141,6 @@ activate_new_session (DbusmenuMenuitem * mi, gpointer user_data)
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 +180,7 @@ rebuild_items (DbusmenuMenuitem *root,
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 +298,7 @@ main (int argc, char ** argv)
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);
dbus_interface = g_object_new (USERS_SERVICE_DBUS_TYPE, NULL);