summaryrefslogtreecommitdiff
path: root/src/gpm-control.c
diff options
context:
space:
mode:
authorAnton V. Boyarshinov <[email protected]>2013-04-08 18:33:55 +0400
committerAnton V. Boyarshinov <[email protected]>2013-04-08 18:33:55 +0400
commitb19ce03f92d310d8fef5781ee3384572e6ae10f8 (patch)
treed88a75f60cf25e12189f0595828c0cb7c2606d77 /src/gpm-control.c
parentfd2ea04942aa4459eefecac1807e4b3107266e76 (diff)
downloadmate-power-manager-b19ce03f92d310d8fef5781ee3384572e6ae10f8.tar.bz2
mate-power-manager-b19ce03f92d310d8fef5781ee3384572e6ae10f8.tar.xz
add logind sleep ability
With upower 0.9.20, sleep and hybernate functions of upower declared deprecated. All applications should use logind for sleep/hybernate. So, there is an implementation of logind-powered sleep for mpm.
Diffstat (limited to 'src/gpm-control.c')
-rw-r--r--src/gpm-control.c84
1 files changed, 82 insertions, 2 deletions
diff --git a/src/gpm-control.c b/src/gpm-control.c
index 105a6d1..b118af1 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -166,9 +166,14 @@ gpm_control_suspend (GpmControl *control, GError **error)
gboolean lock_mate_keyring;
MateKeyringResult keyres;
#endif /* WITH_KEYRING */
+#ifdef WITH_SYSTEMD_SLEEP
+ GError *dbus_error = NULL;
+ DBusGProxy *proxy;
+ GVariant *res;
+#endif
screensaver = gpm_screensaver_new ();
-
+#ifndef WITH_SYSTEMD_SLEEP
g_object_get (control->priv->client,
"can-suspend", &allowed,
NULL);
@@ -177,6 +182,7 @@ gpm_control_suspend (GpmControl *control, GError **error)
g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
goto out;
}
+#endif
#ifdef WITH_KEYRING
/* we should perhaps lock keyrings when sleeping #375681 */
@@ -202,7 +208,41 @@ gpm_control_suspend (GpmControl *control, GError **error)
egg_debug ("emitting sleep");
g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND);
+#ifdef WITH_SYSTEMD_SLEEP
+ /* sleep via logind */
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ NULL,
+ &dbus_error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", dbus_error->message);
+ fprintf(stderr,"Error connecting to dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ return -1;
+ }
+ g_dbus_proxy_call_sync (proxy, "Suspend",
+ g_variant_new( "(b)",FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &dbus_error
+ );
+ if (dbus_error != NULL ) {
+ egg_error ("Error in dbus - %s", dbus_error->message);
+ fprintf(stderr,"Error connecting to dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ }
+ else {
+ ret = TRUE;
+ }
+ g_object_unref(proxy);
+#else
ret = up_client_suspend_sync (control->priv->client, NULL, error);
+#endif
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND);
@@ -239,8 +279,14 @@ gpm_control_hibernate (GpmControl *control, GError **error)
MateKeyringResult keyres;
#endif /* WITH_KEYRING */
+#ifdef WITH_SYSTEMD_SLEEP
+ GError *dbus_error = NULL;
+ DBusGProxy *proxy;
+#endif
+
screensaver = gpm_screensaver_new ();
+#ifndef WITH_SYSTEMD_SLEEP
g_object_get (control->priv->client,
"can-hibernate", &allowed,
NULL);
@@ -249,6 +295,7 @@ gpm_control_hibernate (GpmControl *control, GError **error)
g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate");
goto out;
}
+#endif
#ifdef WITH_KEYRING
/* we should perhaps lock keyrings when sleeping #375681 */
@@ -274,8 +321,41 @@ gpm_control_hibernate (GpmControl *control, GError **error)
egg_debug ("emitting sleep");
g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_HIBERNATE);
+#ifdef WITH_SYSTEMD_SLEEP
+ /* sleep via logind */
+ fprintf(stderr,"logind suspend\n");
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ NULL,
+ &dbus_error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", dbus_error->message);
+ fprintf(stderr,"Error connecting to dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ return -1;
+ }
+ g_dbus_proxy_call_sync (proxy, "Hibernate",
+ g_variant_new( "(b)",FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &dbus_error
+ );
+ if (dbus_error != NULL ) {
+ egg_error ("Error in dbus - %s", dbus_error->message);
+ fprintf(stderr,"Error connecting to dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ }
+ else {
+ ret = TRUE;
+ }
+#else
ret = up_client_hibernate_sync (control->priv->client, NULL, error);
-
+#endif
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE);