1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #include "idleinhibit.h" |
7 | #include "event_queue.h" |
8 | #include "surface.h" |
9 | #include "wayland_pointer_p.h" |
10 | |
11 | #include <wayland-idle-inhibit-unstable-v1-client-protocol.h> |
12 | |
13 | namespace KWayland |
14 | { |
15 | namespace Client |
16 | { |
17 | class Q_DECL_HIDDEN IdleInhibitManager::Private |
18 | { |
19 | public: |
20 | Private() = default; |
21 | |
22 | void setup(zwp_idle_inhibit_manager_v1 *arg); |
23 | |
24 | WaylandPointer<zwp_idle_inhibit_manager_v1, zwp_idle_inhibit_manager_v1_destroy> idleinhibitmanager; |
25 | EventQueue *queue = nullptr; |
26 | }; |
27 | |
28 | IdleInhibitManager::IdleInhibitManager(QObject *parent) |
29 | : QObject(parent) |
30 | , d(new Private) |
31 | { |
32 | } |
33 | |
34 | void IdleInhibitManager::Private::setup(zwp_idle_inhibit_manager_v1 *arg) |
35 | { |
36 | Q_ASSERT(arg); |
37 | Q_ASSERT(!idleinhibitmanager); |
38 | idleinhibitmanager.setup(pointer: arg); |
39 | } |
40 | |
41 | IdleInhibitManager::~IdleInhibitManager() |
42 | { |
43 | release(); |
44 | } |
45 | |
46 | void IdleInhibitManager::setup(zwp_idle_inhibit_manager_v1 *idleinhibitmanager) |
47 | { |
48 | d->setup(idleinhibitmanager); |
49 | } |
50 | |
51 | void IdleInhibitManager::release() |
52 | { |
53 | d->idleinhibitmanager.release(); |
54 | } |
55 | |
56 | void IdleInhibitManager::destroy() |
57 | { |
58 | d->idleinhibitmanager.destroy(); |
59 | } |
60 | |
61 | IdleInhibitManager::operator zwp_idle_inhibit_manager_v1 *() |
62 | { |
63 | return d->idleinhibitmanager; |
64 | } |
65 | |
66 | IdleInhibitManager::operator zwp_idle_inhibit_manager_v1 *() const |
67 | { |
68 | return d->idleinhibitmanager; |
69 | } |
70 | |
71 | bool IdleInhibitManager::isValid() const |
72 | { |
73 | return d->idleinhibitmanager.isValid(); |
74 | } |
75 | |
76 | void IdleInhibitManager::setEventQueue(EventQueue *queue) |
77 | { |
78 | d->queue = queue; |
79 | } |
80 | |
81 | EventQueue *IdleInhibitManager::eventQueue() |
82 | { |
83 | return d->queue; |
84 | } |
85 | |
86 | IdleInhibitor *IdleInhibitManager::createInhibitor(Surface *surface, QObject *parent) |
87 | { |
88 | Q_ASSERT(isValid()); |
89 | auto p = new IdleInhibitor(parent); |
90 | auto w = zwp_idle_inhibit_manager_v1_create_inhibitor(zwp_idle_inhibit_manager_v1: d->idleinhibitmanager, surface: *surface); |
91 | if (d->queue) { |
92 | d->queue->addProxy(proxy: w); |
93 | } |
94 | p->setup(w); |
95 | return p; |
96 | } |
97 | |
98 | class Q_DECL_HIDDEN IdleInhibitor::Private |
99 | { |
100 | public: |
101 | void setup(zwp_idle_inhibitor_v1 *arg); |
102 | |
103 | WaylandPointer<zwp_idle_inhibitor_v1, zwp_idle_inhibitor_v1_destroy> idleinhibitor; |
104 | }; |
105 | |
106 | IdleInhibitor::IdleInhibitor(QObject *parent) |
107 | : QObject(parent) |
108 | , d(new Private) |
109 | { |
110 | } |
111 | |
112 | void IdleInhibitor::Private::setup(zwp_idle_inhibitor_v1 *arg) |
113 | { |
114 | Q_ASSERT(arg); |
115 | Q_ASSERT(!idleinhibitor); |
116 | idleinhibitor.setup(pointer: arg); |
117 | } |
118 | |
119 | IdleInhibitor::~IdleInhibitor() |
120 | { |
121 | release(); |
122 | } |
123 | |
124 | void IdleInhibitor::setup(zwp_idle_inhibitor_v1 *idleinhibitor) |
125 | { |
126 | d->setup(idleinhibitor); |
127 | } |
128 | |
129 | void IdleInhibitor::release() |
130 | { |
131 | d->idleinhibitor.release(); |
132 | } |
133 | |
134 | void IdleInhibitor::destroy() |
135 | { |
136 | d->idleinhibitor.destroy(); |
137 | } |
138 | |
139 | IdleInhibitor::operator zwp_idle_inhibitor_v1 *() |
140 | { |
141 | return d->idleinhibitor; |
142 | } |
143 | |
144 | IdleInhibitor::operator zwp_idle_inhibitor_v1 *() const |
145 | { |
146 | return d->idleinhibitor; |
147 | } |
148 | |
149 | bool IdleInhibitor::isValid() const |
150 | { |
151 | return d->idleinhibitor.isValid(); |
152 | } |
153 | |
154 | } |
155 | } |
156 | |
157 | #include "moc_idleinhibit.cpp" |
158 |