0

I want to get idle time on Gnome. The following command works when typed into a terminal:

dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor /org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime

I'm new to Qt D-Bus and am not sure how to get that same result using QDBusInterface. I have the following code:

QDBusInterface interface( "org.gnome.Mutter.IdleMonitor",
                          "/org/gnome/Mutter/IdleMonitor/Core",
                          "org.gnome.Mutter.IdleMonitor");

QDBusReply<int> reply = interface.call( "GetIdletime");
std::cout << "Reply: " << reply.value() << '\n';

That prints 0 every time. How do I get the correct idle time?

Ricky Kresslein
  • 372
  • 1
  • 13
  • 1
    Use `qdbus` (may be called `qdbus-qt5` depending on your distro) to try the same things. Note that `dbus-send` uses the **session** bus by default, and your Qt code is using the **system** bus. – Adriaan de Groot Jan 29 '22 at 14:28
  • Thank you, this led me to my answer. I used qdbus-qt6 to find out that the reply needed to be of type `qulonglong` rather than int. I also changed my code to use the session bus. – Ricky Kresslein Jan 29 '22 at 14:57

1 Answers1

0

I was able to get this working by changing the type of QDBusReply to qulonglong. The working code is:

QDBusInterface interface( "org.gnome.Mutter.IdleMonitor",
                          "/org/gnome/Mutter/IdleMonitor/Core",
                          "org.gnome.Mutter.IdleMonitor");

QDBusReply<qulonglong> reply = interface.call("GetIdletime");
Ricky Kresslein
  • 372
  • 1
  • 13