1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qwaylandiviapplication.h"
#include "qwaylandiviapplication_p.h"
#include <QtWaylandCompositor/QWaylandCompositor>
#include <QtWaylandCompositor/QWaylandSurface>
#include <QtWaylandCompositor/QWaylandIviSurface>
#include <QtWaylandCompositor/QWaylandResource>
QT_BEGIN_NAMESPACE
/*!
* \qmltype IviApplication
* \instantiates QWaylandIviApplication
* \inqmlmodule QtWayland.Compositor.IviApplication
* \since 5.8
* \brief Provides a shell extension for embedded-style user interfaces.
*
* The IviApplication extension provides a way to associate an IviSurface
* with a regular Wayland surface. Using the IviSurface interface, the client can identify
* itself by giving an ivi id, and the compositor can ask the client to resize.
*
* IviApplication corresponds to the Wayland \c ivi_application interface.
*
* To provide the functionality of the shell extension in a compositor, create
* an instance of the IviApplication component and add it to the list of extensions
* supported by the compositor:
*
* \qml
* import QtWayland.Compositor.IviApplication
*
* WaylandCompositor {
* IviApplication {
* onIviSurfaceCreated: {
* if (iviSurface.iviId === navigationIviId) {
* // ...
* }
* }
* }
* }
* \endqml
*/
/*!
* \class QWaylandIviApplication
* \inmodule QtWaylandCompositor
* \since 5.8
* \brief The QWaylandIviApplication class is an extension for embedded-style user interfaces.
*
* The QWaylandIviApplication extension provides a way to associate an QWaylandIviSurface
* with a regular Wayland surface. Using the QWaylandIviSurface interface, the client can identify
* itself by giving an ivi id, and the compositor can ask the client to resize.
*
* QWaylandIviApplication corresponds to the Wayland \c ivi_application interface.
*/
/*!
* Constructs a QWaylandIviApplication object.
*/
QWaylandIviApplication::QWaylandIviApplication()
: QWaylandCompositorExtensionTemplate<QWaylandIviApplication>(*new QWaylandIviApplicationPrivate())
{
}
/*!
* Constructs a QWaylandIviApplication object for the provided \a compositor.
*/
QWaylandIviApplication::QWaylandIviApplication(QWaylandCompositor *compositor)
: QWaylandCompositorExtensionTemplate<QWaylandIviApplication>(compositor, *new QWaylandIviApplicationPrivate())
{
}
/*!
* Initializes the shell extension.
*/
void QWaylandIviApplication::initialize()
{
Q_D(QWaylandIviApplication);
QWaylandCompositorExtensionTemplate::initialize();
QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
if (!compositor) {
qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandIviApplication";
return;
}
d->init(compositor->display(), 1);
}
/*!
* Returns the Wayland interface for the QWaylandIviApplication.
*/
const struct wl_interface *QWaylandIviApplication::interface()
{
return QWaylandIviApplicationPrivate::interface();
}
/*!
* \internal
*/
QByteArray QWaylandIviApplication::interfaceName()
{
return QWaylandIviApplicationPrivate::interfaceName();
}
/*!
* \qmlsignal void QtWaylandCompositor::IviApplication::iviSurfaceRequested(WaylandSurface surface, int iviId, WaylandResource resource)
*
* This signal is emitted when the client has requested an \c ivi_surface to be associated
* with \a surface, which is identified by \a iviId. The handler for this signal is
* expected to create the ivi surface for \a resource and initialize it within the scope of the
* signal emission. If no ivi surface is created, a default one will be created instead.
*
*/
/*!
* \fn void QWaylandIviApplication::iviSurfaceRequested(QWaylandSurface *surface, uint iviId, const QWaylandResource &resource)
*
* This signal is emitted when the client has requested an \c ivi_surface to be associated
* with \a surface, which is identified by \a iviId. The handler for this signal is
* expected to create the ivi surface for \a resource and initialize it within the scope of the
* signal emission. If no ivi surface is created, a default one will be created instead.
*/
/*!
* \qmlsignal void QtWaylandCompositor::IviApplication::iviSurfaceCreated(IviSurface *iviSurface)
*
* This signal is emitted when an IviSurface has been created. The supplied \a iviSurface is
* most commonly used to instantiate a ShellSurfaceItem.
*/
/*!
* \fn void QWaylandIviApplication::iviSurfaceCreated(QWaylandIviSurface *iviSurface)
*
* This signal is emitted when an IviSurface, \a iviSurface, has been created.
*/
QWaylandIviApplicationPrivate::QWaylandIviApplicationPrivate()
{
}
void QWaylandIviApplicationPrivate::unregisterIviSurface(QWaylandIviSurface *iviSurface)
{
m_iviSurfaces.remove(iviSurface->iviId());
}
void QWaylandIviApplicationPrivate::ivi_application_surface_create(QtWaylandServer::ivi_application::Resource *resource,
uint32_t ivi_id, wl_resource *surfaceResource, uint32_t id)
{
Q_Q(QWaylandIviApplication);
QWaylandSurface *surface = QWaylandSurface::fromResource(surfaceResource);
if (m_iviSurfaces.contains(ivi_id)) {
wl_resource_post_error(resource->handle, IVI_APPLICATION_ERROR_IVI_ID,
"Given ivi_id, %d, is already assigned to wl_surface@%d", ivi_id,
wl_resource_get_id(m_iviSurfaces[ivi_id]->surface()->resource()));
return;
}
if (!surface->setRole(QWaylandIviSurface::role(), resource->handle, IVI_APPLICATION_ERROR_ROLE))
return;
QWaylandResource iviSurfaceResource(wl_resource_create(resource->client(), &ivi_surface_interface,
wl_resource_get_version(resource->handle), id));
emit q->iviSurfaceRequested(surface, ivi_id, iviSurfaceResource);
QWaylandIviSurface *iviSurface = QWaylandIviSurface::fromResource(iviSurfaceResource.resource());
if (!iviSurface)
iviSurface = new QWaylandIviSurface(q, surface, ivi_id, iviSurfaceResource);
m_iviSurfaces.insert(ivi_id, iviSurface);
emit q->iviSurfaceCreated(iviSurface);
}
QT_END_NAMESPACE
|