KWin
Loading...
Searching...
No Matches
idledetector.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "idledetector.h"
8#include "input.h"
9
10namespace KWin
11{
12
13IdleDetector::IdleDetector(std::chrono::milliseconds timeout, QObject *parent)
14 : QObject(parent)
15 , m_timer(new QTimer(this))
16{
17 m_timer->setSingleShot(true);
18 m_timer->setInterval(timeout);
19 connect(m_timer, &QTimer::timeout, this, &IdleDetector::markAsIdle);
20 m_timer->start();
21
22 input()->addIdleDetector(this);
23}
24
26{
27 if (input()) {
29 }
30}
31
33{
34 return m_isInhibited;
35}
36
37void IdleDetector::setInhibited(bool inhibited)
38{
39 if (m_isInhibited == inhibited) {
40 return;
41 }
42 m_isInhibited = inhibited;
43 if (inhibited) {
44 m_timer->stop();
45 } else {
46 m_timer->start();
47 }
48}
49
51{
52 if (!m_isInhibited) {
53 m_timer->start();
54 markAsResumed();
55 }
56}
57
58void IdleDetector::markAsIdle()
59{
60 if (!m_isIdle) {
61 m_isIdle = true;
62 Q_EMIT idle();
63 }
64}
65
66void IdleDetector::markAsResumed()
67{
68 if (m_isIdle) {
69 m_isIdle = false;
70 Q_EMIT resumed();
71 }
72}
73
74} // namespace KWin
75
76#include "moc_idledetector.cpp"
bool isInhibited() const
void setInhibited(bool inhibited)
IdleDetector(std::chrono::milliseconds timeout, QObject *parent=nullptr)
~IdleDetector() override
void addIdleDetector(IdleDetector *detector)
Definition input.cpp:3226
void removeIdleDetector(IdleDetector *detector)
Definition input.cpp:3233
InputRedirection * input()
Definition input.h:549