Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandiviapplication.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:critical reason:network-protocol
4
7
8#include <QtWaylandCompositor/QWaylandCompositor>
9#include <QtWaylandCompositor/QWaylandSurface>
10#include <QtWaylandCompositor/QWaylandIviSurface>
11#include <QtWaylandCompositor/QWaylandResource>
12
14
15/*!
16 * \qmltype IviApplication
17 * \nativetype QWaylandIviApplication
18 * \inqmlmodule QtWayland.Compositor.IviApplication
19 * \since 5.8
20 * \brief Provides a shell extension for embedded-style user interfaces.
21 *
22 * The IviApplication extension provides a way to associate an IviSurface
23 * with a regular Wayland surface. Using the IviSurface interface, the client can identify
24 * itself by giving an ivi id, and the compositor can ask the client to resize.
25 *
26 * IviApplication corresponds to the Wayland \c ivi_application interface.
27 *
28 * To provide the functionality of the shell extension in a compositor, create
29 * an instance of the IviApplication component and add it to the list of extensions
30 * supported by the compositor:
31 *
32 * \qml
33 * import QtWayland.Compositor.IviApplication
34 *
35 * WaylandCompositor {
36 * IviApplication {
37 * onIviSurfaceCreated: {
38 * if (iviSurface.iviId === navigationIviId) {
39 * // ...
40 * }
41 * }
42 * }
43 * }
44 * \endqml
45 */
46
47/*!
48 * \class QWaylandIviApplication
49 * \inmodule QtWaylandCompositor
50 * \since 5.8
51 * \brief The QWaylandIviApplication class is an extension for embedded-style user interfaces.
52 *
53 * The QWaylandIviApplication extension provides a way to associate an QWaylandIviSurface
54 * with a regular Wayland surface. Using the QWaylandIviSurface interface, the client can identify
55 * itself by giving an ivi id, and the compositor can ask the client to resize.
56 *
57 * QWaylandIviApplication corresponds to the Wayland \c ivi_application interface.
58 */
59
60/*!
61 * Constructs a QWaylandIviApplication object.
62 */
63QWaylandIviApplication::QWaylandIviApplication()
64 : QWaylandCompositorExtensionTemplate<QWaylandIviApplication>(*new QWaylandIviApplicationPrivate())
65{
66}
67
68/*!
69 * Constructs a QWaylandIviApplication object for the provided \a compositor.
70 */
71QWaylandIviApplication::QWaylandIviApplication(QWaylandCompositor *compositor)
72 : QWaylandCompositorExtensionTemplate<QWaylandIviApplication>(compositor, *new QWaylandIviApplicationPrivate())
73{
74}
75
76/*!
77 * Initializes the shell extension.
78 */
79void QWaylandIviApplication::initialize()
80{
81 Q_D(QWaylandIviApplication);
82 QWaylandCompositorExtensionTemplate::initialize();
83
84 QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
85 if (!compositor) {
86 qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandIviApplication";
87 return;
88 }
89
90 d->init(compositor->display(), 1);
91}
92
93/*!
94 * Returns the Wayland interface for the QWaylandIviApplication.
95 */
96const struct wl_interface *QWaylandIviApplication::interface()
97{
98 return QWaylandIviApplicationPrivate::interface();
99}
100
101/*!
102 * \internal
103 */
104QByteArray QWaylandIviApplication::interfaceName()
105{
106 return QWaylandIviApplicationPrivate::interfaceName();
107}
108
109/*!
110 * \qmlsignal void IviApplication::iviSurfaceRequested(WaylandSurface surface, int iviId, WaylandResource resource)
111 *
112 * This signal is emitted when the client has requested an \c ivi_surface to be associated
113 * with \a surface, which is identified by \a iviId. The handler for this signal is
114 * expected to create the ivi surface for \a resource and initialize it within the scope of the
115 * signal emission. If no ivi surface is created, a default one will be created instead.
116 *
117 */
118
119/*!
120 * \fn void QWaylandIviApplication::iviSurfaceRequested(QWaylandSurface *surface, uint iviId, const QWaylandResource &resource)
121 *
122 * This signal is emitted when the client has requested an \c ivi_surface to be associated
123 * with \a surface, which is identified by \a iviId. The handler for this signal is
124 * expected to create the ivi surface for \a resource and initialize it within the scope of the
125 * signal emission. If no ivi surface is created, a default one will be created instead.
126 */
127
128/*!
129 * \qmlsignal void IviApplication::iviSurfaceCreated(IviSurface *iviSurface)
130 *
131 * This signal is emitted when an IviSurface has been created. The supplied \a iviSurface is
132 * most commonly used to instantiate a ShellSurfaceItem.
133 */
134
135/*!
136 * \fn void QWaylandIviApplication::iviSurfaceCreated(QWaylandIviSurface *iviSurface)
137 *
138 * This signal is emitted when an IviSurface, \a iviSurface, has been created.
139 */
140
141QWaylandIviApplicationPrivate::QWaylandIviApplicationPrivate()
142{
143}
144
145void QWaylandIviApplicationPrivate::unregisterIviSurface(QWaylandIviSurface *iviSurface)
146{
147 m_iviSurfaces.remove(iviSurface->iviId());
148}
149
150void QWaylandIviApplicationPrivate::ivi_application_surface_create(QtWaylandServer::ivi_application::Resource *resource,
151 uint32_t ivi_id, wl_resource *surfaceResource, uint32_t id)
152{
153 Q_Q(QWaylandIviApplication);
154 QWaylandSurface *surface = QWaylandSurface::fromResource(surfaceResource);
155
156 if (m_iviSurfaces.contains(ivi_id)) {
157 wl_resource_post_error(resource->handle, IVI_APPLICATION_ERROR_IVI_ID,
158 "Given ivi_id, %d, is already assigned to wl_surface@%d", ivi_id,
159 wl_resource_get_id(m_iviSurfaces[ivi_id]->surface()->resource()));
160 return;
161 }
162
163 if (!surface->setRole(QWaylandIviSurface::role(), resource->handle, IVI_APPLICATION_ERROR_ROLE))
164 return;
165
166 QWaylandResource iviSurfaceResource(wl_resource_create(resource->client(), &ivi_surface_interface,
167 wl_resource_get_version(resource->handle), id));
168
169 emit q->iviSurfaceRequested(surface, ivi_id, iviSurfaceResource);
170
171 QWaylandIviSurface *iviSurface = QWaylandIviSurface::fromResource(iviSurfaceResource.resource());
172
173 if (!iviSurface)
174 iviSurface = new QWaylandIviSurface(q, surface, ivi_id, iviSurfaceResource);
175
176 m_iviSurfaces.insert(ivi_id, iviSurface);
177
178 emit q->iviSurfaceCreated(iviSurface);
179}
180
181QT_END_NAMESPACE
182
183#include "moc_qwaylandiviapplication.cpp"
Combined button and popup list for selecting options.