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 ++++++++++++++++++++ src/lock-helper.h | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'src') 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" diff --git a/src/lock-helper.h b/src/lock-helper.h index 9a0571c..f9405ac 100644 --- a/src/lock-helper.h +++ b/src/lock-helper.h @@ -1,3 +1,24 @@ +/* +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 . +*/ + #ifndef LOCK_HELPER_H__ #define 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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lock-helper.h | 3 +++ 2 files changed, 82 insertions(+) (limited to 'src') 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) diff --git a/src/lock-helper.h b/src/lock-helper.h index f9405ac..b4a382e 100644 --- a/src/lock-helper.h +++ b/src/lock-helper.h @@ -26,6 +26,9 @@ with this program. If not, see . 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); -- cgit v1.2.3 From 1b12089eb7897608478ce4c3ab9b58361cbe991f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Oct 2009 12:56:05 -0400 Subject: Switching the sleep action to have a response so we can make sure to unthrottle the screensaver. --- src/session-service.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/session-service.c b/src/session-service.c index 3c0535f..a4240be 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -55,6 +55,14 @@ static DbusmenuMenuitem * logout_mi = NULL; static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; +/* 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; +} /* Let's put this machine to sleep, with some info on how it should sleep. */ @@ -67,12 +75,15 @@ sleep (DbusmenuMenuitem * mi, gpointer userdata) g_warning("Can not %s as no DeviceKit Power Proxy", type); } + 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; } -- cgit v1.2.3