Advertisement
KukuRuzo

Untitled

Oct 14th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | Source Code | 0 0
  1. diff --git a/src/tools/idle/idle_x11.cpp b/src/tools/idle/idle_x11.cpp
  2. index 5cdf6071..dbf090ef 100644
  3. --- a/src/tools/idle/idle_x11.cpp
  4. +++ b/src/tools/idle/idle_x11.cpp
  5. @@ -75,7 +75,12 @@ public:
  6.      Private() { }
  7.  
  8.  #ifdef USE_DBUS
  9. -    QString dbusService = QString();
  10. +    struct {
  11. +        QString name = QString();
  12. +        QString path = QString();
  13. +        QString method = QString();
  14. +        bool isGnome = false;
  15. +    } idleService;
  16.  #endif // USE_DBUS
  17.  #ifdef HAVE_XSS
  18.      XScreenSaverInfo *ss_info = nullptr;
  19. @@ -110,12 +115,28 @@ bool IdlePlatform::init()
  20.  #ifdef USE_DBUS
  21.      // if DBUS idle is available using it else try to use XSS functions
  22.      const auto        services     = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
  23. -    const QStringList idleServices = { COMMON_SS_SERV, KDE_SS_SERV, GNOME_SS_SERV };
  24. +    const QStringList idleServices = { GNOME_SS_SERV, COMMON_SS_SERV, KDE_SS_SERV };
  25.      // find first available dbus-service
  26.      for (const auto &service : idleServices) {
  27.          if (services.contains(service)) {
  28. -            d->dbusService = service;
  29. -            return true;
  30. +            bool isGnome = (service == GNOME_SS_SERV);
  31. +            auto path = isGnome ? GNOME_SS_PATH : COMMON_SS_PATH;
  32. +            auto interface  = QDBusInterface(service, path, "org.freedesktop.DBus.Introspectable");
  33. +            if (interface.isValid()) {
  34. +                QDBusReply<QString> reply = interface.call("Introspect");
  35. +                if(reply.isValid()) {
  36. +                    if(reply.value().contains(isGnome ? GNOME_SS_F : COMMON_SS_F)) {
  37. +                        d->idleService.name = service;
  38. +                        d->idleService.path = path;
  39. +                        d->idleService.method = isGnome ? GNOME_SS_F : COMMON_SS_F;
  40. +                        d->idleService.isGnome = isGnome;
  41. +                        return true;
  42. +                    }
  43. +                }
  44. +                /*else {
  45. +                    qDebug() << reply.error().message().toUtf8();
  46. +                }*/
  47. +            }
  48.          }
  49.      }
  50.  #endif // USE_DBUS
  51. @@ -140,18 +161,17 @@ bool IdlePlatform::init()
  52.  int IdlePlatform::secondsIdle()
  53.  {
  54.  #ifdef USE_DBUS
  55. -    if (!d->dbusService.isEmpty()) {
  56. +    if (!d->idleService.name.isEmpty()) {
  57.          // KDE and freedesktop uses the same path interface and method but gnome uses other
  58. -        bool                isNotGnome = d->dbusService == COMMON_SS_SERV || d->dbusService == KDE_SS_SERV;
  59. -        const QLatin1String iface      = isNotGnome ? COMMON_SS_SERV : GNOME_SS_SERV;
  60. -        const QLatin1String path       = isNotGnome ? COMMON_SS_PATH : GNOME_SS_PATH;
  61. -        const QLatin1String method     = isNotGnome ? COMMON_SS_F : GNOME_SS_F;
  62. -        auto                interface  = QDBusInterface(d->dbusService, path, iface);
  63. +        auto interface  = QDBusInterface(d->idleService.name, d->idleService.path, d->idleService.name);
  64.          if (interface.isValid()) {
  65. -            QDBusReply<uint> reply = interface.call(method);
  66. -            // probably reply value for freedesktop and kde need to be converted to seconds
  67. -            if (reply.isValid())
  68. -                return isNotGnome ? reply.value() / 1000 : reply.value();
  69. +            QDBusMessage reply = interface.call(d->idleService.method);
  70. +            if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() > 0) {
  71. +                auto result = reply.arguments().at(0);
  72. +                if (result.canConvert<int>())
  73. +                // reply should be in milliseconds and must be converted to seconds
  74. +                    return result.toInt() / 1000;
  75. +            }
  76.          }
  77.      }
  78.  #endif // USE_DBUS
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement