summaryrefslogtreecommitdiffstats
path: root/examples/wayland/minimal-qml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/wayland/minimal-qml')
-rw-r--r--examples/wayland/minimal-qml/CMakeLists.txt48
-rw-r--r--examples/wayland/minimal-qml/doc/images/minimal-qml.pngbin0 -> 11721 bytes
-rw-r--r--examples/wayland/minimal-qml/doc/src/minimal-qml.qdoc113
-rw-r--r--examples/wayland/minimal-qml/main.cpp51
-rw-r--r--examples/wayland/minimal-qml/main.qml89
5 files changed, 163 insertions, 138 deletions
diff --git a/examples/wayland/minimal-qml/CMakeLists.txt b/examples/wayland/minimal-qml/CMakeLists.txt
new file mode 100644
index 000000000..6834cd92f
--- /dev/null
+++ b/examples/wayland/minimal-qml/CMakeLists.txt
@@ -0,0 +1,48 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(minimal-qml LANGUAGES CXX)
+
+set(CMAKE_AUTOMOC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/minimal-qml")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
+
+qt_add_executable(minimal-qml
+ main.cpp
+)
+
+set_target_properties(minimal-qml PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(minimal-qml PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::Qml
+)
+
+# Resources:
+set(minimal-qml_resource_files
+ "main.qml"
+)
+
+qt6_add_resources(minimal-qml "minimal-qml"
+ PREFIX
+ "/"
+ FILES
+ ${minimal-qml_resource_files}
+)
+
+install(TARGETS minimal-qml
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/wayland/minimal-qml/doc/images/minimal-qml.png b/examples/wayland/minimal-qml/doc/images/minimal-qml.png
new file mode 100644
index 000000000..c950f933a
--- /dev/null
+++ b/examples/wayland/minimal-qml/doc/images/minimal-qml.png
Binary files differ
diff --git a/examples/wayland/minimal-qml/doc/src/minimal-qml.qdoc b/examples/wayland/minimal-qml/doc/src/minimal-qml.qdoc
index 5a435f3fc..2150fece3 100644
--- a/examples/wayland/minimal-qml/doc/src/minimal-qml.qdoc
+++ b/examples/wayland/minimal-qml/doc/src/minimal-qml.qdoc
@@ -1,36 +1,93 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** 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 Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
- * \title Qt Wayland Compositor Examples - Minimal QML
+ * \title Minimal QML
* \example minimal-qml
+ * \examplecategory {Embedded}
* \brief Minimal QML is a simple example that demonstrates how to write a Wayland compositor in QML.
* \ingroup qtwaylandcompositor-examples
*
* Minimal QML is a desktop-style Wayland compositor example implementing a
- * complete Qt Wayland Compositor with as little code as possible.
+ * complete Qt Wayland Compositor with as little code as possible. The compositor is implemented
+ * with Qt Quick and QML.
+ *
+ * \image minimal-qml.png
+ *
+ * \section1 The WaylandCompositor Object
+ *
+ * The top-level item of the compositor is a \l WaylandCompositor. This represents the Wayland
+ * server itself and manages the connections to clients as they come in.
+ *
+ * \snippet minimal-qml/main.qml compositor
+ *
+ * By default, the server supports the core Wayland protocol for communicating with clients.
+ * Usually, though, you will also want to support one or more extensions to the protocol. This
+ * gives the client more tools to influence its role in the windowing system.
+ *
+ * Qt supports several standard and common extensions. In addition, it is easy to create and support
+ * custom extensions, as long as support can be added in both the client and server code.
+ *
+ * \section1 Shell Extensions
+ *
+ * Typically, a compositor will support at least one
+ * \l{Shell Extensions - Qt Wayland Compositor}{shell extension}. Extensions are added to
+ * the compositor by instantiating them as direct children of the \l WaylandCompositor object. They
+ * will automatically be added to its \c extensions property and broadcast to clients when they
+ * connect.
+ *
+ * \snippet minimal-qml/main.qml shells
+ *
+ * The \e{Minimal QML} example supports three different shells: \l{WlShell}, \l{XdgShell} and
+ * \l{IviApplication}.
+ *
+ * A client can connect to either of these and it will be used as a channel for communicating
+ * about certain things between the client and compositor, such as creating new windows,
+ * negotiating size, and so on.
+ *
+ * When a client creates a new surface, its active extension will receive a signal of this. The
+ * signal contains a \l ShellSurface argument. Depending on which extension received the signal,
+ * this argument will be of a subclass of \l{ShellSurface}: \l{WlShellSurface}, \l{XdgSurface}
+ * or \l{IviSurface} respectively.
+ *
+ * The \l ShellSurface can be used to access features of the shell extension for the specific
+ * surface. In the \e{Minimal QML} example, we simply want to add the client to our scene. To
+ * record existence of the new window, we add it to a simple \l ListModel for safe-keeping.
+ *
+ * \snippet minimal-qml/main.qml model
+ *
+ * \section1 Creating the Scene
+ *
+ * Most of the necessary compositor code is already ready. The final step is to make sure
+ * applications are actually visible on the screen.
+ *
+ * For all compositors, we have to define at least one output. This is done by instantiating
+ * a \l WaylandOutput object as the direct child of the \l WaylandCompositor. If there is only
+ * a single output, this will represent the primary screen on the system. (You may also create
+ * multiple \l WaylandOutput objects to address multiple screens if they are available. See
+ * the \l{Multi Screen}{Multi Screen example} for more details
+ * about this.)
+ *
+ * \snippet minimal-qml/main.qml output
+ *
+ * Inside the \l{WaylandOutput}, we create a \l Window that serves as the container for
+ * our scene. In the example, we give this a size. The size used if the compositor is running as
+ * an application inside another windowing system which supports custom-sized windows. In a
+ * typical use case on an embedded device, where the compositor is the only display server running,
+ * it will probably be running on a full-screen platform plugin (such as \c{eglfs}) and the size
+ * set here will not matter.
+ *
+ * The final step is to create items for each of the \l ShellSurface objects that have been created.
+ * For this, we can use the \l ShellSurfaceItem class.
+ *
+ * \snippet minimal-qml/main.qml shell surface item
+ *
+ * We create a \l ShellSurfaceItem for each of the shell surfaces in our model, and assign them
+ * to the \c shellSurface property. In addition, we make sure the model is updated when the shell
+ * surface is destroyed. This can happen when a client manually closes a window, and if it exits
+ * or crashes.
+ *
+ * And this is all the code needed to create a functional Wayland compositor using Qt Quick and
+ * QML. For another example of a compositor written in QML but which has a few more features, take
+ * a look at the \l{Fancy Compositor}{Fancy Compositor example}.
*/
diff --git a/examples/wayland/minimal-qml/main.cpp b/examples/wayland/minimal-qml/main.cpp
index 60378e860..b187aa753 100644
--- a/examples/wayland/minimal-qml/main.cpp
+++ b/examples/wayland/minimal-qml/main.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/QUrl>
#include <QtCore/QDebug>
diff --git a/examples/wayland/minimal-qml/main.qml b/examples/wayland/minimal-qml/main.qml
index 63ed9da5f..e1e1c18d3 100644
--- a/examples/wayland/minimal-qml/main.qml
+++ b/examples/wayland/minimal-qml/main.qml
@@ -1,65 +1,28 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-import QtQuick 2.6
-import QtQuick.Window 2.2
-import QtWayland.Compositor 1.3
+import QtQuick
+import QtQuick.Window
+import QtWayland.Compositor
+import QtWayland.Compositor.XdgShell
+import QtWayland.Compositor.WlShell
+import QtWayland.Compositor.IviApplication
+//! [compositor]
WaylandCompositor {
+//! [compositor]
// The output defines the screen.
+
+ //! [output]
WaylandOutput {
sizeFollowsWindow: true
window: Window {
width: 1024
height: 768
visible: true
+ //! [output]
+
+ //! [shell surface item]
Repeater {
model: shellSurfaces
// ShellSurfaceItem handles displaying a shell surface.
@@ -67,29 +30,33 @@ WaylandCompositor {
// resize/move, and forwarding of mouse and keyboard
// events to the client process.
ShellSurfaceItem {
- autoCreatePopupItems: true
shellSurface: modelData
onSurfaceDestroyed: shellSurfaces.remove(index)
}
}
+ //! [shell surface item]
}
}
+
// Extensions are additions to the core Wayland
// protocol. We choose to support three different
// shells (window management protocols). When the
// client creates a new shell surface (i.e. a window)
// we append it to our list of shellSurfaces.
+
+ //! [shells]
WlShell {
- onWlShellSurfaceCreated:
- shellSurfaces.append({shellSurface: shellSurface});
- }
- XdgShellV6 {
- onToplevelCreated:
- shellSurfaces.append({shellSurface: xdgSurface});
+ onWlShellSurfaceCreated: (shellSurface) => shellSurfaces.append({shellSurface: shellSurface});
}
XdgShell {
- onToplevelCreated:
- shellSurfaces.append({shellSurface: xdgSurface});
+ onToplevelCreated: (toplevel, xdgSurface) => shellSurfaces.append({shellSurface: xdgSurface});
+ }
+ IviApplication {
+ onIviSurfaceCreated: (iviSurface) => shellSurfaces.append({shellSurface: iviSurface});
}
+ //! [shells]
+
+ //! [model]
ListModel { id: shellSurfaces }
+ //! [model]
}