diff options
author | Anton V. Boyarshinov <[email protected]> | 2013-04-08 18:33:55 +0400 |
---|---|---|
committer | Anton V. Boyarshinov <[email protected]> | 2013-04-08 18:33:55 +0400 |
commit | b19ce03f92d310d8fef5781ee3384572e6ae10f8 (patch) | |
tree | d88a75f60cf25e12189f0595828c0cb7c2606d77 /src/gpm-button.c | |
parent | fd2ea04942aa4459eefecac1807e4b3107266e76 (diff) | |
download | mate-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-button.c')
-rw-r--r-- | src/gpm-button.c | 56 |
1 files changed, 56 insertions, 0 deletions
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) |