diff options
Diffstat (limited to 'examples/wayland/spanning-screens')
-rw-r--r-- | examples/wayland/spanning-screens/CMakeLists.txt | 48 | ||||
-rw-r--r-- | examples/wayland/spanning-screens/doc/images/spanning-screens.jpg | bin | 0 -> 77163 bytes | |||
-rw-r--r-- | examples/wayland/spanning-screens/doc/src/spanning-screens.qdoc | 82 | ||||
-rw-r--r-- | examples/wayland/spanning-screens/main.cpp | 53 | ||||
-rw-r--r-- | examples/wayland/spanning-screens/main.qml | 77 |
5 files changed, 125 insertions, 135 deletions
diff --git a/examples/wayland/spanning-screens/CMakeLists.txt b/examples/wayland/spanning-screens/CMakeLists.txt new file mode 100644 index 000000000..0e4239033 --- /dev/null +++ b/examples/wayland/spanning-screens/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(spanning-screens LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/spanning-screens") + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml) + +qt_add_executable(spanning-screens + main.cpp +) + +set_target_properties(spanning-screens PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(spanning-screens PUBLIC + Qt::Core + Qt::Gui + Qt::Qml +) + +# Resources: +set(spanning-screens_resource_files + "main.qml" +) + +qt6_add_resources(spanning-screens "spanning-screens" + PREFIX + "/" + FILES + ${spanning-screens_resource_files} +) + +install(TARGETS spanning-screens + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/wayland/spanning-screens/doc/images/spanning-screens.jpg b/examples/wayland/spanning-screens/doc/images/spanning-screens.jpg Binary files differnew file mode 100644 index 000000000..4f348393c --- /dev/null +++ b/examples/wayland/spanning-screens/doc/images/spanning-screens.jpg diff --git a/examples/wayland/spanning-screens/doc/src/spanning-screens.qdoc b/examples/wayland/spanning-screens/doc/src/spanning-screens.qdoc index 3ab0b91f5..7c548171c 100644 --- a/examples/wayland/spanning-screens/doc/src/spanning-screens.qdoc +++ b/examples/wayland/spanning-screens/doc/src/spanning-screens.qdoc @@ -1,36 +1,60 @@ -/**************************************************************************** -** -** 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 - Spanning Screens + * \title Spanning Screens * \example spanning-screens + * \examplecategory {Embedded} * \brief Spanning Screens is an example that demonstrates how to let Wayland clients span multiple screens. * \ingroup qtwaylandcompositor-examples * - * Spanning screens is a Wayland compositor example that maximizes clients - * across a top and a bottom screen. + * \section1 Introduction + * + * Spanning screens is a Wayland compositor example that maximizes clients across a top and a bottom + * screen. + * + * \image spanning-screens.jpg + * + * For an introduction to the basic principles of creating a \l{Qt Wayland Compositor} with Qt, + * see the \l{Minimal QML}{Minimal QML example}. + * + * \section1 Supporting Multiple Screens + * + * In \l{Qt Wayland Compositor} a screen is represented by a \l{WaylandOutput}, and a \l Window is + * used to contain the \l{Qt Quick} scene representing both clients and the compositor's UI. + * + * In this example, a multi-screen setup is emulated by creating two windows on the primary screen, + * but the code can easily be modified to target multiple physical screens. + * + * \snippet spanning-screens/main.qml enable screens + * + * Since each \l Window represents an isolated \l{Qt Quick} scene, this means we need a trick to + * have the same client content display inside both windows. The way to do this in + * \l{Qt Wayland Compositor} is to create two views of the same client content: One for the "top" + * window and one for the "bottom". The views share a reference to the same underlying graphics buffer. + * This allows us to copy different areas of the client's surface onto each of the windows. + * + * \snippet spanning-screens/main.qml create items + * + * When the client connects to the \l{Shell Extensions - Qt Wayland Compositor}{shell extension} + * \l{XdgShell}, we create two references to the surface. One of them is added to the "top" output, + * and the second to the "bottom". The item on the bottom output also gets an offset corresponding + * to the height of the top output. This ensures that the part of the client surface showing on + * the bottom output starts where the top output ends. + * + * \snippet spanning-screens/main.qml size + * + * In addition, we tell the client to resize its surface so that it fills both the top and bottom + * window. The end result is a client that spans two windows, or "screens". + * + * Referencing the same client surface from multiple items is a tool which can be used for many + * things. For a demonstration of a desktop-style compositor where windows can be moved from screen + * to screen, take a look at the \l{Multi Screen}{Multi Screen example}. + * + * The \l{Multi Output}{Multi Output example} shows how client surfaces can be displayed on multiple + * outputs with different sizes and other properties. + * + * \note In order to support multiple Wayland outputs in the same compositor, the + * \l Qt::AA_ShareOpenGLContexts attribute must be set before the \l QGuiApplication + * object is constructed. */ diff --git a/examples/wayland/spanning-screens/main.cpp b/examples/wayland/spanning-screens/main.cpp index 435b4e3f1..607d14899 100644 --- a/examples/wayland/spanning-screens/main.cpp +++ b/examples/wayland/spanning-screens/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> @@ -57,6 +10,8 @@ int main(int argc, char *argv[]) { + // AA_ShareOpenGLContexts is required for compositors with multiple outputs + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QGuiApplication app(argc, argv); QQmlApplicationEngine appEngine(QUrl("qrc:///main.qml")); diff --git a/examples/wayland/spanning-screens/main.qml b/examples/wayland/spanning-screens/main.qml index ab57306bb..d47246dee 100644 --- a/examples/wayland/spanning-screens/main.qml +++ b/examples/wayland/spanning-screens/main.qml @@ -1,56 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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$ -** -****************************************************************************/ - -import QtQuick 2.6 -import QtQuick.Window 2.3 -import QtWayland.Compositor 1.3 +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Window +import QtWayland.Compositor +import QtWayland.Compositor.XdgShell WaylandCompositor { WaylandOutput { @@ -68,10 +22,12 @@ WaylandCompositor { Text { text: "Top screen" } + // ![enable screens] // Enable the following to make the output target an actual screen, // for example when running on eglfs in a multi-display embedded system. // screen: Qt.application.screens[0] + // ![enable screens] } } @@ -99,16 +55,20 @@ WaylandCompositor { Component { id: chromeComponent - ShellSurfaceItem { - autoCreatePopupItems: true - onSurfaceDestroyed: destroy() + Item { + property alias shellSurface: ssi.shellSurface + ShellSurfaceItem { + id: ssi + onSurfaceDestroyed: destroy() + } } } XdgShell { - onToplevelCreated: { + onToplevelCreated: (toplevel, xdgSurface) => { const shellSurface = xdgSurface; + // ![create items] const topItem = chromeComponent.createObject(topSurfaceArea, { shellSurface }); @@ -117,11 +77,14 @@ WaylandCompositor { shellSurface, y: Qt.binding(function() { return -topSurfaceArea.height;}) }); + // ![create items] + // ![size] const height = topSurfaceArea.pixelHeight + bottomSurfaceArea.pixelHeight; const width = Math.max(bottomSurfaceArea.pixelWidth, topSurfaceArea.pixelWidth); const size = Qt.size(width, height); toplevel.sendFullscreen(size); + // ![size] } } } |