summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac22
-rw-r--r--src/gpm-button.c56
-rw-r--r--src/gpm-button.h3
-rw-r--r--src/gpm-control.c84
-rw-r--r--src/gpm-prefs-core.c94
5 files changed, 256 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 9a4e570..f4bd119 100644
--- a/configure.ac
+++ b/configure.ac
@@ -305,6 +305,27 @@ AM_CONDITIONAL(WITH_SYSTEMD_INHIBIT, test x$use_systemdinhibit = xyes)
AC_SUBST(WITH_SYSTEMD_INHIBIT)
dnl ---------------------------------------------------------------------------
+dnl systemd sleep
+dnl ---------------------------------------------------------------------------
+
+AC_ARG_WITH(systemdsleep,
+ AS_HELP_STRING([--with-systemdsleep],
+ [Use logind for suspend and hibernate instead of upower]),,
+ with_systemdsleep=auto)
+
+use_systemdsleep=no
+if test "x$with_systemdsleep" != "xno" ; then
+ PKG_CHECK_MODULES(SYSTEMD_SLEEP, libsystemd-login >= 195 libsystemd-daemon >= 195 , use_systemdsleep=yes, use_systemdsleep=no)
+
+ if test "x$use_systemdsleep" = "xyes"; then
+ AC_DEFINE(WITH_SYSTEMD_SLEEP, 1, [systemdsleeo support])
+ fi
+
+fi
+AM_CONDITIONAL(WITH_SYSTEMD_SLEEP, test x$use_systemdsleep = xyes)
+AC_SUBST(WITH_SYSTEMD_SLEEP)
+
+dnl ---------------------------------------------------------------------------
dnl - DocBook Documentation
dnl ---------------------------------------------------------------------------
AC_ARG_ENABLE(docbook-docs,
@@ -419,6 +440,7 @@ echo "
Self test support: ${have_tests}
Use libunique: ${enable_libunique}
systemd support: ${use_systemdinhibit}
+ systemd sleep support: ${use_systemdsleep}
Docbook support: ${enable_docbook_docs}
documentation dir: $DOCDIR
dbus-1 services dir: $DBUS_SERVICES_DIR
diff --git a/src/gpm-button.c b/src/gpm-button.c
index cb5cd50..4f9f171 100644
--- a/src/gpm-button.c
+++ b/src/gpm-button.c
@@ -249,6 +249,53 @@ gpm_button_class_init (GpmButtonClass *klass)
G_TYPE_NONE, 1, G_TYPE_STRING);
}
+#ifdef WITH_SYSTEMD_SLEEP
+gboolean gpm_button_get_lid_closed()
+{
+
+ GDBusProxy *proxy;
+ GVariant *res, *inner;
+ gboolean lid;
+GError *error = NULL;
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
+ "org.freedesktop.DBus.Properties",
+ NULL,
+ &error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return -1;
+ }
+
+ res = g_dbus_proxy_call_sync (proxy, "Get",
+ g_variant_new( "(ss)",
+ "org.freedesktop.UPower",
+ "LidIsClosed"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res, "(v)", &inner );
+ lid = g_variant_get_boolean(inner);
+ g_variant_unref (inner);
+ g_variant_unref (res);
+ return lid;
+ } else if (error != NULL ) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ }
+ g_object_unref(proxy);
+
+ return FALSE;
+}
+#endif
+
/**
* gpm_button_is_lid_closed:
**/
@@ -256,9 +303,14 @@ gboolean
gpm_button_is_lid_closed (GpmButton *button)
{
g_return_val_if_fail (GPM_IS_BUTTON (button), FALSE);
+#ifdef WITH_SYSTEMD_SLEEP
+ return gpm_button_get_lid_closed();
+#else
return up_client_get_lid_is_closed (button->priv->client);
+#endif
}
+
/**
* gpm_button_reset_time:
*
@@ -282,7 +334,11 @@ gpm_button_client_changed_cb (UpClient *client, GpmButton *button)
gboolean lid_is_closed;
/* get new state */
+#ifdef WITH_SYSTEMD_SLEEP
+ lid_is_closed = gpm_button_get_lid_closed();
+#else
lid_is_closed = up_client_get_lid_is_closed (button->priv->client);
+#endif
/* same state */
if (button->priv->lid_is_closed == lid_is_closed)
diff --git a/src/gpm-button.h b/src/gpm-button.h
index 8992007..7d60334 100644
--- a/src/gpm-button.h
+++ b/src/gpm-button.h
@@ -66,6 +66,9 @@ typedef struct
GType gpm_button_get_type (void);
GpmButton *gpm_button_new (void);
gboolean gpm_button_is_lid_closed (GpmButton *button);
+#ifdef WITH_SYSTEMD_SLEEP
+gboolean gpm_button_get_lid_closed ();
+#endif
gboolean gpm_button_reset_time (GpmButton *button);
G_END_DECLS
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);
diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c
index da985c1..e84d0b1 100644
--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -812,6 +812,11 @@ gpm_prefs_init (GpmPrefs *prefs)
GpmBrightness *brightness;
gboolean ret;
guint i;
+#ifdef WITH_SYSTEMD_SLEEP
+ GDBusProxy *proxy;
+ GVariant *res, *inner;
+ gchar * r;
+#endif
prefs->priv = GPM_PREFS_GET_PRIVATE (prefs);
@@ -823,10 +828,96 @@ gpm_prefs_init (GpmPrefs *prefs)
prefs->priv->can_shutdown = TRUE;
egg_console_kit_can_stop (prefs->priv->console, &prefs->priv->can_shutdown, NULL);
+#ifdef WITH_SYSTEMD_SLEEP
+ /* get values from logind */
+
+ prefs->priv->can_suspend = FALSE;
+ prefs->priv->can_hibernate = FALSE;
+ 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,
+ &error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return -1;
+ }
+ res = g_dbus_proxy_call_sync (proxy, "CanSuspend",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res,"(s)", &r);
+ prefs->priv->can_suspend = g_strcmp0(r,"yes")==0?TRUE:FALSE;
+ g_variant_unref (res);
+ } else if (error != NULL ) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ }
+
+ res = g_dbus_proxy_call_sync (proxy, "CanHibernate",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res,"(s)", &r);
+ prefs->priv->can_hibernate = g_strcmp0(r,"yes")==0?TRUE:FALSE;
+ g_variant_unref (res);
+ } else if (error != NULL ) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ }
+ g_object_unref(proxy);
+#else
/* get values from UpClient */
prefs->priv->can_suspend = up_client_get_can_suspend (prefs->priv->client);
prefs->priv->can_hibernate = up_client_get_can_hibernate (prefs->priv->client);
-
+#endif
+#ifdef WITH_SYSTEMD_SLEEP
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
+ "org.freedesktop.DBus.Properties",
+ NULL,
+ &error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return -1;
+ }
+
+ res = g_dbus_proxy_call_sync (proxy, "Get",
+ g_variant_new( "(ss)",
+ "org.freedesktop.UPower",
+ "LidIsPresent"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res, "(v)", &inner );
+ prefs->priv->has_button_lid = g_variant_get_boolean(inner);
+ g_variant_unref (inner);
+ g_variant_unref (res);
+ } else if (error != NULL ) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ }
+ g_object_unref(proxy);
+#else
#if UP_CHECK_VERSION(0,9,2)
prefs->priv->has_button_lid = up_client_get_lid_is_present (prefs->priv->client);
#else
@@ -834,6 +925,7 @@ gpm_prefs_init (GpmPrefs *prefs)
"lid-is-present", &prefs->priv->has_button_lid,
NULL);
#endif
+#endif
prefs->priv->has_button_suspend = TRUE;
/* find if we have brightness hardware */