Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandxdgoutputv1.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QWaylandCompositor>
5
7#include "qwaylandoutput_p.h"
8
9#include <wayland-server.h>
10
12
92
100
101// QWaylandXdgOutputManagerV1Private
102
107{
109
112 if (!compositor) {
113 qCWarning(qLcWaylandCompositor) << "Failed to find QWaylandCompositor when initializing QWaylandXdgOutputManagerV1";
114 return;
115 }
116 d->init(compositor->display(), d->interfaceVersion());
117}
118
123{
124 return QWaylandXdgOutputManagerV1Private::interface();
125}
126
127// QWaylandXdgOutputManagerV1Private
128
130{
131 if (!xdgOutputs.contains(output)) {
132 xdgOutputs[output] = xdgOutput;
133 QWaylandOutputPrivate::get(output)->xdgOutput = xdgOutput;
134 }
135}
136
141
143 uint32_t id,
144 wl_resource *outputResource)
145{
147
148 // Verify if the associated output exist
149 auto *output = QWaylandOutput::fromResource(outputResource);
150 if (!output) {
151 qCWarning(qLcWaylandCompositor,
152 "The client is requesting a QWaylandXdgOutputV1 for a "
153 "QWaylandOutput that doesn't exist");
154 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "output not found");
155 return;
156 }
157
158 // Do we have a QWaylandXdgOutputV1 for this output?
159 if (!xdgOutputs.contains(output)) {
160 qCWarning(qLcWaylandCompositor,
161 "The client is requesting a QWaylandXdgOutputV1 that the compositor "
162 "didn't create before");
163 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT,
164 "compositor didn't create a QWaylandXdgOutputV1 for this zxdg_output_v1 object");
165 return;
166 }
167
168 // Bind QWaylandXdgOutputV1 and initialize
169 auto *xdgOutput = xdgOutputs[output];
170 auto *xdgOutputPrivate = QWaylandXdgOutputV1Private::get(xdgOutput);
171 Q_ASSERT(xdgOutputPrivate);
172 xdgOutputPrivate->setManager(q);
173 xdgOutputPrivate->setOutput(output);
174 xdgOutputPrivate->add(resource->client(), id, qMin(resource->version(), QWaylandXdgOutputV1Private::interfaceVersion()));
175}
176
177// QWaylandXdgOutputV1
178
183
186{
188
189 // Set members before emitting changed signals so that handlers will
190 // see both already set and not nullptr, avoiding potential crashes
191 d->manager = manager;
192 d->output = output;
193
194 QWaylandXdgOutputManagerV1Private::get(d->manager)->registerXdgOutput(output, this);
195
198}
199
201{
203
204 if (d->manager)
205 QWaylandXdgOutputManagerV1Private::get(d->manager)->unregisterXdgOutput(d->output);
206}
207
221{
222 Q_D(const QWaylandXdgOutputV1);
223 return d->manager;
224}
225
239{
240 Q_D(const QWaylandXdgOutputV1);
241 return d->output;
242}
243
273{
274 Q_D(const QWaylandXdgOutputV1);
275 return d->name;
276}
277
279{
281
282 if (d->name == name)
283 return;
284
285 // Can't change after clients bound to xdg-output
286 if (d->initialized) {
287 qCWarning(qLcWaylandCompositor, "QWaylandXdgOutputV1::name cannot be changed after initialization");
288 return;
289 }
290
291 d->name = name;
293}
294
314{
315 Q_D(const QWaylandXdgOutputV1);
316 return d->description;
317}
318
320{
322
323 if (d->description == description)
324 return;
325
326 // Can't change after clients bound to xdg-output
327 if (d->initialized) {
328 qCWarning(qLcWaylandCompositor, "QWaylandXdgOutputV1::description cannot be changed after initialization");
329 return;
330 }
331
332 d->description = description;
334}
335
351{
352 Q_D(const QWaylandXdgOutputV1);
353 return d->logicalPos;
354}
355
357{
359
360 if (d->logicalPos == position)
361 return;
362
363 d->logicalPos = position;
364 if (d->initialized) {
365 d->sendLogicalPosition(position);
366 d->sendDone();
367 }
370}
371
403{
404 Q_D(const QWaylandXdgOutputV1);
405 return d->logicalSize;
406}
407
409{
411
412 if (d->logicalSize == size)
413 return;
414
415 d->logicalSize = size;
416 if (d->initialized) {
417 d->sendLogicalSize(size);
418 d->sendDone();
419 }
422}
423
445{
446 Q_D(const QWaylandXdgOutputV1);
447 return QRect(d->logicalPos, d->logicalSize);
448}
449
450// QWaylandXdgOutputV1Private
451
453{
454 const auto values = resourceMap().values();
455 for (auto *resource : values)
456 send_logical_position(resource->handle, position.x(), position.y());
457 needToSendDone = true;
458}
459
461{
462 const auto values = resourceMap().values();
463 for (auto *resource : values)
464 send_logical_size(resource->handle, size.width(), size.height());
465 needToSendDone = true;
466}
467
469{
470 if (needToSendDone) {
471 const auto values = resourceMap().values();
472 for (auto *resource : values) {
473 if (resource->version() < 3)
474 send_done(resource->handle);
475 }
476 needToSendDone = false;
477 }
478}
479
481{
483
484 if (!_manager) {
485 qCWarning(qLcWaylandCompositor,
486 "Cannot associate a null QWaylandXdgOutputManagerV1 to QWaylandXdgOutputV1 %p", this);
487 return;
488 }
489
490 if (manager == _manager)
491 return;
492
493 if (manager) {
494 qCWarning(qLcWaylandCompositor,
495 "Cannot associate a different QWaylandXdgOutputManagerV1 to QWaylandXdgOutputV1 %p "
496 "after initialization", this);
497 return;
498 }
499
500 manager = _manager;
501 emit q->managerChanged();
502}
503
505{
507
508 if (!_output) {
509 qCWarning(qLcWaylandCompositor,
510 "Cannot associate a null QWaylandOutput to QWaylandXdgOutputV1 %p", this);
511 return;
512 }
513
514 if (output == _output)
515 return;
516
517 if (output) {
518 qCWarning(qLcWaylandCompositor,
519 "Cannot associate a different QWaylandOutput to QWaylandXdgOutputV1 %p "
520 "after initialization", this);
521 return;
522 }
523
524 // Assign output above manager, to make both values valid in handlers
525 output = _output;
526
527 if (!manager) {
528 // Try to find the manager from the output parents
529 for (auto *p = output->parent(); p != nullptr; p = p->parent()) {
530 if (auto *m = qobject_cast<QWaylandXdgOutputManagerV1 *>(p)) {
531 manager = m;
532 emit q->managerChanged();
533 break;
534 }
535 }
536 }
537
538 emit q->outputChanged();
539
540 // Register the output
541 if (manager)
543}
544
546{
547 send_logical_position(resource->handle, logicalPos.x(), logicalPos.y());
548 send_logical_size(resource->handle, logicalSize.width(), logicalSize.height());
549 if (resource->version() >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)
550 send_name(resource->handle, name);
551 if (resource->version() >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION)
552 send_description(resource->handle, description);
553 send_done(resource->handle);
554
555 initialized = true;
556}
557
559{
560 wl_resource_destroy(resource->handle);
561}
562
564
565#include "moc_qwaylandxdgoutputv1.cpp"
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
virtual void initialize()
Initializes the QWaylandCompositorExtension.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
static QWaylandOutputPrivate * get(QWaylandOutput *output)
\qmltype WaylandOutput \instantiates QWaylandOutput \inqmlmodule QtWayland.Compositor
static QWaylandOutput * fromResource(wl_resource *resource)
Returns the QWaylandOutput corresponding to resource.
static QWaylandXdgOutputManagerV1Private * get(QWaylandXdgOutputManagerV1 *manager)
void unregisterXdgOutput(QWaylandOutput *output)
void zxdg_output_manager_v1_get_xdg_output(Resource *resource, uint32_t id, wl_resource *outputResource) override
void registerXdgOutput(QWaylandOutput *output, QWaylandXdgOutputV1 *xdgOutput)
\qmltype XdgOutputManagerV1 \instantiates QWaylandXdgOutputManagerV1 \inqmlmodule QtWayland....
static const wl_interface * interface()
Returns the Wayland interface for QWaylandXdgOutputManagerV1.
void initialize() override
Initializes the extension.
QWaylandXdgOutputManagerV1()
Constructs a QWaylandXdgOutputManagerV1 object.
void zxdg_output_v1_destroy(Resource *resource) override
void sendLogicalSize(const QSize &size)
void sendLogicalPosition(const QPoint &position)
QWaylandXdgOutputManagerV1 * manager
static QWaylandXdgOutputV1Private * get(QWaylandXdgOutputV1 *xdgOutput)
void zxdg_output_v1_bind_resource(Resource *resource) override
void setOutput(QWaylandOutput *output)
void setManager(QWaylandXdgOutputManagerV1 *manager)
QPoint logicalPosition
\qmlproperty point XdgOutputV1::logicalPosition
QRect logicalGeometry
\qmlproperty rect XdgOutputV1::logicalGeometry \readonly
void logicalGeometryChanged()
QString name
\qmlproperty string XdgOutputV1::name
QWaylandOutput * output
\qmlproperty WaylandOutput XdgOutputV1::output \readonly
QSize logicalSize
\qmlproperty size XdgOutputV1::logicalSize
void setLogicalSize(const QSize &size)
QString description
\qmlproperty string XdgOutputV1::description
void setName(const QString &name)
void setDescription(const QString &name)
void setLogicalPosition(const QPoint &position)
QWaylandXdgOutputManagerV1 * manager
\qmlproperty XdgOutputManagerV1 XdgOutputV1::manager \readonly
void logicalPositionChanged()
Combined button and popup list for selecting options.
#define qCWarning(category,...)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
static QOpenGLCompositor * compositor
GLenum GLsizei GLsizei GLint * values
[15]
const GLfloat * m
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint name
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QT_BEGIN_NAMESPACE typedef uchar * output
QNetworkAccessManager manager