KIdleTime

xscreensaverbasedpoller.cpp
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.0-only
5  */
6 
7 #include "xscreensaverbasedpoller.h"
8 
9 #include <config-kidletime.h>
10 
11 #include <QX11Info>
12 
13 #include <X11/Xlib.h>
14 #include <X11/extensions/scrnsaver.h>
15 
16 XScreensaverBasedPoller::XScreensaverBasedPoller(QObject *parent)
17  : WidgetBasedPoller(parent), m_screenSaverIface(nullptr)
18 {
19 
20 }
21 
22 XScreensaverBasedPoller::~XScreensaverBasedPoller()
23 {
24 }
25 
26 bool XScreensaverBasedPoller::additionalSetUp()
27 {
28  m_screenSaverIface = new OrgFreedesktopScreenSaverInterface(QLatin1String("org.freedesktop.ScreenSaver"),
29  QLatin1String("/ScreenSaver"),
31 
32  connect(m_screenSaverIface, SIGNAL(ActiveChanged(bool)), SLOT(screensaverActivated(bool)));
33 
34  return true;
35 }
36 
37 void XScreensaverBasedPoller::screensaverActivated(bool activated)
38 {
39  // We care only if it has been disactivated
40 
41  if (!activated) {
42  m_screenSaverIface->SimulateUserActivity();
43  emit resumingFromIdle();
44  }
45 }
46 
47 int XScreensaverBasedPoller::getIdleTime()
48 {
49  XScreenSaverInfo *mitInfo = nullptr;
50  mitInfo = XScreenSaverAllocInfo();
51  XScreenSaverQueryInfo(QX11Info::display(), DefaultRootWindow(QX11Info::display()), mitInfo);
52  int ret = mitInfo->idle;
53  XFree(mitInfo);
54  return ret;
55 }
56 
57 void XScreensaverBasedPoller::simulateUserActivity()
58 {
59  stopCatchingIdleEvents();
60  XResetScreenSaver(QX11Info::display());
61  XFlush(QX11Info::display());
62 }
63 
QDBusConnection sessionBus()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void resumingFromIdle()
Triggered, if KIdleTime is catching resume events, when the system resumes from an idle state...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 22:48:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.