diff options
author | Paul Olav Tvete <paul.tvete@qt.io> | 2021-10-18 16:41:12 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@qt.io> | 2021-12-02 09:08:40 +0100 |
commit | d89c8920f3b82dd2098971b5a66c4b9c75da5af0 (patch) | |
tree | b7f35e03485f1aa8725e30870f3066b34d24ea94 /examples/wayland/custom-shell/client-plugin | |
parent | 0204df32ee7417db3156ef3c70bcf762d7e9fb0a (diff) |
Introduce new qt-shell and an API for custom shells
Adds a new API for writing custom shell extensions. This API is supported,
but semi-public. Binary compatibility is not guaranteed.
Also adds qt-shell, a new shell that maps directly to the QWindow API, and
provides functionality that Qt provides on other window systems, such as
absolute window positions and window activation. This shell is not intended
for use on the desktop.
This is a squashed commit of a development branch consisting of approximately
60 changes. Contributors:
Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Paul Olav Tvete <paul.tvete@qt.io>
Task-number: QTBUG-94330
Task-number: QTBUG-91542
Change-Id: I419b6bd8179fe03e4da47d328c7ff4b4795b8a91
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: David Edmundson <davidedmundson@kde.org>
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'examples/wayland/custom-shell/client-plugin')
8 files changed, 486 insertions, 0 deletions
diff --git a/examples/wayland/custom-shell/client-plugin/CMakeLists.txt b/examples/wayland/custom-shell/client-plugin/CMakeLists.txt new file mode 100644 index 000000000..8af9aeb30 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.14) +project(exampleshellplugin LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/custom-shell/plugins") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Gui) +find_package(Qt6 COMPONENTS WaylandClient) + +qt_add_plugin(exampleshellplugin) +target_sources(exampleshellplugin PRIVATE + main.cpp + exampleshellintegration.cpp exampleshellintegration.h + examplesurface.cpp examplesurface.h +) + +qt6_generate_wayland_protocol_client_sources(exampleshellplugin + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/../protocol/example-shell.xml +) + +set_target_properties(exampleshellplugin PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/../plugins/wayland-shell-integration" +) + +target_link_libraries(exampleshellplugin PUBLIC + Qt::Core + Qt::Gui + Qt::GuiPrivate + Qt::WaylandClient + Qt::WaylandClientPrivate + Wayland::Client +) + +install(TARGETS exampleshellplugin + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/wayland/custom-shell/client-plugin/client-plugin.pro b/examples/wayland/custom-shell/client-plugin/client-plugin.pro new file mode 100644 index 000000000..96a01c231 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/client-plugin.pro @@ -0,0 +1,33 @@ +QT += gui-private waylandclient-private +CONFIG += plugin wayland-scanner +TEMPLATE = lib + +QMAKE_USE += wayland-client + +qtConfig(xkbcommon): \ + QMAKE_USE += xkbcommon + +WAYLANDCLIENTSOURCES += \ + ../protocol/example-shell.xml + +HEADERS += \ + exampleshellintegration.h \ + examplesurface.h + +SOURCES += \ + main.cpp \ + exampleshellintegration.cpp \ + examplesurface.cpp + +OTHER_FILES += \ + example-shell.json + +DESTDIR = ../plugins/wayland-shell-integration +TARGET = $$qtLibraryTarget(exampleshellplugin) + +### Everything below this line is just to make the example work inside the Qt source tree. +### Do not include the following lines in your own code. + +target.path = $$[QT_INSTALL_EXAMPLES]/wayland/customshell/plugins/wayland-shell-integration +INSTALLS += target +CONFIG += install_ok diff --git a/examples/wayland/custom-shell/client-plugin/example-shell.json b/examples/wayland/custom-shell/client-plugin/example-shell.json new file mode 100644 index 000000000..c36490af5 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/example-shell.json @@ -0,0 +1,3 @@ +{ + "Keys":[ "example-shell" ] +} diff --git a/examples/wayland/custom-shell/client-plugin/exampleshellintegration.cpp b/examples/wayland/custom-shell/client-plugin/exampleshellintegration.cpp new file mode 100644 index 000000000..aefe4921b --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/exampleshellintegration.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Wayland module +** +** $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$ +** +****************************************************************************/ + +#include "exampleshellintegration.h" +#include "examplesurface.h" + +//! [constructor] +ExampleShellIntegration::ExampleShellIntegration() + : QWaylandShellIntegrationTemplate(/* Supported protocol version */ 1) +{ +} +//! [constructor] + +//! [createShellSurface] +QWaylandShellSurface *ExampleShellIntegration::createShellSurface(QWaylandWindow *window) +{ + if (!isActive()) + return nullptr; + auto *surface = surface_create(wlSurfaceForWindow(window)); + return new ExampleShellSurface(surface, window); +} +//! [createShellSurface] diff --git a/examples/wayland/custom-shell/client-plugin/exampleshellintegration.h b/examples/wayland/custom-shell/client-plugin/exampleshellintegration.h new file mode 100644 index 000000000..344483eab --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/exampleshellintegration.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Wayland module +** +** $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$ +** +****************************************************************************/ + +#ifndef EXAMPLESHELLINTEGRATION_H +#define EXAMPLESHELLINTEGRATION_H +#include <QtWaylandClient/private/qwaylandclientshellapi_p.h> +#include "qwayland-example-shell.h" + +using namespace QtWaylandClient; + +//! [shell-integration] +class Q_WAYLAND_CLIENT_EXPORT ExampleShellIntegration + : public QWaylandShellIntegrationTemplate<ExampleShellIntegration> + , public QtWayland::qt_example_shell +{ +public: + ExampleShellIntegration(); + + QWaylandShellSurface *createShellSurface(QWaylandWindow *window) override; +}; +//! [shell-integration] + +#endif // EXAMPLESHELLINTEGRATION_H diff --git a/examples/wayland/custom-shell/client-plugin/examplesurface.cpp b/examples/wayland/custom-shell/client-plugin/examplesurface.cpp new file mode 100644 index 000000000..68fbaf4b0 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/examplesurface.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Wayland module +** +** $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$ +** +****************************************************************************/ + +#include "examplesurface.h" +#include <qpa/qwindowsysteminterface.h> +#include <qpa/qplatformwindow.h> + +ExampleShellSurface::ExampleShellSurface(struct ::qt_example_shell_surface *shell_surface, QWaylandWindow *window) + : QWaylandShellSurface(window) + , QtWayland::qt_example_shell_surface(shell_surface) +{ +} + +ExampleShellSurface::~ExampleShellSurface() +{ +} + +bool ExampleShellSurface::wantsDecorations() const +{ + return true; +} + +//! [setTitle] +void ExampleShellSurface::setTitle(const QString &windowTitle) +{ + set_window_title(windowTitle); +} +//! [setTitle] + +void ExampleShellSurface::requestWindowStates(Qt::WindowStates states) +{ + set_minimized(states & Qt::WindowMinimized); +} + +//! [applyConfigure] +void ExampleShellSurface::applyConfigure() +{ + if (m_stateChanged) + QWindowSystemInterface::handleWindowStateChanged(platformWindow()->window(), m_pendingStates); + m_stateChanged = false; +} +//! [applyConfigure] + +void ExampleShellSurface::example_shell_surface_minimize(uint32_t minimized) +{ + m_pendingStates = minimized ? Qt::WindowMinimized : Qt::WindowNoState; + m_stateChanged = true; + applyConfigureWhenPossible(); +} diff --git a/examples/wayland/custom-shell/client-plugin/examplesurface.h b/examples/wayland/custom-shell/client-plugin/examplesurface.h new file mode 100644 index 000000000..a15bd52ee --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/examplesurface.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Wayland module +** +** $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$ +** +****************************************************************************/ + +#ifndef EXAMPLESHELLSURFACE_H +#define EXAMPLESHELLSURFACE_H + +#include <QtWaylandClient/private/qwaylandclientshellapi_p.h> +#include "qwayland-example-shell.h" + +using namespace QtWaylandClient; + +//! [ExampleShellSurface] +class ExampleShellSurface : public QWaylandShellSurface + , public QtWayland::qt_example_shell_surface +//! [ExampleShellSurface] +{ +public: + ExampleShellSurface(struct ::qt_example_shell_surface *shell_surface, QWaylandWindow *window); + ~ExampleShellSurface() override; + +//! [virtuals] + bool wantsDecorations() const override; + void setTitle(const QString &) override; + void requestWindowStates(Qt::WindowStates states) override; + void applyConfigure() override; +//! [virtuals] + +protected: +//! [events] + void example_shell_surface_minimize(uint32_t minimized) override; +//! [events] + +private: + Qt::WindowStates m_pendingStates; + bool m_stateChanged = false; +}; + +#endif // EXAMPLESHELLSURFACE_H diff --git a/examples/wayland/custom-shell/client-plugin/main.cpp b/examples/wayland/custom-shell/client-plugin/main.cpp new file mode 100644 index 000000000..3a3ad8221 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/main.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Wayland module +** +** $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$ +** +****************************************************************************/ + +#include "exampleshellintegration.h" + +//! [include] +#include <QtWaylandClient/private/qwaylandclientshellapi_p.h> +//! [include] + +#include "qwayland-example-shell.h" + +using namespace QtWaylandClient; + +//! [plugin] +class QWaylandExampleShellIntegrationPlugin : public QWaylandShellIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QWaylandShellIntegrationFactoryInterface_iid FILE "example-shell.json") + +public: + QWaylandShellIntegration *create(const QString &key, const QStringList ¶mList) override; +}; + +QWaylandShellIntegration *QWaylandExampleShellIntegrationPlugin::create(const QString &key, const QStringList ¶mList) +{ + Q_UNUSED(key); + Q_UNUSED(paramList); + return new ExampleShellIntegration(); +} +//! [plugin] + +#include "main.moc" |