summaryrefslogtreecommitdiff
path: root/src/gpm-control.c
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2013-05-02 03:01:36 -0700
committerStefano Karapetsas <[email protected]>2013-05-02 03:01:36 -0700
commitacbec2f8c4c0bf0227bd9e43c3c74cea0974ebc3 (patch)
treefe47686e67595d81cf6a67b606074abe8e1f2b52 /src/gpm-control.c
parente4710f05da0f07667f1392385864d32e79681549 (diff)
parent4963dd54412f8bdab61fd4537c753c064c2d3712 (diff)
downloadmate-power-manager-acbec2f8c4c0bf0227bd9e43c3c74cea0974ebc3.tar.bz2
mate-power-manager-acbec2f8c4c0bf0227bd9e43c3c74cea0974ebc3.tar.xz
Merge pull request #55 from boyarsh/master
Add ability to suspend/hibernate via logind
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..9f70f7f 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_debug ("Error in dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ ret = TRUE;
+ }
+ 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_debug ("Error in dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ ret = TRUE;
+ }
+ 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);