1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 or (at your option) any later version
20 ** approved by the KDE Free Qt Foundation. The licenses are as published by
21 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
22 ** included in the packaging of this file. Please review the following
23 ** information to ensure the GNU General Public License requirements will
24 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25 **
26 ** $QT_END_LICENSE$
27 **
28 ****************************************************************************/
29
30 #include "qwaylandivisurface.h"
31 #include "qwaylandivisurface_p.h"
32 #include "qwaylandiviapplication_p.h"
33 #if QT_CONFIG(wayland_compositor_quick)
34 #include "qwaylandivisurfaceintegration_p.h"
35 #endif
36
37 #include <QtWaylandCompositor/QWaylandResource>
38 #include <QDebug>
39
40 #include <QtWaylandCompositor/private/qwaylandutils_p.h>
41
42 QT_BEGIN_NAMESPACE
43
44 QWaylandSurfaceRole QWaylandIviSurfacePrivate::s_role("ivi_surface");
45
46 /*!
47 * \qmltype IviSurface
48 * \inqmlmodule QtWayland.Compositor
49 * \since 5.8
50 * \brief Provides a simple way to identify and resize a surface.
51 *
52 * This type is part of the \l{IviApplication} extension and provides a way to extend
53 * the functionality of an existing WaylandSurface with a way to resize and identify it.
54 *
55 * It corresponds to the Wayland \c ivi_surface interface.
56 */
57
58 /*!
59 * \class QWaylandIviSurface
60 * \inmodule QtWaylandCompositor
61 * \since 5.8
62 * \brief The QWaylandIviSurface class provides a simple way to identify and resize a surface.
63 *
64 * This class is part of the QWaylandIviApplication extension and provides a way to
65 * extend the functionality of an existing QWaylandSurface with a way to resize and identify it.
66 *
67 * It corresponds to the Wayland \c ivi_surface interface.
68 */
69
70 /*!
71 * Constructs a QWaylandIviSurface.
72 */
QWaylandIviSurface()73 QWaylandIviSurface::QWaylandIviSurface()
74 : QWaylandShellSurfaceTemplate<QWaylandIviSurface>(*new QWaylandIviSurfacePrivate())
75 {
76 }
77
78 /*!
79 * Constructs a QWaylandIviSurface for \a surface and initializes it with the
80 * given \a application, \a surface, \a iviId, and \a resource.
81 */
QWaylandIviSurface(QWaylandIviApplication * application,QWaylandSurface * surface,uint iviId,const QWaylandResource & resource)82 QWaylandIviSurface::QWaylandIviSurface(QWaylandIviApplication *application, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource)
83 : QWaylandShellSurfaceTemplate<QWaylandIviSurface>(*new QWaylandIviSurfacePrivate())
84 {
85 initialize(application, surface, iviId, resource);
86 }
87
88 /*!
89 * \qmlmethod void QtWaylandCompositor::IviSurface::initialize(IviApplication iviApplication, WaylandSurface surface, int iviId, WaylandResource resource)
90 *
91 * Initializes the IviSurface, associating it with the given \a iviApplication, \a surface,
92 * \a iviId, and \a resource.
93 */
94
95 /*!
96 * Initializes the QWaylandIviSurface, associating it with the given \a iviApplication, \a surface,
97 * \a iviId, and \a resource.
98 */
initialize(QWaylandIviApplication * iviApplication,QWaylandSurface * surface,uint iviId,const QWaylandResource & resource)99 void QWaylandIviSurface::initialize(QWaylandIviApplication *iviApplication, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource)
100 {
101 Q_D(QWaylandIviSurface);
102
103 d->m_iviApplication = iviApplication;
104 d->m_surface = surface;
105 d->m_iviId = iviId;
106
107 d->init(resource.resource());
108 setExtensionContainer(surface);
109
110 emit surfaceChanged();
111 emit iviIdChanged();
112
113 QWaylandCompositorExtension::initialize();
114 }
115
116 /*!
117 * \qmlproperty WaylandSurface QtWaylandCompositor::IviSurface::surface
118 *
119 * This property holds the surface associated with this IviSurface.
120 */
121
122 /*!
123 * \property QWaylandIviSurface::surface
124 *
125 * This property holds the surface associated with this QWaylandIviSurface.
126 */
surface() const127 QWaylandSurface *QWaylandIviSurface::surface() const
128 {
129 Q_D(const QWaylandIviSurface);
130 return d->m_surface;
131 }
132
133 /*!
134 * \qmlproperty int QtWaylandCompositor::IviSurface::iviId
135 * \readonly
136 *
137 * This property holds the ivi id id of this IviSurface.
138 */
139
140 /*!
141 * \property QWaylandIviSurface::iviId
142 *
143 * This property holds the ivi id of this QWaylandIviSurface.
144 */
iviId() const145 uint QWaylandIviSurface::iviId() const
146 {
147 Q_D(const QWaylandIviSurface);
148 return d->m_iviId;
149 }
150
151 /*!
152 * Returns the Wayland interface for the QWaylandIviSurface.
153 */
interface()154 const struct wl_interface *QWaylandIviSurface::interface()
155 {
156 return QWaylandIviSurfacePrivate::interface();
157 }
158
interfaceName()159 QByteArray QWaylandIviSurface::interfaceName()
160 {
161 return QWaylandIviSurfacePrivate::interfaceName();
162 }
163
164 /*!
165 * Returns the surface role for the QWaylandIviSurface.
166 */
role()167 QWaylandSurfaceRole *QWaylandIviSurface::role()
168 {
169 return &QWaylandIviSurfacePrivate::s_role;
170 }
171
172 /*!
173 * Returns the QWaylandIviSurface corresponding to the \a resource.
174 */
fromResource(wl_resource * resource)175 QWaylandIviSurface *QWaylandIviSurface::fromResource(wl_resource *resource)
176 {
177 if (auto p = QtWayland::fromResource<QWaylandIviSurfacePrivate *>(resource))
178 return p->q_func();
179 return nullptr;
180 }
181
182 /*!
183 * \qmlmethod int QtWaylandCompositor::IviSurface::sendConfigure(size size)
184 *
185 * Sends a configure event to the client, telling it to resize the surface to the given \a size.
186 */
187
188 /*!
189 * Sends a configure event to the client, telling it to resize the surface to the given \a size.
190 */
sendConfigure(const QSize & size)191 void QWaylandIviSurface::sendConfigure(const QSize &size)
192 {
193 if (!size.isValid()) {
194 qWarning() << "Can't configure ivi_surface with an invalid size" << size;
195 return;
196 }
197 Q_D(QWaylandIviSurface);
198 d->send_configure(size.width(), size.height());
199 }
200
201 #if QT_CONFIG(wayland_compositor_quick)
createIntegration(QWaylandQuickShellSurfaceItem * item)202 QWaylandQuickShellIntegration *QWaylandIviSurface::createIntegration(QWaylandQuickShellSurfaceItem *item)
203 {
204 return new QtWayland::IviSurfaceIntegration(item);
205 }
206 #endif
207
208 /*!
209 * \internal
210 */
initialize()211 void QWaylandIviSurface::initialize()
212 {
213 QWaylandShellSurfaceTemplate::initialize();
214 }
215
QWaylandIviSurfacePrivate()216 QWaylandIviSurfacePrivate::QWaylandIviSurfacePrivate()
217 {
218 }
219
ivi_surface_destroy_resource(QtWaylandServer::ivi_surface::Resource * resource)220 void QWaylandIviSurfacePrivate::ivi_surface_destroy_resource(QtWaylandServer::ivi_surface::Resource *resource)
221 {
222 Q_UNUSED(resource);
223 Q_Q(QWaylandIviSurface);
224 QWaylandIviApplicationPrivate::get(m_iviApplication)->unregisterIviSurface(q);
225 delete q;
226 }
227
ivi_surface_destroy(QtWaylandServer::ivi_surface::Resource * resource)228 void QWaylandIviSurfacePrivate::ivi_surface_destroy(QtWaylandServer::ivi_surface::Resource *resource)
229 {
230 wl_resource_destroy(resource->handle);
231 }
232
233 QT_END_NAMESPACE
234