1/* This file is part of the KDE libraries
2 * SPDX-FileCopyrightText: 2009 Dario Freddi <drf at kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "xscreensaverbasedpoller.h"
8
9#include <config-kidletime.h>
10
11#include <QGuiApplication>
12
13// sourcing the moc file before the Xlib include,
14// whose defines like "Bool" break Qt names
15#include "moc_xscreensaverbasedpoller.cpp"
16
17#include <X11/Xlib.h>
18#include <X11/extensions/scrnsaver.h>
19
20static Display *display()
21{
22 return qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display();
23}
24
25XScreensaverBasedPoller::XScreensaverBasedPoller(QObject *parent)
26 : KWindowBasedIdleTimePoller(parent)
27 , m_screenSaverIface(nullptr)
28{
29}
30
31XScreensaverBasedPoller::~XScreensaverBasedPoller()
32{
33}
34
35bool XScreensaverBasedPoller::additionalSetUp()
36{
37 m_screenSaverIface = new OrgFreedesktopScreenSaverInterface(QLatin1String("org.freedesktop.ScreenSaver"),
38 QLatin1String("/ScreenSaver"),
39 QDBusConnection::sessionBus(),
40 this);
41
42 connect(sender: m_screenSaverIface, signal: &OrgFreedesktopScreenSaverInterface::ActiveChanged, context: this, slot: &XScreensaverBasedPoller::screensaverActivated);
43
44 return true;
45}
46
47void XScreensaverBasedPoller::screensaverActivated(bool activated)
48{
49 // We care only if it has been disactivated
50
51 if (!activated) {
52 m_screenSaverIface->SimulateUserActivity();
53 Q_EMIT resumingFromIdle();
54 }
55}
56
57int XScreensaverBasedPoller::getIdleTime()
58{
59 XScreenSaverInfo *mitInfo = nullptr;
60 mitInfo = XScreenSaverAllocInfo();
61 XScreenSaverQueryInfo(display(), DefaultRootWindow(display()), mitInfo);
62 int ret = mitInfo->idle;
63 XFree(mitInfo);
64 return ret;
65}
66
67void XScreensaverBasedPoller::simulateUserActivity()
68{
69 stopCatchingIdleEvents();
70 XResetScreenSaver(display());
71 XFlush(display());
72}
73

source code of kidletime/src/plugins/xscreensaver/xscreensaverbasedpoller.cpp