Changeset View
Changeset View
Standalone View
Standalone View
src/client/xdgoutput.cpp
- This file was added.
1 | /**************************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2018 David Edmundson <kde@davidedmundson.co.uk> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library 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 GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | ****************************************************************************/ | ||||
20 | #include "xdgoutput.h" | ||||
21 | #include "event_queue.h" | ||||
22 | #include "wayland_pointer_p.h" | ||||
23 | #include "output.h" | ||||
24 | | ||||
25 | #include <wayland-xdg-output-unstable-v1-client-protocol.h> | ||||
26 | #include <wayland-client-protocol.h> | ||||
27 | | ||||
28 | #include <QDebug> | ||||
29 | | ||||
30 | namespace KWayland | ||||
31 | { | ||||
32 | namespace Client | ||||
33 | { | ||||
34 | | ||||
35 | class XdgOutputManager::Private | ||||
36 | { | ||||
37 | public: | ||||
38 | Private() = default; | ||||
39 | | ||||
40 | void setup(zxdg_output_manager_v1 *arg); | ||||
41 | | ||||
42 | WaylandPointer<zxdg_output_manager_v1, zxdg_output_manager_v1_destroy> xdgoutputmanager; | ||||
43 | EventQueue *queue = nullptr; | ||||
44 | }; | ||||
45 | | ||||
46 | XdgOutputManager::XdgOutputManager(QObject *parent) | ||||
47 | : QObject(parent) | ||||
48 | , d(new Private) | ||||
49 | { | ||||
50 | } | ||||
51 | | ||||
52 | void XdgOutputManager::Private::setup(zxdg_output_manager_v1 *arg) | ||||
53 | { | ||||
54 | Q_ASSERT(arg); | ||||
55 | Q_ASSERT(!xdgoutputmanager); | ||||
56 | xdgoutputmanager.setup(arg); | ||||
57 | } | ||||
58 | | ||||
59 | XdgOutputManager::~XdgOutputManager() | ||||
60 | { | ||||
61 | release(); | ||||
62 | } | ||||
63 | | ||||
64 | void XdgOutputManager::setup(zxdg_output_manager_v1 *xdgoutputmanager) | ||||
65 | { | ||||
66 | d->setup(xdgoutputmanager); | ||||
67 | } | ||||
68 | | ||||
69 | void XdgOutputManager::release() | ||||
70 | { | ||||
71 | d->xdgoutputmanager.release(); | ||||
72 | } | ||||
73 | | ||||
74 | void XdgOutputManager::destroy() | ||||
75 | { | ||||
76 | d->xdgoutputmanager.destroy(); | ||||
77 | } | ||||
78 | | ||||
79 | XdgOutputManager::operator zxdg_output_manager_v1*() { | ||||
80 | return d->xdgoutputmanager; | ||||
81 | } | ||||
82 | | ||||
83 | XdgOutputManager::operator zxdg_output_manager_v1*() const { | ||||
84 | return d->xdgoutputmanager; | ||||
85 | } | ||||
86 | | ||||
87 | bool XdgOutputManager::isValid() const | ||||
88 | { | ||||
89 | return d->xdgoutputmanager.isValid(); | ||||
90 | } | ||||
91 | | ||||
92 | void XdgOutputManager::setEventQueue(EventQueue *queue) | ||||
93 | { | ||||
94 | d->queue = queue; | ||||
95 | } | ||||
96 | | ||||
97 | EventQueue *XdgOutputManager::eventQueue() | ||||
98 | { | ||||
99 | return d->queue; | ||||
100 | } | ||||
101 | | ||||
102 | XdgOutput *XdgOutputManager::getXdgOutput(Output *output, QObject *parent) | ||||
103 | { | ||||
104 | Q_ASSERT(isValid()); | ||||
105 | auto p = new XdgOutput(parent); | ||||
106 | auto w = zxdg_output_manager_v1_get_xdg_output(d->xdgoutputmanager, *output); | ||||
107 | if (d->queue) { | ||||
108 | d->queue->addProxy(w); | ||||
109 | } | ||||
110 | p->setup(w); | ||||
111 | return p; | ||||
112 | } | ||||
113 | | ||||
114 | struct XdgOutputBuffer | ||||
115 | { | ||||
116 | QPoint logicalPosition; | ||||
117 | QSize logicalSize; | ||||
118 | }; | ||||
119 | | ||||
120 | class XdgOutput::Private | ||||
121 | { | ||||
122 | public: | ||||
123 | Private(XdgOutput *q); | ||||
124 | | ||||
125 | void setup(zxdg_output_v1 *arg); | ||||
126 | | ||||
127 | WaylandPointer<zxdg_output_v1, zxdg_output_v1_destroy> xdgoutput; | ||||
128 | | ||||
129 | XdgOutputBuffer current; | ||||
130 | XdgOutputBuffer pending; | ||||
131 | | ||||
132 | private: | ||||
133 | XdgOutput *q; | ||||
134 | | ||||
135 | private: | ||||
136 | static void logical_positionCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y); | ||||
137 | static void logical_sizeCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height); | ||||
138 | static void doneCallback(void *data, zxdg_output_v1 *zxdg_output_v1); | ||||
139 | | ||||
140 | static const zxdg_output_v1_listener s_listener; | ||||
141 | }; | ||||
142 | | ||||
143 | const zxdg_output_v1_listener XdgOutput::Private::s_listener = { | ||||
144 | logical_positionCallback, | ||||
145 | logical_sizeCallback, | ||||
146 | doneCallback | ||||
147 | }; | ||||
148 | | ||||
149 | void XdgOutput::Private::logical_positionCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y) | ||||
150 | { | ||||
151 | auto p = reinterpret_cast<XdgOutput::Private*>(data); | ||||
152 | Q_ASSERT(p->xdgoutput == zxdg_output_v1); | ||||
153 | p->pending.logicalPosition = QPoint(x,y); | ||||
154 | } | ||||
155 | | ||||
156 | void XdgOutput::Private::logical_sizeCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height) | ||||
157 | { | ||||
158 | auto p = reinterpret_cast<XdgOutput::Private*>(data); | ||||
159 | Q_ASSERT(p->xdgoutput == zxdg_output_v1); | ||||
160 | p->pending.logicalSize = QSize(width,height); | ||||
161 | } | ||||
162 | | ||||
163 | void XdgOutput::Private::doneCallback(void *data, zxdg_output_v1 *zxdg_output_v1) | ||||
164 | { | ||||
165 | auto p = reinterpret_cast<XdgOutput::Private*>(data); | ||||
166 | Q_ASSERT(p->xdgoutput == zxdg_output_v1); | ||||
167 | std::swap(p->current, p->pending); | ||||
168 | | ||||
169 | if (p->current.logicalSize != p->pending.logicalSize || | ||||
170 | p->current.logicalPosition != p->pending.logicalPosition) { | ||||
171 | emit p->q->changed(); | ||||
172 | } | ||||
173 | } | ||||
174 | | ||||
175 | XdgOutput::Private::Private(XdgOutput *q) | ||||
176 | : q(q) | ||||
177 | { | ||||
178 | } | ||||
179 | | ||||
180 | XdgOutput::XdgOutput(QObject *parent) | ||||
181 | : QObject(parent) | ||||
182 | , d(new Private(this)) | ||||
183 | { | ||||
184 | } | ||||
185 | | ||||
186 | void XdgOutput::Private::setup(zxdg_output_v1 *arg) | ||||
187 | { | ||||
188 | Q_ASSERT(arg); | ||||
189 | Q_ASSERT(!xdgoutput); | ||||
190 | xdgoutput.setup(arg); | ||||
191 | zxdg_output_v1_add_listener(xdgoutput, &s_listener, this); | ||||
192 | } | ||||
193 | | ||||
194 | XdgOutput::~XdgOutput() | ||||
195 | { | ||||
196 | release(); | ||||
197 | } | ||||
198 | | ||||
199 | void XdgOutput::setup(zxdg_output_v1 *xdgoutput) | ||||
200 | { | ||||
201 | d->setup(xdgoutput); | ||||
202 | } | ||||
203 | | ||||
204 | void XdgOutput::release() | ||||
205 | { | ||||
206 | d->xdgoutput.release(); | ||||
207 | } | ||||
208 | | ||||
209 | void XdgOutput::destroy() | ||||
210 | { | ||||
211 | d->xdgoutput.destroy(); | ||||
212 | } | ||||
213 | | ||||
214 | QSize XdgOutput::logicalSize() const | ||||
215 | { | ||||
216 | return d->current.logicalSize; | ||||
217 | } | ||||
218 | | ||||
219 | QPoint XdgOutput::logicalPosition() const | ||||
220 | { | ||||
221 | return d->current.logicalPosition; | ||||
222 | } | ||||
223 | | ||||
224 | XdgOutput::operator zxdg_output_v1*() { | ||||
225 | return d->xdgoutput; | ||||
226 | } | ||||
227 | | ||||
228 | XdgOutput::operator zxdg_output_v1*() const { | ||||
229 | return d->xdgoutput; | ||||
230 | } | ||||
231 | | ||||
232 | bool XdgOutput::isValid() const | ||||
233 | { | ||||
234 | return d->xdgoutput.isValid(); | ||||
235 | } | ||||
236 | | ||||
237 | | ||||
238 | } | ||||
239 | } | ||||
240 | |