diff options
Diffstat (limited to 'examples/wayland/custom-shell/client-plugin')
8 files changed, 248 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..39569b80f --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/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.14) +project(exampleshellplugin LANGUAGES CXX) + +set(CMAKE_AUTOMOC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/custom-shell/plugins") + +find_package(Qt6 REQUIRED COMPONENTS Core Gui 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..b979640a7 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/exampleshellintegration.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#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..f7f9de909 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/exampleshellintegration.h @@ -0,0 +1,23 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef EXAMPLESHELLINTEGRATION_H +#define EXAMPLESHELLINTEGRATION_H +#include <QtWaylandClient/private/qwaylandclientshellapi_p.h> +#include "qwayland-example-shell.h" + +using namespace QtWaylandClient; + +//! [shell-integration] +class Q_WAYLANDCLIENT_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..eb17331c3 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/examplesurface.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#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..e5d6fb92a --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/examplesurface.h @@ -0,0 +1,38 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#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..4ae488880 --- /dev/null +++ b/examples/wayland/custom-shell/client-plugin/main.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#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" |