File indexing completed on 2024-11-10 04:56:59

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "poller.h"
0010 #include "idledetector.h"
0011 #include "input.h"
0012 
0013 namespace KWin
0014 {
0015 
0016 KWinIdleTimePoller::KWinIdleTimePoller(QObject *parent)
0017     : KAbstractIdleTimePoller(parent)
0018 {
0019 }
0020 
0021 bool KWinIdleTimePoller::isAvailable()
0022 {
0023     return true;
0024 }
0025 
0026 bool KWinIdleTimePoller::setUpPoller()
0027 {
0028     return true;
0029 }
0030 
0031 void KWinIdleTimePoller::unloadPoller()
0032 {
0033 }
0034 
0035 void KWinIdleTimePoller::addTimeout(int nextTimeout)
0036 {
0037     if (m_timeouts.contains(nextTimeout)) {
0038         return;
0039     }
0040 
0041     auto detector = new IdleDetector(std::chrono::milliseconds(nextTimeout), this);
0042     m_timeouts.insert(nextTimeout, detector);
0043     connect(detector, &IdleDetector::idle, this, [this, nextTimeout] {
0044         Q_EMIT timeoutReached(nextTimeout);
0045     });
0046     connect(detector, &IdleDetector::resumed, this, &KWinIdleTimePoller::resumingFromIdle);
0047 }
0048 
0049 void KWinIdleTimePoller::removeTimeout(int nextTimeout)
0050 {
0051     delete m_timeouts.take(nextTimeout);
0052 }
0053 
0054 QList< int > KWinIdleTimePoller::timeouts() const
0055 {
0056     return m_timeouts.keys();
0057 }
0058 
0059 void KWinIdleTimePoller::catchIdleEvent()
0060 {
0061     if (m_catchResumeTimeout) {
0062         // already setup
0063         return;
0064     }
0065     m_catchResumeTimeout = new IdleDetector(std::chrono::milliseconds::zero(), this);
0066     connect(m_catchResumeTimeout, &IdleDetector::resumed, this, [this]() {
0067         m_catchResumeTimeout->deleteLater();
0068         m_catchResumeTimeout = nullptr;
0069         Q_EMIT resumingFromIdle();
0070     });
0071 }
0072 
0073 void KWinIdleTimePoller::stopCatchingIdleEvents()
0074 {
0075     delete m_catchResumeTimeout;
0076     m_catchResumeTimeout = nullptr;
0077 }
0078 
0079 int KWinIdleTimePoller::forcePollRequest()
0080 {
0081     return 0;
0082 }
0083 
0084 void KWinIdleTimePoller::simulateUserActivity()
0085 {
0086     input()->simulateUserActivity();
0087 }
0088 
0089 } // namespace KWin
0090 
0091 #include "moc_poller.cpp"