kwin/src/idledetector.cpp
Laurent Montel b823747c3b Add explicit moc includes to sources for moc-covered headers
* speeds up incremental builds as changes to a header will not always
  need the full mocs_compilation.cpp for all the target's headers rebuild,
  while having a moc file sourced into a source file only adds minor
  extra costs, due to small own code and the used headers usually
  already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
  resulting in those quickly processed, while the minor extra cost of the
  sourced moc files does not outweigh that in summary.
  Measured times actually improved by some percent points.
  (ideally CMake would just skip empty mocs_compilation.cpp & its object
  file one day)
* enables compiler to see all methods of a class in same compilation unit
  to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
  moc code being sourced into the cpp file there definitions can be ensured
  and often are already for the needs of the normal class methods
2023-07-15 08:40:49 +00:00

76 lines
1.3 KiB
C++

/*
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "idledetector.h"
#include "input.h"
namespace KWin
{
IdleDetector::IdleDetector(std::chrono::milliseconds timeout, QObject *parent)
: QObject(parent)
, m_timer(new QTimer(this))
{
m_timer->setSingleShot(true);
m_timer->setInterval(timeout);
connect(m_timer, &QTimer::timeout, this, &IdleDetector::markAsIdle);
m_timer->start();
input()->addIdleDetector(this);
}
IdleDetector::~IdleDetector()
{
if (input()) {
input()->removeIdleDetector(this);
}
}
bool IdleDetector::isInhibited() const
{
return m_isInhibited;
}
void IdleDetector::setInhibited(bool inhibited)
{
if (m_isInhibited == inhibited) {
return;
}
m_isInhibited = inhibited;
if (inhibited) {
m_timer->stop();
} else {
m_timer->start();
}
}
void IdleDetector::activity()
{
if (!m_isInhibited) {
m_timer->start();
markAsResumed();
}
}
void IdleDetector::markAsIdle()
{
if (!m_isIdle) {
m_isIdle = true;
Q_EMIT idle();
}
}
void IdleDetector::markAsResumed()
{
if (m_isIdle) {
m_isIdle = false;
Q_EMIT resumed();
}
}
} // namespace KWin
#include "moc_idledetector.cpp"