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

KDE's Doxygen guidelines are available online.