From b36c93575f88bd5a045c36f3d8084608ae20879f Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 4 Jul 2013 23:11:54 +0200 Subject: drop --with-systemdsleep and move logind detection to runtime There is no need to bind the user to either systemd-logind or upower at build time. People can switch between init systems or run logind without systemd. --- src/gpm-button.c | 105 +++++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 57 deletions(-) (limited to 'src/gpm-button.c') diff --git a/src/gpm-button.c b/src/gpm-button.c index 4f9f171..3c70ca1 100644 --- a/src/gpm-button.c +++ b/src/gpm-button.c @@ -249,53 +249,6 @@ 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: **/ @@ -303,11 +256,53 @@ 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 + + GDBusProxy *proxy; + GVariant *res, *inner; + gboolean lid; + GError *error = NULL; + + if (LOGIND_RUNNING()) { + 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; + } + else { + return up_client_get_lid_is_closed (button->priv->client); + } } @@ -334,11 +329,7 @@ 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 + lid_is_closed = gpm_button_is_lid_closed(button); /* same state */ if (button->priv->lid_is_closed == lid_is_closed) -- cgit v1.2.1