1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qwaylandivisurface.h"
5#include "qwaylandivisurface_p.h"
6#include "qwaylandiviapplication_p.h"
7#if QT_CONFIG(wayland_compositor_quick)
8#include "qwaylandivisurfaceintegration_p.h"
9#endif
10
11#include <QtWaylandCompositor/QWaylandResource>
12#include <QDebug>
13
14#include <QtWaylandCompositor/private/qwaylandutils_p.h>
15
16QT_BEGIN_NAMESPACE
17
18QWaylandSurfaceRole QWaylandIviSurfacePrivate::s_role("ivi_surface");
19
20/*!
21 * \qmltype IviSurface
22 * \instantiates QWaylandIviSurface
23 * \inqmlmodule QtWayland.Compositor.IviApplication
24 * \since 5.8
25 * \brief Provides a simple way to identify and resize a surface.
26 *
27 * This type is part of the \l{IviApplication} extension and provides a way to extend
28 * the functionality of an existing WaylandSurface with a way to resize and identify it.
29 *
30 * It corresponds to the Wayland \c ivi_surface interface.
31 */
32
33/*!
34 * \class QWaylandIviSurface
35 * \inmodule QtWaylandCompositor
36 * \since 5.8
37 * \brief The QWaylandIviSurface class provides a simple way to identify and resize a surface.
38 *
39 * This class is part of the QWaylandIviApplication extension and provides a way to
40 * extend the functionality of an existing QWaylandSurface with a way to resize and identify it.
41 *
42 * It corresponds to the Wayland \c ivi_surface interface.
43 */
44
45/*!
46 * Constructs a QWaylandIviSurface.
47 */
48QWaylandIviSurface::QWaylandIviSurface()
49 : QWaylandShellSurfaceTemplate<QWaylandIviSurface>(*new QWaylandIviSurfacePrivate())
50{
51}
52
53/*!
54 * Constructs a QWaylandIviSurface for \a surface and initializes it with the
55 * given \a application, \a surface, \a iviId, and \a resource.
56 */
57QWaylandIviSurface::QWaylandIviSurface(QWaylandIviApplication *application, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource)
58 : QWaylandShellSurfaceTemplate<QWaylandIviSurface>(*new QWaylandIviSurfacePrivate())
59{
60 initialize(iviApplication: application, surface, iviId, resource);
61}
62
63/*!
64 * \qmlmethod void IviSurface::initialize(IviApplication iviApplication, WaylandSurface surface, int iviId, WaylandResource resource)
65 *
66 * Initializes the IviSurface, associating it with the given \a iviApplication, \a surface,
67 * \a iviId, and \a resource.
68 */
69
70/*!
71 * Initializes the QWaylandIviSurface, associating it with the given \a iviApplication, \a surface,
72 * \a iviId, and \a resource.
73 */
74void QWaylandIviSurface::initialize(QWaylandIviApplication *iviApplication, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource)
75{
76 Q_D(QWaylandIviSurface);
77
78 d->m_iviApplication = iviApplication;
79 d->m_surface = surface;
80 d->m_iviId = iviId;
81
82 d->init(resource.resource());
83 setExtensionContainer(surface);
84
85 emit surfaceChanged();
86 emit iviIdChanged();
87
88 QWaylandCompositorExtension::initialize();
89}
90
91/*!
92 * \qmlproperty WaylandSurface IviSurface::surface
93 *
94 * This property holds the surface associated with this IviSurface.
95 */
96
97/*!
98 * \property QWaylandIviSurface::surface
99 *
100 * This property holds the surface associated with this QWaylandIviSurface.
101 */
102QWaylandSurface *QWaylandIviSurface::surface() const
103{
104 Q_D(const QWaylandIviSurface);
105 return d->m_surface;
106}
107
108/*!
109 * \qmlproperty int IviSurface::iviId
110 * \readonly
111 *
112 * This property holds the ivi id id of this IviSurface.
113 */
114
115/*!
116 * \property QWaylandIviSurface::iviId
117 *
118 * This property holds the ivi id of this QWaylandIviSurface.
119 */
120uint QWaylandIviSurface::iviId() const
121{
122 Q_D(const QWaylandIviSurface);
123 return d->m_iviId;
124}
125
126/*!
127 * Returns the Wayland interface for the QWaylandIviSurface.
128 */
129const struct wl_interface *QWaylandIviSurface::interface()
130{
131 return QWaylandIviSurfacePrivate::interface();
132}
133
134QByteArray QWaylandIviSurface::interfaceName()
135{
136 return QWaylandIviSurfacePrivate::interfaceName();
137}
138
139/*!
140 * Returns the surface role for the QWaylandIviSurface.
141 */
142QWaylandSurfaceRole *QWaylandIviSurface::role()
143{
144 return &QWaylandIviSurfacePrivate::s_role;
145}
146
147/*!
148 * Returns the QWaylandIviSurface corresponding to the \a resource.
149 */
150QWaylandIviSurface *QWaylandIviSurface::fromResource(wl_resource *resource)
151{
152 if (auto p = QtWayland::fromResource<QWaylandIviSurfacePrivate *>(resource))
153 return p->q_func();
154 return nullptr;
155}
156
157/*!
158 * \qmlmethod int IviSurface::sendConfigure(size size)
159 *
160 * Sends a configure event to the client, telling it to resize the surface to the given \a size.
161 */
162
163/*!
164 * Sends a configure event to the client, telling it to resize the surface to the given \a size.
165 */
166void QWaylandIviSurface::sendConfigure(const QSize &size)
167{
168 if (!size.isValid()) {
169 qWarning() << "Can't configure ivi_surface with an invalid size" << size;
170 return;
171 }
172 Q_D(QWaylandIviSurface);
173 d->send_configure(size.width(), size.height());
174}
175
176#if QT_CONFIG(wayland_compositor_quick)
177QWaylandQuickShellIntegration *QWaylandIviSurface::createIntegration(QWaylandQuickShellSurfaceItem *item)
178{
179 return new QtWayland::IviSurfaceIntegration(item);
180}
181#endif
182
183/*!
184 * \internal
185 */
186void QWaylandIviSurface::initialize()
187{
188 QWaylandShellSurfaceTemplate::initialize();
189}
190
191QWaylandIviSurfacePrivate::QWaylandIviSurfacePrivate()
192{
193}
194
195void QWaylandIviSurfacePrivate::ivi_surface_destroy_resource(QtWaylandServer::ivi_surface::Resource *resource)
196{
197 Q_UNUSED(resource);
198 Q_Q(QWaylandIviSurface);
199 QWaylandIviApplicationPrivate::get(iviApplication: m_iviApplication)->unregisterIviSurface(iviSurface: q);
200 delete q;
201}
202
203void QWaylandIviSurfacePrivate::ivi_surface_destroy(QtWaylandServer::ivi_surface::Resource *resource)
204{
205 wl_resource_destroy(resource->handle);
206}
207
208QT_END_NAMESPACE
209
210#include "moc_qwaylandivisurface.cpp"
211

source code of qtwayland/src/compositor/extensions/qwaylandivisurface.cpp