From 22c8f600df11f18b96bd4666d222a716163310a6 Mon Sep 17 00:00:00 2001 From: Faheem Pervez Date: Mon, 23 Dec 2013 11:41:07 +0000 Subject: [PATCH] Make sleep and shutdown functions work on systemd's logind --- src/misc.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 5f5356ec6..2cc473e4e 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -82,7 +82,14 @@ void misc::shutdownComputer(bool sleep) { #if defined(Q_WS_X11) && defined(QT_DBUS_LIB) // Use dbus to power off / suspend the system if (sleep) { - // Recent systems use UPower + // Some recent systems use systemd's logind + QDBusInterface login1Iface("org.freedesktop.login1", "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", QDBusConnection::systemBus()); + if (login1Iface.isValid()) { + login1Iface.call("Suspend", false); + return; + } + // Else, other recent systems use UPower QDBusInterface upowerIface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus()); if (upowerIface.isValid()) { @@ -95,7 +102,14 @@ void misc::shutdownComputer(bool sleep) { QDBusConnection::systemBus()); halIface.call("Suspend", 5); } else { - // Recent systems use ConsoleKit + // Some recent systems use systemd's logind + QDBusInterface login1Iface("org.freedesktop.login1", "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", QDBusConnection::systemBus()); + if (login1Iface.isValid()) { + login1Iface.call("PowerOff", false); + return; + } + // Else, other recent systems use ConsoleKit QDBusInterface consolekitIface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()); if (consolekitIface.isValid()) {