KWayland

xdgoutput.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "xdgoutput.h"
7 #include "event_queue.h"
8 #include "wayland_pointer_p.h"
9 #include "output.h"
10 
11 #include <wayland-xdg-output-unstable-v1-client-protocol.h>
12 #include <wayland-client-protocol.h>
13 
14 #include <QDebug>
15 
16 namespace KWayland
17 {
18 namespace Client
19 {
20 
21 class XdgOutputManager::Private
22 {
23 public:
24  Private() = default;
25 
26  void setup(zxdg_output_manager_v1 *arg);
27 
28  WaylandPointer<zxdg_output_manager_v1, zxdg_output_manager_v1_destroy> xdgoutputmanager;
29  EventQueue *queue = nullptr;
30 };
31 
33  : QObject(parent)
34  , d(new Private)
35 {
36 }
37 
38 void XdgOutputManager::Private::setup(zxdg_output_manager_v1 *arg)
39 {
40  Q_ASSERT(arg);
41  Q_ASSERT(!xdgoutputmanager);
42  xdgoutputmanager.setup(arg);
43 }
44 
45 XdgOutputManager::~XdgOutputManager()
46 {
47  release();
48 }
49 
50 void XdgOutputManager::setup(zxdg_output_manager_v1 *xdgoutputmanager)
51 {
52  d->setup(xdgoutputmanager);
53 }
54 
56 {
57  d->xdgoutputmanager.release();
58 }
59 
61 {
62  d->xdgoutputmanager.destroy();
63 }
64 
65 XdgOutputManager::operator zxdg_output_manager_v1*() {
66  return d->xdgoutputmanager;
67 }
68 
69 XdgOutputManager::operator zxdg_output_manager_v1*() const {
70  return d->xdgoutputmanager;
71 }
72 
74 {
75  return d->xdgoutputmanager.isValid();
76 }
77 
79 {
80  d->queue = queue;
81 }
82 
84 {
85  return d->queue;
86 }
87 
88 XdgOutput *XdgOutputManager::getXdgOutput(Output *output, QObject *parent)
89 {
90  Q_ASSERT(isValid());
91  auto p = new XdgOutput(parent);
92  auto w = zxdg_output_manager_v1_get_xdg_output(d->xdgoutputmanager, *output);
93  if (d->queue) {
94  d->queue->addProxy(w);
95  }
96  p->setup(w);
97  return p;
98 }
99 
100 struct XdgOutputBuffer
101 {
102  QPoint logicalPosition;
103  QSize logicalSize;
104  QString name;
105  QString description;
106 };
107 
108 class XdgOutput::Private
109 {
110 public:
111  Private(XdgOutput *q);
112 
113  void setup(zxdg_output_v1 *arg);
114 
115  WaylandPointer<zxdg_output_v1, zxdg_output_v1_destroy> xdgoutput;
116 
117  XdgOutputBuffer current;
118  XdgOutputBuffer pending;
119 
120 private:
121  XdgOutput *q;
122 
123 private:
124  static void logical_positionCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y);
125  static void logical_sizeCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height);
126  static void doneCallback(void *data, zxdg_output_v1 *zxdg_output_v1);
127  static void nameCallback(void *data, zxdg_output_v1 *zxdg_output_v1, const char *name);
128  static void descriptionCallback(void *data, zxdg_output_v1 *zxdg_output_v1, const char *description);
129 
130  static const zxdg_output_v1_listener s_listener;
131 };
132 
133 const zxdg_output_v1_listener XdgOutput::Private::s_listener = {
134  logical_positionCallback,
135  logical_sizeCallback,
136  doneCallback,
137  nameCallback,
138  descriptionCallback
139 };
140 
141 void XdgOutput::Private::logical_positionCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y)
142 {
143  auto p = reinterpret_cast<XdgOutput::Private*>(data);
144  Q_ASSERT(p->xdgoutput == zxdg_output_v1);
145  p->pending.logicalPosition = QPoint(x,y);
146 }
147 
148 void XdgOutput::Private::logical_sizeCallback(void *data, zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height)
149 {
150  auto p = reinterpret_cast<XdgOutput::Private*>(data);
151  Q_ASSERT(p->xdgoutput == zxdg_output_v1);
152  p->pending.logicalSize = QSize(width,height);
153 }
154 
155 void XdgOutput::Private::nameCallback(void *data, zxdg_output_v1 *zxdg_output_v1, const char *name)
156 {
157  auto p = reinterpret_cast<XdgOutput::Private*>(data);
158  Q_ASSERT(p->xdgoutput == zxdg_output_v1);
159  p->pending.name = name;
160 }
161 
162 void XdgOutput::Private::descriptionCallback(void *data, zxdg_output_v1 *zxdg_output_v1, const char *description)
163 {
164  auto p = reinterpret_cast<XdgOutput::Private*>(data);
165  Q_ASSERT(p->xdgoutput == zxdg_output_v1);
166  p->pending.description = description;
167 }
168 
169 
170 void XdgOutput::Private::doneCallback(void *data, zxdg_output_v1 *zxdg_output_v1)
171 {
172  auto p = reinterpret_cast<XdgOutput::Private*>(data);
173  Q_ASSERT(p->xdgoutput == zxdg_output_v1);
174  std::swap(p->current, p->pending);
175 
176  emit p->q->changed();
177 }
178 
179 XdgOutput::Private::Private(XdgOutput *qptr)
180  : q(qptr)
181 {
182 }
183 
184 XdgOutput::XdgOutput(QObject *parent)
185  : QObject(parent)
186  , d(new Private(this))
187 {
188 }
189 
190 void XdgOutput::Private::setup(zxdg_output_v1 *arg)
191 {
192  Q_ASSERT(arg);
193  Q_ASSERT(!xdgoutput);
194  xdgoutput.setup(arg);
195  zxdg_output_v1_add_listener(xdgoutput, &s_listener, this);
196 }
197 
198 XdgOutput::~XdgOutput()
199 {
200  release();
201 }
202 
203 void XdgOutput::setup(zxdg_output_v1 *xdgoutput)
204 {
205  d->setup(xdgoutput);
206 }
207 
209 {
210  d->xdgoutput.release();
211 }
212 
214 {
215  d->xdgoutput.destroy();
216 }
217 
219 {
220  return d->current.logicalSize;
221 }
222 
224 {
225  return d->current.logicalPosition;
226 }
227 
229 {
230  return d->current.name;
231 }
232 
234 {
235  return d->current.description;
236 }
237 
238 XdgOutput::operator zxdg_output_v1*() {
239  return d->xdgoutput;
240 }
241 
242 XdgOutput::operator zxdg_output_v1*() const {
243  return d->xdgoutput;
244 }
245 
246 bool XdgOutput::isValid() const
247 {
248  return d->xdgoutput.isValid();
249 }
250 
251 
252 }
253 }
254 
QSize logicalSize() const
The size of the output in compositor co-ordinates (i.e pixel size / output scale) ...
Definition: xdgoutput.cpp:218
QString description() const
A longer human readable description.
Definition: xdgoutput.cpp:233
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
QString name() const
A consistent unique name for this monitor.
Definition: xdgoutput.cpp:228
void destroy()
Destroys the data held by this XdgOutput.
Definition: xdgoutput.cpp:213
Wrapper for the wl_output interface.
Definition: output.h:55
XdgOutputManager(QObject *parent=nullptr)
Creates a new XdgOutputManager.
Definition: xdgoutput.cpp:32
void destroy()
Destroys the data held by this XdgOutputManager.
Definition: xdgoutput.cpp:60
void release()
Releases the zxdg_output_manager_v1 interface.
Definition: xdgoutput.cpp:55
Wrapper for the zxdg_output_v1 interface.
Definition: xdgoutput.h:144
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this XdgOutputManager.
Definition: xdgoutput.cpp:78
QPoint logicalPosition() const
The top left position of the output in compositor co-ordinates.
Definition: xdgoutput.cpp:223
void release()
Releases the zxdg_output_v1 interface.
Definition: xdgoutput.cpp:208
void setup(zxdg_output_v1 *xdgoutput)
Setup this XdgOutput to manage the xdgoutput.
Definition: xdgoutput.cpp:203
void setup(zxdg_output_manager_v1 *xdgoutputmanager)
Setup this XdgOutputManager to manage the xdgoutputmanager.
Definition: xdgoutput.cpp:50
QObject(QObject *parent)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 22:48:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.