Changeset View
Changeset View
Standalone View
Standalone View
idle_inhibition.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #pragma once | ||||
21 | | ||||
22 | #include <QObject> | ||||
23 | #include <QVector> | ||||
24 | | ||||
25 | #include <algorithm> | ||||
26 | | ||||
27 | namespace KWayland | ||||
28 | { | ||||
29 | namespace Server | ||||
30 | { | ||||
31 | class IdleInterface; | ||||
32 | } | ||||
33 | } | ||||
34 | | ||||
35 | using KWayland::Server::IdleInterface; | ||||
36 | | ||||
37 | namespace KWin | ||||
38 | { | ||||
39 | class ShellClient; | ||||
40 | | ||||
41 | class IdleInhibition : public QObject | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | public: | ||||
45 | explicit IdleInhibition(IdleInterface *idle); | ||||
46 | ~IdleInhibition(); | ||||
47 | | ||||
48 | void registerShellClient(ShellClient *client); | ||||
49 | | ||||
50 | bool isInhibited() const { | ||||
51 | return !m_idleInhibitors.isEmpty(); | ||||
52 | } | ||||
53 | bool isInhibited(ShellClient *client) const { | ||||
54 | return std::any_of(m_idleInhibitors.begin(), m_idleInhibitors.end(), [client] (auto c) { return c == client; }); | ||||
55 | } | ||||
56 | | ||||
57 | private: | ||||
58 | void inhibit(ShellClient *client); | ||||
59 | void uninhibit(ShellClient *client); | ||||
60 | | ||||
61 | IdleInterface *m_idle; | ||||
62 | QVector<ShellClient*> m_idleInhibitors; | ||||
63 | }; | ||||
64 | } |