From 5c89dfad85a05fda6aeabe2b98017fcc8b01c624 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 2 Mar 2020 11:44:56 +0400 Subject: [PATCH] Implement LastUserInputTime on Linux This is a dbus implementation, ideally a X11 implementation should be added as a fallback to get it work on non-mainstream DEs (and WMs) --- .../platform/linux/specific_linux.cpp | 29 +++++++++++++++++++ .../platform/linux/specific_linux.h | 4 --- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 4e6ee35c88..895529b11a 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -26,6 +26,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION #include +#include +#include +#include +#include #endif #include @@ -341,6 +345,31 @@ QString GetIconName() { return IconName; } +std::optional LastUserInputTime() { + // TODO: a fallback pure-X11 implementation, this one covers only major DEs on X11 and Wayland + // an example: https://stackoverflow.com/q/9049087 +#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION + static const auto message = QDBusMessage::createMethodCall( + qsl("org.freedesktop.ScreenSaver"), + qsl("/org/freedesktop/ScreenSaver"), + qsl("org.freedesktop.ScreenSaver"), + qsl("GetSessionIdleTime")); + + const QDBusReply reply = QDBusConnection::sessionBus().call( + message); + + if (reply.isValid()) { + return (crl::now() - static_cast(reply.value())); + } else if (reply.error().type() != QDBusError::ServiceUnknown) { + LOG(("Unable to get last user input time: %1: %2") + .arg(reply.error().name()) + .arg(reply.error().message())); + } +#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION + + return std::nullopt; +} + } // namespace Platform namespace { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index 526a2aec58..7f18032cb9 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -37,10 +37,6 @@ QString GetLauncherFilename(); QString GetIconName(); -inline std::optional LastUserInputTime() { - return std::nullopt; -} - inline void IgnoreApplicationActivationRightNow() { }