Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/libpsi/tools/idle/idle_x11.cpp b/src/libpsi/tools/idle/idle_x11.cpp
- index 578bcbb1..4fff6803 100644
- --- a/src/libpsi/tools/idle/idle_x11.cpp
- +++ b/src/libpsi/tools/idle/idle_x11.cpp
- @@ -19,20 +19,78 @@
- #include "idle.h"
- -#ifndef HAVE_XSS
- +#if !defined(HAVE_XSS) && !defined(USE_DBUS)
- IdlePlatform::IdlePlatform() { d = nullptr; }
- IdlePlatform::~IdlePlatform() { }
- bool IdlePlatform::init() { return false; }
- int IdlePlatform::secondsIdle() { return 0; }
- -#else
- +#elif defined(USE_DBUS) && (!defined(HAVE_X11) || !defined(LIMIT_X11_USAGE))
- +#include <QDBusConnection>
- +#include <QDBusConnectionInterface>
- +#include <QDBusInterface>
- +#include <QDBusMessage>
- +#include <QDBusReply>
- +
- +// Screen Saver dbus services
- +static const QLatin1String COMMON_SS_SERV("org.freedesktop.ScreenSaver");
- +static const QLatin1String COMMON_SS_PATH("/ScreenSaver");
- +static const QLatin1String KDE_SS_SERV("org.kde.screensaver");
- +static const QLatin1String GNOME_SS_SERV("org.gnome.Mutter.IdleMonitor");
- +static const QLatin1String GNOME_SS_PATH("/org/gnome/Mutter/IdleMonitor/Core");
- +// Screen saver functions
- +static const QLatin1String GNOME_SS_F("GetIdletime");
- +static const QLatin1String COMMON_SS_F("GetSessionIdleTime");
- +
- +class IdlePlatform::Private {
- +public:
- + Private() { }
- + QString availableService;
- + bool getServicesAvailable()
- + {
- + const auto services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
- + const QStringList idleServices = { KDE_SS_SERV, GNOME_SS_SERV };
- + // find first available dbus-service
- + for (const auto &service : idleServices) {
- + if (services.contains(service)) {
- + availableService = service;
- + return true;
- + }
- + }
- + return false;
- + }
- +};
- +
- +IdlePlatform::IdlePlatform() { d = new Private; }
- +IdlePlatform::~IdlePlatform() { delete d; }
- +bool IdlePlatform::init() { return !d->getServicesAvailable(); }
- +
- +int IdlePlatform::secondsIdle()
- +{
- + // KDE and freedesktop uses the same path interface and method but gnome uses other
- + bool isNotGnome = d->availableService == COMMON_SS_SERV || d->availableService == KDE_SS_SERV;
- + const QLatin1String iface = isNotGnome ? COMMON_SS_SERV : GNOME_SS_SERV;
- + const QLatin1String path = isNotGnome ? COMMON_SS_PATH : GNOME_SS_PATH;
- + const QLatin1String method = isNotGnome ? COMMON_SS_F : GNOME_SS_F;
- + auto interface = QDBusInterface(d->availableService, path, iface);
- + if (interface.isValid()) {
- + QDBusReply<int> reply = interface.call(method);
- + // probably reply value for freedesktop and kde need to be converted to seconds
- + if (reply.isValid())
- + return isNotGnome ? reply.value() / 1000 : reply.value();
- + }
- + return 0;
- +}
- +
- +#else
- +
- #include <QApplication>
- #include <QDesktopWidget>
- #include <QX11Info>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement