From e9bce071011fd10360934dcc09cdabff2b9880ce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 19:49:57 -0400 Subject: Creating the lock helper files. --- src/lock-helper.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/lock-helper.c (limited to 'src/lock-helper.c') diff --git a/src/lock-helper.c b/src/lock-helper.c new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From f6fc44d8020fb20200b961359ad581dade9e231b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 20:23:17 -0400 Subject: Moving arround the lock screen code so that it's in a helper. --- src/lock-helper.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) (limited to 'src/lock-helper.c') 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 +#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; +} + -- cgit v1.2.3 From d6c6861081cd6133fd605bae27a9c199b41b1555 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 20:28:06 -0400 Subject: Setting up the callback --- src/lock-helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lock-helper.c') diff --git a/src/lock-helper.c b/src/lock-helper.c index 0df840e..e717968 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -10,6 +10,18 @@ static gboolean is_guest = FALSE; static gdm_autologin_cb_t gdm_autologin_cb = NULL; +/* 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 -- cgit v1.2.3 From b90777f78569b41e8ef6cdd065fc44a2ab4bd19b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Oct 2009 10:31:26 -0400 Subject: Building a GSS proxy and setting up a signal to it. Then when we lock, we drop to a mainloop and wait for the screensaver to activate. --- src/lock-helper.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 11 deletions(-) (limited to 'src/lock-helper.c') diff --git a/src/lock-helper.c b/src/lock-helper.c index e717968..b2ae7f0 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -2,6 +2,9 @@ #include #include "lock-helper.h" +static DBusGProxy * gss_proxy = NULL; +static GMainLoop * gss_mainloop = NULL; + static DBusGProxy * gdm_settings_proxy = NULL; static gboolean gdm_auto_login = FALSE; static const gchar * gdm_auto_login_string = "daemon/AutomaticLoginEnable"; @@ -126,6 +129,53 @@ build_gdm_proxy (void) 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 @@ -137,26 +187,30 @@ lock_screen (DbusmenuMenuitem * mi, gpointer data) return; } - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - g_return_if_fail(session_bus != NULL); + g_return_if_fail(gss_proxy != 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, + dbus_g_proxy_call_no_reply(gss_proxy, "Lock", G_TYPE_INVALID, G_TYPE_INVALID); - g_object_unref(proxy); + 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) { @@ -165,6 +219,7 @@ lock_screen_setup (gpointer data) } build_gdm_proxy(); + build_gss_proxy(); return FALSE; } -- cgit v1.2.3 From 18d5a15229b093fbecc358f6883ae9811d5c97d6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Oct 2009 10:42:06 -0400 Subject: Copyright headers --- src/lock-helper.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/lock-helper.c') diff --git a/src/lock-helper.c b/src/lock-helper.c index b2ae7f0..5f32c0c 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -1,3 +1,23 @@ +/* +A small helper for locking the screen. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +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 . +*/ #include #include "lock-helper.h" -- cgit v1.2.3 From 22a02f891220f637ec1b451b517f25b69cbe8b01 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Oct 2009 11:57:52 -0400 Subject: Adding throttle and unthrottle functions --- src/lock-helper.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'src/lock-helper.c') diff --git a/src/lock-helper.c b/src/lock-helper.c index 5f32c0c..b202b9d 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -24,6 +24,8 @@ with this program. If not, see . 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; @@ -33,6 +35,83 @@ 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, reason, + G_TYPE_INVALID); + + return; +} + /* Setting up a call back */ void lock_screen_gdm_cb_set (gdm_autologin_cb_t cb) -- cgit v1.2.3 From 0547aa3fd537737ede2d22a3cc164e31df97b103 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Oct 2009 13:10:38 -0400 Subject: Oops, forgot to say who we were. --- src/lock-helper.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/lock-helper.c') diff --git a/src/lock-helper.c b/src/lock-helper.c index b202b9d..0bdec6c 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -106,6 +106,7 @@ screensaver_throttle (gchar * reason) 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); -- cgit v1.2.3