summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSander Sweers <[email protected]>2016-04-17 15:04:08 +0200
committermonsta <[email protected]>2017-03-05 14:12:12 +0300
commit9923739fe6f161a05078340593bf6a91db13d9be (patch)
tree04206ce1a4d88c8236229d2f1adfc325d8dcd641
parent54d119718d8c2c109e089669aacdb66ffeb38a3e (diff)
downloadmate-session-manager-9923739fe6f161a05078340593bf6a91db13d9be.tar.bz2
mate-session-manager-9923739fe6f161a05078340593bf6a91db13d9be.tar.xz
Replace deprecated upower functions with ConsoleKit2 equivalents
This requires ConsoleKit2 version 0.9.2. + corrections for issues mentioned at https://github.com/mate-desktop/mate-session-manager/pull/133
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac28
-rw-r--r--mate-session/Makefile.am2
-rw-r--r--mate-session/gsm-consolekit.c133
-rw-r--r--mate-session/gsm-consolekit.h8
-rw-r--r--mate-session/gsm-logout-dialog.c28
-rw-r--r--mate-session/gsm-manager.c71
7 files changed, 159 insertions, 113 deletions
diff --git a/Makefile.am b/Makefile.am
index 55d9370..40911b8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,8 +28,6 @@ MAINTAINERCLEANFILES = \
$(srcdir)/m4/intltool.m4 \
`find "$(srcdir)" -type f -name Makefile.in -print`
-DISTCHECK_CONFIGURE_FLAGS = --disable-upower
-
# Build ChangeLog from GIT history
ChangeLog:
$(AM_V_GEN) if test -d $(top_srcdir)/.git; then \
diff --git a/configure.ac b/configure.ac
index 4714e29..206feaf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,6 @@ GLIB_REQUIRED=2.36.0
GIO_REQUIRED=2.25.0
GTK_REQUIRED=3.14.0
DBUS_GLIB_REQUIRED=0.76
-UPOWER_REQUIRED=0.9.0
dnl ====================================================================
dnl Dependency Checks
@@ -117,32 +116,6 @@ AM_CONDITIONAL(HAVE_SYSTEMD, test "x$use_systemd" = "xyes")
AC_SUBST(HAVE_SYSTEMD)
dnl ====================================================================
-dnl UPOWER
-dnl ====================================================================
-
-AC_ARG_ENABLE(upower,
- AS_HELP_STRING([--enable-upower],
- [Use upower to suspend/hibernate]),
- enable_upower=$enableval,
- enable_upower=no)
-if test "x$enable_upower" = "xyes"; then
- PKG_CHECK_MODULES([UPOWER], [upower-glib >= $UPOWER_REQUIRED], has_upower=yes, has_upower=no)
-
- if test "x$has_upower" = "xyes"; then
- AC_DEFINE(HAVE_UPOWER, 1, [upower support])
- AC_SUBST(UPOWER_CFLAGS)
- AC_SUBST(UPOWER_LIBS)
- fi
- PKG_CHECK_MODULES([UPOWER_HIBERNATE], [upower-glib < 0.99], has_upower_hibernate_suspend=yes, has_upower_hibernate_suspend=no)
- if test "x$has_upower_hibernate_suspend" = "xyes"; then
- AC_DEFINE(HAVE_UPOWER_HIBERNATE_SUSPEND, 1, [upower based support for hibernate and suspend (< 0.99)])
- fi
-
-fi
-AM_CONDITIONAL(HAVE_UPOWER, test "x$has_upower" = "xyes")
-AC_SUBST(HAVE_UPOWER)
-
-dnl ====================================================================
dnl Check for XSync extension
dnl ====================================================================
@@ -368,7 +341,6 @@ echo "
Default WM: ${with_default_wm}
Systemd support: ${use_systemd}
- Upower support: ${enable_upower}
IPv6 support: ${have_full_ipv6}
Backtrace support: ${have_backtrace}
XRender support: ${have_xrender}
diff --git a/mate-session/Makefile.am b/mate-session/Makefile.am
index c6e8d37..4b2e3f1 100644
--- a/mate-session/Makefile.am
+++ b/mate-session/Makefile.am
@@ -7,7 +7,6 @@ noinst_PROGRAMS = \
AM_CPPFLAGS = \
$(MATE_SESSION_CFLAGS) \
$(SYSTEMD_CFLAGS) \
- $(UPOWER_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS)
AM_CFLAGS = $(WARN_CFLAGS)
@@ -81,7 +80,6 @@ mate_session_LDADD = \
$(XEXT_LIBS) \
$(MATE_SESSION_LIBS) \
$(SYSTEMD_LIBS) \
- $(UPOWER_LIBS) \
$(EXECINFO_LIBS)
libgsmutil_la_SOURCES = \
diff --git a/mate-session/gsm-consolekit.c b/mate-session/gsm-consolekit.c
index dee78ab..5f39358 100644
--- a/mate-session/gsm-consolekit.c
+++ b/mate-session/gsm-consolekit.c
@@ -480,6 +480,65 @@ gsm_consolekit_attempt_stop (GsmConsolekit *manager)
}
}
+void
+gsm_consolekit_attempt_suspend (GsmConsolekit *manager)
+{
+ gboolean res;
+ GError *error;
+
+ error = NULL;
+
+ if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
+ g_warning ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy,
+ "Suspend",
+ INT_MAX,
+ &error,
+ G_TYPE_BOOLEAN, TRUE, /* interactive */
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ if (!res) {
+ g_warning ("Unable to suspend system: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+void
+gsm_consolekit_attempt_hibernate (GsmConsolekit *manager)
+{
+ gboolean res;
+ GError *error;
+
+ error = NULL;
+
+ if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
+ g_warning ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy,
+ "Hibernate",
+ INT_MAX,
+ &error,
+ G_TYPE_BOOLEAN, TRUE, /* interactive */
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+
+ if (!res) {
+ g_warning ("Unable to hibernate system: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static gboolean
get_current_session_id (DBusConnection *connection,
char **session_id)
@@ -836,6 +895,80 @@ gsm_consolekit_can_stop (GsmConsolekit *manager)
return can_stop;
}
+gboolean
+gsm_consolekit_can_suspend (GsmConsolekit *manager)
+{
+ gboolean res;
+ gboolean can_suspend;
+ gchar *retval;
+ GError *error = NULL;
+
+ if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
+ g_warning ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy,
+ "CanSuspend",
+ INT_MAX,
+ &error,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &retval,
+ G_TYPE_INVALID);
+
+ if (res == FALSE) {
+ g_warning ("Could not make DBUS call: %s",
+ error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ can_suspend = g_strcmp0 (retval, "yes") == 0 ||
+ g_strcmp0 (retval, "challenge") == 0;
+
+ g_free (retval);
+ return can_suspend;
+}
+
+gboolean
+gsm_consolekit_can_hibernate (GsmConsolekit *manager)
+{
+ gboolean res;
+ gboolean can_hibernate;
+ gchar *retval;
+ GError *error = NULL;
+
+ if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
+ g_warning ("Could not connect to ConsoleKit: %s",
+ error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy,
+ "CanHibernate",
+ INT_MAX,
+ &error,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &retval,
+ G_TYPE_INVALID);
+
+ if (res == FALSE) {
+ g_warning ("Could not make DBUS call: %s",
+ error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ can_hibernate = g_strcmp0 (retval, "yes") == 0 ||
+ g_strcmp0 (retval, "challenge") == 0;
+
+ g_free (retval);
+ return can_hibernate;
+}
+
gchar *
gsm_consolekit_get_current_session_type (GsmConsolekit *manager)
{
diff --git a/mate-session/gsm-consolekit.h b/mate-session/gsm-consolekit.h
index 741bde9..3dbb4f8 100644
--- a/mate-session/gsm-consolekit.h
+++ b/mate-session/gsm-consolekit.h
@@ -87,10 +87,18 @@ gboolean gsm_consolekit_can_stop (GsmConsolekit *manager);
gboolean gsm_consolekit_can_restart (GsmConsolekit *manager);
+gboolean gsm_consolekit_can_suspend (GsmConsolekit *manager);
+
+gboolean gsm_consolekit_can_hibernate (GsmConsolekit *manager);
+
void gsm_consolekit_attempt_stop (GsmConsolekit *manager);
void gsm_consolekit_attempt_restart (GsmConsolekit *manager);
+void gsm_consolekit_attempt_suspend (GsmConsolekit *manager);
+
+void gsm_consolekit_attempt_hibernate (GsmConsolekit *manager);
+
void gsm_consolekit_set_session_idle (GsmConsolekit *manager,
gboolean is_idle);
diff --git a/mate-session/gsm-logout-dialog.c b/mate-session/gsm-logout-dialog.c
index 97f7560..0dbeb2b 100644
--- a/mate-session/gsm-logout-dialog.c
+++ b/mate-session/gsm-logout-dialog.c
@@ -27,10 +27,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#ifdef HAVE_UPOWER
-#include <upower.h>
-#endif
-
#include "gsm-logout-dialog.h"
#ifdef HAVE_SYSTEMD
#include "gsm-systemd.h"
@@ -58,9 +54,6 @@ typedef enum {
struct _GsmLogoutDialogPrivate
{
GsmDialogLogoutType type;
-#ifdef HAVE_UPOWER
- UpClient *up_client;
-#endif
#ifdef HAVE_SYSTEMD
GsmSystemd *systemd;
#endif
@@ -156,9 +149,6 @@ gsm_logout_dialog_init (GsmLogoutDialog *logout_dialog)
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (logout_dialog), TRUE);
gtk_window_set_keep_above (GTK_WINDOW (logout_dialog), TRUE);
gtk_window_stick (GTK_WINDOW (logout_dialog));
-#ifdef HAVE_UPOWER
- logout_dialog->priv->up_client = up_client_new ();
-#endif
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING())
logout_dialog->priv->systemd = gsm_get_systemd ();
@@ -185,12 +175,6 @@ gsm_logout_dialog_destroy (GsmLogoutDialog *logout_dialog,
g_source_remove (logout_dialog->priv->timeout_id);
logout_dialog->priv->timeout_id = 0;
}
-#ifdef HAVE_UPOWER
- if (logout_dialog->priv->up_client) {
- g_object_unref (logout_dialog->priv->up_client);
- logout_dialog->priv->up_client = NULL;
- }
-#endif
#ifdef HAVE_SYSTEMD
if (logout_dialog->priv->systemd) {
g_object_unref (logout_dialog->priv->systemd);
@@ -214,13 +198,9 @@ gsm_logout_supports_system_suspend (GsmLogoutDialog *logout_dialog)
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING())
ret = gsm_systemd_can_suspend (logout_dialog->priv->systemd);
-#endif
-#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND)
else
#endif
-#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND
- ret = up_client_get_can_suspend (logout_dialog->priv->up_client);
-#endif
+ ret = gsm_consolekit_can_suspend (logout_dialog->priv->consolekit);
return ret;
}
@@ -232,13 +212,9 @@ gsm_logout_supports_system_hibernate (GsmLogoutDialog *logout_dialog)
#ifdef HAVE_SYSTEMD
if (LOGIND_RUNNING())
ret = gsm_systemd_can_hibernate (logout_dialog->priv->systemd);
-#endif
-#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND)
else
#endif
-#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND
- ret = up_client_get_can_hibernate (logout_dialog->priv->up_client);
-#endif
+ ret = gsm_consolekit_can_hibernate (logout_dialog->priv->consolekit);
return ret;
}
diff --git a/mate-session/gsm-manager.c b/mate-session/gsm-manager.c
index 63a31bd..2e8273a 100644
--- a/mate-session/gsm-manager.c
+++ b/mate-session/gsm-manager.c
@@ -38,10 +38,6 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#ifdef HAVE_UPOWER
-#include <upower.h>
-#endif
-
#include <gtk/gtk.h> /* for logout dialog */
#include <gio/gio.h> /* for gsettings */
@@ -150,10 +146,6 @@ struct GsmManagerPrivate
DBusGProxy *bus_proxy;
DBusGConnection *connection;
-#ifdef HAVE_UPOWER
- /* Interface with other parts of the system */
- UpClient *up_client;
-#endif
};
enum {
@@ -1178,26 +1170,19 @@ manager_attempt_hibernate (GsmManager *manager)
gsm_systemd_attempt_hibernate (systemd);
}
-#endif
-#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND)
else {
#endif
-#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND
- gboolean can_hibernate = up_client_get_can_hibernate (manager->priv->up_client);
+ GsmConsolekit *consolekit;
+ consolekit = gsm_get_consolekit ();
+
+ gboolean can_hibernate = gsm_consolekit_can_hibernate (consolekit);
if (can_hibernate) {
/* lock the screen before we suspend */
manager_perhaps_lock (manager);
- GError *error = NULL;
- gboolean ret = up_client_hibernate_sync (manager->priv->up_client, NULL, &error);
- if (!ret) {
- g_warning ("Unexpected hibernate failure: %s",
- error->message);
- g_error_free (error);
- }
+ gsm_consolekit_attempt_hibernate (consolekit);
}
-#endif
-#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND)
+#ifdef HAVE_SYSTEMD
}
#endif
}
@@ -1217,26 +1202,19 @@ manager_attempt_suspend (GsmManager *manager)
gsm_systemd_attempt_suspend (systemd);
}
-#endif
-#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND)
else {
#endif
-#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND
- gboolean can_suspend = up_client_get_can_suspend (manager->priv->up_client);
+ GsmConsolekit *consolekit;
+ consolekit = gsm_get_consolekit ();
+
+ gboolean can_suspend = gsm_consolekit_can_suspend (consolekit);
if (can_suspend) {
/* lock the screen before we suspend */
manager_perhaps_lock (manager);
- GError *error = NULL;
- gboolean ret = up_client_suspend_sync (manager->priv->up_client, NULL, &error);
- if (!ret) {
- g_warning ("Unexpected suspend failure: %s",
- error->message);
- g_error_free (error);
- }
+ gsm_consolekit_attempt_suspend (consolekit);
}
-#endif
-#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND)
+#ifdef HAVE_SYSTEMD
}
#endif
}
@@ -2452,12 +2430,6 @@ gsm_manager_dispose (GObject *object)
g_object_unref (manager->priv->settings_screensaver);
manager->priv->settings_screensaver = NULL;
}
-#ifdef HAVE_UPOWER
- if (manager->priv->up_client != NULL) {
- g_object_unref (manager->priv->up_client);
- manager->priv->up_client = NULL;
- }
-#endif
G_OBJECT_CLASS (gsm_manager_parent_class)->dispose (object);
}
@@ -2664,9 +2636,6 @@ gsm_manager_init (GsmManager *manager)
"status-changed",
G_CALLBACK (on_presence_status_changed),
manager);
-#ifdef HAVE_UPOWER
- manager->priv->up_client = up_client_new ();
-#endif
g_signal_connect (manager->priv->settings_session,
"changed",
G_CALLBACK (on_gsettings_key_changed),
@@ -3376,14 +3345,6 @@ gsm_manager_can_shutdown (GsmManager *manager,
#ifdef HAVE_SYSTEMD
GsmSystemd *systemd;
#endif
- gboolean can_suspend = FALSE;
- gboolean can_hibernate = FALSE;
-#ifdef HAVE_UPOWER
- g_object_get (manager->priv->up_client,
- "can-suspend", &can_suspend,
- "can-hibernate", &can_hibernate,
- NULL);
-#endif
g_debug ("GsmManager: CanShutdown called");
g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
@@ -3393,8 +3354,8 @@ gsm_manager_can_shutdown (GsmManager *manager,
systemd = gsm_get_systemd ();
*shutdown_available = gsm_systemd_can_stop (systemd)
|| gsm_systemd_can_restart (systemd)
- || can_suspend
- || can_hibernate;
+ || gsm_systemd_can_suspend (systemd)
+ || gsm_systemd_can_hibernate (systemd);
g_object_unref (systemd);
}
else {
@@ -3403,8 +3364,8 @@ gsm_manager_can_shutdown (GsmManager *manager,
*shutdown_available = !_log_out_is_locked_down (manager) &&
(gsm_consolekit_can_stop (consolekit)
|| gsm_consolekit_can_restart (consolekit)
- || can_suspend
- || can_hibernate);
+ || gsm_consolekit_can_suspend (consolekit)
+ || gsm_consolekit_can_hibernate (consolekit));
g_object_unref (consolekit);
#ifdef HAVE_SYSTEMD
}