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() { }