summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/gpm-backlight-helper.c2
-rw-r--r--src/gpm-button.c105
-rw-r--r--src/gpm-button.h3
-rw-r--r--src/gpm-common.h4
-rw-r--r--src/gpm-control.c239
-rw-r--r--src/gpm-main.c8
-rw-r--r--src/gpm-manager.c48
-rw-r--r--src/gpm-prefs-core.c218
-rw-r--r--src/gpm-statistics.c5
10 files changed, 343 insertions, 290 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5fda8ee..a10b98b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -194,7 +194,6 @@ mate_power_manager_LDADD = \
$(LIBNOTIFY_LIBS) \
$(GPM_EXTRA_LIBS) \
$(UPOWER_LIBS) \
- $(SYSTEMD_INHIBIT_LIBS) \
-lm
mate_power_manager_CFLAGS = \
diff --git a/src/gpm-backlight-helper.c b/src/gpm-backlight-helper.c
index a9c0fd4..3ad78c7 100644
--- a/src/gpm-backlight-helper.c
+++ b/src/gpm-backlight-helper.c
@@ -175,8 +175,10 @@ main (gint argc, gchar *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
+#if !GLIB_CHECK_VERSION(2,36,0)
/* setup type system */
g_type_init ();
+#endif
context = g_option_context_new (NULL);
/* TRANSLATORS: tool that is used when copying profiles system-wide */
diff --git a/src/gpm-button.c b/src/gpm-button.c
index 4f9f171..1e38173 100644
--- a/src/gpm-button.c
+++ b/src/gpm-button.c
@@ -249,65 +249,60 @@ 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:
**/
gboolean
gpm_button_is_lid_closed (GpmButton *button)
{
+ GDBusProxy *proxy;
+ GVariant *res, *inner;
+ gboolean lid;
+ GError *error = NULL;
+
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
+
+ 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)
diff --git a/src/gpm-button.h b/src/gpm-button.h
index 7d60334..8992007 100644
--- a/src/gpm-button.h
+++ b/src/gpm-button.h
@@ -66,9 +66,6 @@ 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-common.h b/src/gpm-common.h
index ca4762c..6f712cb 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -24,8 +24,12 @@
#include <glib.h>
+#include <unistd.h>
+
G_BEGIN_DECLS
+#define LOGIND_RUNNING() (access("/run/systemd/seats/", F_OK) >= 0)
+
#define GPM_DBUS_SERVICE "org.mate.PowerManager"
#define GPM_DBUS_INTERFACE "org.mate.PowerManager"
#define GPM_DBUS_INTERFACE_BACKLIGHT "org.mate.PowerManager.Backlight"
diff --git a/src/gpm-control.c b/src/gpm-control.c
index 19b16db..8253336 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -86,6 +86,50 @@ gpm_control_error_quark (void)
}
/**
+ * gpm_manager_systemd_shutdown:
+ *
+ * Shutdown the system using systemd-logind.
+ *
+ * Return value: fd, -1 on error
+ **/
+static gboolean
+gpm_control_systemd_shutdown (void) {
+ GError *error = NULL;
+ GDBusProxy *proxy;
+
+ egg_debug ("Requesting systemd to shutdown");
+ 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 );
+ //append all our arguments
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_dbus_proxy_call_sync (proxy, "PowerOff",
+ g_variant_new( "(b)", FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error != NULL) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* gpm_control_shutdown:
* @control: This class instance
*
@@ -96,9 +140,14 @@ gpm_control_shutdown (GpmControl *control, GError **error)
{
gboolean ret;
EggConsoleKit *console;
- console = egg_console_kit_new ();
- ret = egg_console_kit_stop (console, error);
- g_object_unref (console);
+
+ if (LOGIND_RUNNING()) {
+ ret = gpm_control_systemd_shutdown ();
+ } else {
+ console = egg_console_kit_new ();
+ ret = egg_console_kit_stop (console, error);
+ g_object_unref (console);
+ }
return ret;
}
@@ -166,23 +215,22 @@ gpm_control_suspend (GpmControl *control, GError **error)
gboolean lock_gnome_keyring;
GnomeKeyringResult keyres;
#endif /* WITH_KEYRING */
-#ifdef WITH_SYSTEMD_SLEEP
+
GError *dbus_error = NULL;
- DBusGProxy *proxy;
- GVariant *res;
-#endif
+ GDBusProxy *proxy;
screensaver = gpm_screensaver_new ();
-#ifndef WITH_SYSTEMD_SLEEP
- g_object_get (control->priv->client,
- "can-suspend", &allowed,
- NULL);
- if (!allowed) {
- egg_debug ("cannot suspend as not allowed from policy");
- g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
- goto out;
+
+ if (LOGIND_RUNNING()) {
+ g_object_get (control->priv->client,
+ "can-suspend", &allowed,
+ NULL);
+ if (!allowed) {
+ egg_debug ("cannot suspend as not allowed from policy");
+ 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 */
@@ -208,40 +256,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);
- 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
+ if (LOGIND_RUNNING()) {
+ /* 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);
+ 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);
+ }
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND);
@@ -278,23 +327,21 @@ gpm_control_hibernate (GpmControl *control, GError **error)
GnomeKeyringResult keyres;
#endif /* WITH_KEYRING */
-#ifdef WITH_SYSTEMD_SLEEP
GError *dbus_error = NULL;
- DBusGProxy *proxy;
-#endif
+ GDBusProxy *proxy;
screensaver = gpm_screensaver_new ();
-#ifndef WITH_SYSTEMD_SLEEP
- g_object_get (control->priv->client,
- "can-hibernate", &allowed,
- NULL);
- if (!allowed) {
- egg_debug ("cannot hibernate as not allowed from policy");
- g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate");
- goto out;
+ if (!LOGIND_RUNNING()) {
+ g_object_get (control->priv->client,
+ "can-hibernate", &allowed,
+ NULL);
+ if (!allowed) {
+ egg_debug ("cannot hibernate as not allowed from policy");
+ 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 */
@@ -320,39 +367,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 */
- 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);
- 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
+ if (LOGIND_RUNNING()) {
+ /* 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);
+ 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);
+ }
+
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE);
diff --git a/src/gpm-main.c b/src/gpm-main.c
index 064ccf3..054cf3b 100644
--- a/src/gpm-main.c
+++ b/src/gpm-main.c
@@ -183,13 +183,14 @@ main (int argc, char *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
-#if GLIB_CHECK_VERSION(2,32,0)
-#else
+#if !GLIB_CHECK_VERSION(2,32,0)
if (! g_thread_supported ())
g_thread_init (NULL);
#endif
dbus_g_thread_init ();
+#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init ();
+#endif
context = g_option_context_new (N_("MATE Power Manager"));
/* TRANSLATORS: program name, a simple app to view pending updates */
@@ -203,8 +204,7 @@ main (int argc, char *argv[])
goto unref_program;
}
-#if GLIB_CHECK_VERSION(2,32,0)
-#else
+#if !GLIB_CHECK_VERSION(2,32,0)
if (!g_thread_supported ())
g_thread_init (NULL);
#endif
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 9b697b5..aeb5a31 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -33,11 +33,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
-#ifdef WITH_SYSTEMD_INHIBIT
-#include <systemd/sd-daemon.h>
-#endif /* WITH_SYSTEMD_INHIBIT */
#include <glib/gi18n.h>
+#include <gio/gunixfdlist.h>
#include <gtk/gtk.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
@@ -103,10 +101,8 @@ struct GpmManagerPrivate
NotifyNotification *notification_warning_low;
NotifyNotification *notification_discharging;
NotifyNotification *notification_fully_charged;
-#ifdef WITH_SYSTEMD_INHIBIT
gint32 systemd_inhibit;
GDBusProxy *systemd_inhibit_proxy;
-#endif
};
typedef enum {
@@ -908,8 +904,8 @@ gpm_manager_button_pressed_cb (GpmButton *button, const gchar *type, GpmManager
gchar *message;
egg_debug ("Button press event type=%s", type);
- /* ConsoleKit says we are not on active console */
- if (!egg_console_kit_is_active (manager->priv->console)) {
+ /* ConsoleKit/systemd say we are not on active console */
+ if (!LOGIND_RUNNING() && !egg_console_kit_is_active (manager->priv->console)) {
egg_debug ("ignoring as not on active console");
return;
}
@@ -1847,9 +1843,8 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm
g_timeout_add_seconds (1, gpm_manager_reset_just_resumed_cb, manager);
}
-#ifdef WITH_SYSTEMD_INHIBIT
/**
- * gpm_main_system_inhibit:
+ * gpm_main_systemd_inhibit:
*
* Return a fd to the to the inhibitor, that we can close on exit.
*
@@ -1917,7 +1912,6 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) {
egg_debug ("Inhibiting systemd sleep - success");
return r;
}
-#endif
/**
* gpm_manager_init:
@@ -1929,20 +1923,17 @@ gpm_manager_init (GpmManager *manager)
gboolean check_type_cpu;
gint timeout;
DBusGConnection *connection;
- GDBusConnection *g_connection;
+ GDBusConnection *g_connection;
GError *error = NULL;
manager->priv = GPM_MANAGER_GET_PRIVATE (manager);
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- g_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ g_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-#ifdef WITH_SYSTEMD_INHIBIT
- /* We want to inhibit the systemd suspend options, and take care of them ourselves */
- if (sd_booted() > 0) {
- manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy);
- }
-
-#endif
+ /* We want to inhibit the systemd suspend options, and take care of them ourselves */
+ if (LOGIND_RUNNING()) {
+ manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy);
+ }
/* init to unthrottled */
manager->priv->screensaver_ac_throttle_id = 0;
@@ -2101,16 +2092,15 @@ gpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->client);
g_object_unref (manager->priv->status_icon);
-#ifdef WITH_SYSTEMD_INHIBIT
- /* Let systemd take over again ... */
- if (manager->priv->systemd_inhibit > 0) {
- close(manager->priv->systemd_inhibit);
- }
- if (manager->priv->systemd_inhibit_proxy != NULL) {
- g_object_unref (manager->priv->systemd_inhibit_proxy);
- }
- //g_object_unref (manager->priv->systemd_inhibit);
-#endif
+ if (LOGIND_RUNNING()) {
+ /* Let systemd take over again ... */
+ if (manager->priv->systemd_inhibit > 0) {
+ close(manager->priv->systemd_inhibit);
+ }
+ if (manager->priv->systemd_inhibit_proxy != NULL) {
+ g_object_unref (manager->priv->systemd_inhibit_proxy);
+ }
+ }
G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object);
}
diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c
index e84d0b1..d1795dd 100644
--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -812,11 +812,10 @@ 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);
@@ -824,108 +823,129 @@ gpm_prefs_init (GpmPrefs *prefs)
prefs->priv->console = egg_console_kit_new ();
prefs->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA);
- /* are we allowed to shutdown? */
- 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_shutdown = FALSE;
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 (LOGIND_RUNNING()) {
+ /* get values from 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,
+ &error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ res = g_dbus_proxy_call_sync (proxy, "CanPowerOff",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error == NULL && res != NULL) {
+ g_variant_get(res,"(s)", &r);
+ prefs->priv->can_shutdown = 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, "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 {
+ /* are we allowed to shutdown? */
+ egg_console_kit_can_stop (prefs->priv->console, &prefs->priv->can_shutdown, NULL);
+ /* 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);
+ }
+
+ 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;
+ }
+
+ 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);
+ prefs->priv->has_button_lid = up_client_get_lid_is_present (prefs->priv->client);
#else
- g_object_get (prefs->priv->client,
- "lid-is-present", &prefs->priv->has_button_lid,
- NULL);
-#endif
+ g_object_get (prefs->priv->client,
+ "lid-is-present", &prefs->priv->has_button_lid,
+ NULL);
#endif
+ }
+
prefs->priv->has_button_suspend = TRUE;
/* find if we have brightness hardware */
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index 4813d1f..98b5632 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -1564,13 +1564,14 @@ main (int argc, char *argv[])
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
-#if GLIB_CHECK_VERSION(2,32,0)
-#else
+#if !GLIB_CHECK_VERSION(2,32,0)
if (! g_thread_supported ())
g_thread_init (NULL);
#endif
dbus_g_thread_init ();
+#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init ();
+#endif
context = g_option_context_new (NULL);
/* TRANSLATORS: the program name */