diff options
-rw-r--r-- | src/lock-helper.c | 79 | ||||
-rw-r--r-- | src/lock-helper.h | 3 |
2 files changed, 82 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. 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); |