summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/wayland/custom-extension/client-common/customextension.cpp2
-rw-r--r--examples/wayland/custom-extension/client-common/customextension.h6
-rw-r--r--examples/wayland/custom-extension/compositor/CMakeLists.txt6
-rw-r--r--examples/wayland/custom-extension/compositor/compositor.pro4
-rw-r--r--examples/wayland/custom-extension/compositor/customextension.cpp8
-rw-r--r--examples/wayland/custom-extension/compositor/customextension.h8
-rw-r--r--examples/wayland/custom-extension/compositor/main.cpp6
-rw-r--r--examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml1
-rw-r--r--examples/wayland/custom-extension/compositor/qml/main.qml17
-rw-r--r--examples/wayland/custom-extension/cpp-client/main.cpp18
-rw-r--r--examples/wayland/custom-extension/doc/images/custom-extension.pngbin0 -> 64841 bytes
-rw-r--r--examples/wayland/custom-extension/doc/src/custom-extension.qdoc147
-rw-r--r--examples/wayland/custom-extension/qml-client/CMakeLists.txt8
-rw-r--r--examples/wayland/custom-extension/qml-client/main.cpp7
-rw-r--r--examples/wayland/custom-extension/qml-client/main.qml90
-rw-r--r--examples/wayland/custom-extension/qml-client/qml-client.pro6
16 files changed, 273 insertions, 61 deletions
diff --git a/examples/wayland/custom-extension/client-common/customextension.cpp b/examples/wayland/custom-extension/client-common/customextension.cpp
index 3c585af3a..4f898ea9b 100644
--- a/examples/wayland/custom-extension/client-common/customextension.cpp
+++ b/examples/wayland/custom-extension/client-common/customextension.cpp
@@ -68,10 +68,12 @@ CustomExtensionObject *CustomExtension::createCustomObject(const QString &color,
return new CustomExtensionObject(obj, text);
}
+//! [sendBounce]
void CustomExtension::sendBounce(QWindow *window, uint ms)
{
QtWayland::qt_example_extension::bounce(getWlSurface(window), ms);
}
+//! [sendBounce]
void CustomExtension::sendSpin(QWindow *window, uint ms)
{
diff --git a/examples/wayland/custom-extension/client-common/customextension.h b/examples/wayland/custom-extension/client-common/customextension.h
index c3a9a4939..5dd770199 100644
--- a/examples/wayland/custom-extension/client-common/customextension.h
+++ b/examples/wayland/custom-extension/client-common/customextension.h
@@ -6,16 +6,21 @@
#include <QtWaylandClient/QWaylandClientExtension>
#include <QtGui/QWindow>
+#include <QtQml/QQmlEngine>
+
#include "qwayland-custom.h"
QT_BEGIN_NAMESPACE
class CustomExtensionObject;
+//! [CustomExtension]
class CustomExtension : public QWaylandClientExtensionTemplate<CustomExtension>
, public QtWayland::qt_example_extension
+//! [CustomExtension]
{
Q_OBJECT
+ QML_ELEMENT
public:
CustomExtension();
Q_INVOKABLE void registerWindow(QWindow *window);
@@ -67,7 +72,6 @@ protected:
public slots:
void setText(const QString &text);
-
signals:
void textChanged(const QString &text);
void clicked();
diff --git a/examples/wayland/custom-extension/compositor/CMakeLists.txt b/examples/wayland/custom-extension/compositor/CMakeLists.txt
index 4a946e6a6..bb70cf106 100644
--- a/examples/wayland/custom-extension/compositor/CMakeLists.txt
+++ b/examples/wayland/custom-extension/compositor/CMakeLists.txt
@@ -14,6 +14,7 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/custom-extension/composit
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml WaylandCompositor)
+qt6_policy(SET QTP0001 NEW)
qt_add_executable(custom-extension-compositor
customextension.cpp customextension.h
main.cpp
@@ -50,6 +51,11 @@ qt6_add_resources(custom-extension-compositor "compositor"
${compositor_resource_files}
)
+qt6_add_qml_module(custom-extension-compositor
+ URI io.qt.examples.customextension
+ VERSION 1.0
+)
+
install(TARGETS custom-extension-compositor
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/wayland/custom-extension/compositor/compositor.pro b/examples/wayland/custom-extension/compositor/compositor.pro
index 283ccdf4b..263b9fbdd 100644
--- a/examples/wayland/custom-extension/compositor/compositor.pro
+++ b/examples/wayland/custom-extension/compositor/compositor.pro
@@ -2,6 +2,10 @@ QT += core gui qml
QT += waylandcompositor
+CONFIG += qmltypes
+QML_IMPORT_NAME = io.qt.examples.customextension
+QML_IMPORT_MAJOR_VERSION = 1
+
CONFIG += wayland-scanner
CONFIG += c++11
SOURCES += \
diff --git a/examples/wayland/custom-extension/compositor/customextension.cpp b/examples/wayland/custom-extension/compositor/customextension.cpp
index e6968adc6..0d19a62e2 100644
--- a/examples/wayland/custom-extension/compositor/customextension.cpp
+++ b/examples/wayland/custom-extension/compositor/customextension.cpp
@@ -8,7 +8,7 @@
#include <QDebug>
CustomExtension::CustomExtension(QWaylandCompositor *compositor)
- :QWaylandCompositorExtensionTemplate(compositor)
+ : QWaylandCompositorExtensionTemplate(compositor)
{
}
@@ -19,6 +19,7 @@ void CustomExtension::initialize()
init(compositor->display(), 1);
}
+//! [setFontSize]
void CustomExtension::setFontSize(QWaylandSurface *surface, uint pixelSize)
{
if (surface) {
@@ -29,6 +30,7 @@ void CustomExtension::setFontSize(QWaylandSurface *surface, uint pixelSize)
}
}
}
+//! [setFontSize]
void CustomExtension::showDecorations(QWaylandClient *client, bool shown)
{
@@ -39,7 +41,6 @@ void CustomExtension::showDecorations(QWaylandClient *client, bool shown)
send_set_window_decoration(target->handle, shown);
}
}
-
}
void CustomExtension::close(QWaylandSurface *surface)
@@ -53,6 +54,7 @@ void CustomExtension::close(QWaylandSurface *surface)
}
}
+//! [example_extension_bounce]
void CustomExtension::example_extension_bounce(QtWaylandServer::qt_example_extension::Resource *resource, wl_resource *wl_surface, uint32_t duration)
{
Q_UNUSED(resource);
@@ -60,6 +62,7 @@ void CustomExtension::example_extension_bounce(QtWaylandServer::qt_example_exten
qDebug() << "server received bounce" << surface << duration;
emit bounce(surface, duration);
}
+//! [example_extension_bounce]
void CustomExtension::example_extension_spin(QtWaylandServer::qt_example_extension::Resource *resource, wl_resource *wl_surface, uint32_t duration)
{
@@ -90,7 +93,6 @@ CustomExtensionObject::CustomExtensionObject(const QString &color, const QString
, m_color(color)
, m_text(text)
{
-
}
void CustomExtensionObject::sendClicked()
diff --git a/examples/wayland/custom-extension/compositor/customextension.h b/examples/wayland/custom-extension/compositor/customextension.h
index 330199697..e377d5f57 100644
--- a/examples/wayland/custom-extension/compositor/customextension.h
+++ b/examples/wayland/custom-extension/compositor/customextension.h
@@ -9,14 +9,18 @@
#include <QtWaylandCompositor/QWaylandCompositorExtensionTemplate>
#include <QtWaylandCompositor/QWaylandQuickExtension>
#include <QtWaylandCompositor/QWaylandCompositor>
+#include <QtWaylandCompositor/QWaylandSurface>
#include "qwayland-server-custom.h"
class CustomExtensionObject;
+//! [CustomExtension]
class CustomExtension : public QWaylandCompositorExtensionTemplate<CustomExtension>
, public QtWaylandServer::qt_example_extension
{
Q_OBJECT
+ QML_ELEMENT
+//! [CustomExtension]
public:
CustomExtension(QWaylandCompositor *compositor = nullptr);
void initialize() override;
@@ -25,7 +29,6 @@ signals:
void surfaceAdded(QWaylandSurface *surface);
void bounce(QWaylandSurface *surface, uint ms);
void spin(QWaylandSurface *surface, uint ms);
-
void customObjectCreated(CustomExtensionObject *obj);
public slots:
@@ -33,11 +36,12 @@ public slots:
void showDecorations(QWaylandClient *client, bool);
void close(QWaylandSurface *surface);
+//! [example_extension_bounce]
protected:
void example_extension_bounce(Resource *resource, wl_resource *surface, uint32_t duration) override;
+//! [example_extension_bounce]
void example_extension_spin(Resource *resource, wl_resource *surface, uint32_t duration) override;
void example_extension_register_surface(Resource *resource, wl_resource *surface) override;
-
void example_extension_create_local_object(Resource *resource, uint32_t id, const QString &color, const QString &text) override;
};
diff --git a/examples/wayland/custom-extension/compositor/main.cpp b/examples/wayland/custom-extension/compositor/main.cpp
index a44027229..458f5b9a3 100644
--- a/examples/wayland/custom-extension/compositor/main.cpp
+++ b/examples/wayland/custom-extension/compositor/main.cpp
@@ -11,15 +11,9 @@
#include "customextension.h"
-static void registerTypes()
-{
- qmlRegisterType<CustomExtensionQuickExtension>("io.qt.examples.customextension", 1, 0, "CustomExtension");
-}
-
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
- registerTypes();
QQmlApplicationEngine appEngine(QUrl("qrc:///qml/main.qml"));
return app.exec();
diff --git a/examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml b/examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml
index ec70a4373..ea2cb9b16 100644
--- a/examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml
+++ b/examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml
@@ -9,6 +9,7 @@ WaylandOutput {
id: output
property alias surfaceArea: background
sizeFollowsWindow: true
+
window: Window {
id: screen
diff --git a/examples/wayland/custom-extension/compositor/qml/main.qml b/examples/wayland/custom-extension/compositor/qml/main.qml
index 7005af841..9907263da 100644
--- a/examples/wayland/custom-extension/compositor/qml/main.qml
+++ b/examples/wayland/custom-extension/compositor/qml/main.qml
@@ -91,13 +91,14 @@ WaylandCompositor {
bounceAnimation.start()
}
+//! [setFontSize]
onFontSizeChanged: {
custom.setFontSize(surface, fontSize)
}
+//! [setFontSize]
}
}
-
Component {
id: customObjectComponent
Rectangle {
@@ -107,7 +108,7 @@ WaylandCompositor {
width: 100
height: 100
- radius: width/2
+ radius: width / 2
x: Math.random() * (defaultOutput.surfaceArea.width - 100)
y: Math.random() * (defaultOutput.surfaceArea.height - 100)
@@ -138,12 +139,13 @@ WaylandCompositor {
var h = defaultOutput.surfaceArea.height / 2
item.x = Math.random() * w
item.y = Math.random() * h
- var listCopy = itemList; // List properties cannot be modified through Javascript operations
+ var listCopy = itemList // List properties cannot be modified through Javascript operations
listCopy.push(item)
itemList = listCopy
}
}
+//! [CustomExtension]
CustomExtension {
id: custom
@@ -151,26 +153,31 @@ WaylandCompositor {
var item = itemForSurface(surface)
item.isCustom = true
}
+
onBounce: (surface, ms) => {
var item = itemForSurface(surface)
item.doBounce(ms)
}
+
onSpin: (surface, ms) => {
var item = itemForSurface(surface)
item.doSpin(ms)
}
+
onCustomObjectCreated: (obj) => {
var item = customObjectComponent.createObject(defaultOutput.surfaceArea,
- { "color": obj.color, "text": obj.text, "obj": obj } )
+ { "color": obj.color,
+ "text": obj.text,
+ "obj": obj } )
}
}
function setDecorations(shown) {
var n = itemList.length
for (var i = 0; i < n; i++) {
- // TODO: we only need to do it once for each client
if (itemList[i].isCustom)
custom.showDecorations(itemList[i].surface.client, shown)
}
}
+//! [CustomExtension]
}
diff --git a/examples/wayland/custom-extension/cpp-client/main.cpp b/examples/wayland/custom-extension/cpp-client/main.cpp
index d3feae404..c3951ea9d 100644
--- a/examples/wayland/custom-extension/cpp-client/main.cpp
+++ b/examples/wayland/custom-extension/cpp-client/main.cpp
@@ -6,17 +6,14 @@
#include <QPainter>
#include <QMouseEvent>
#include <QPlatformSurfaceEvent>
-
-#include "../client-common/customextension.h"
-
#include <QDebug>
-#include <QtGui/qpa/qplatformnativeinterface.h>
#include <QTimer>
+#include "../client-common/customextension.h"
+
class TestWindow : public QRasterWindow
{
Q_OBJECT
-
public:
TestWindow(CustomExtension *customExtension)
: m_extension(customExtension)
@@ -25,8 +22,12 @@ public:
, rect3(50, 350, 100, 100)
, rect4(200,350, 100, 100)
{
+ setTitle(tr("C++ Client"));
m_extension->registerWindow(this);
+
+//! [connection]
connect(m_extension, &CustomExtension::fontSize, this, &TestWindow::handleSetFontSize);
+//! [connection]
}
public slots:
@@ -39,6 +40,7 @@ public slots:
qDebug() << "sending spin...";
m_extension->sendSpin(this, 500);
}
+
void doBounce()
{
if (!m_extension->isActive()) {
@@ -58,7 +60,7 @@ public slots:
CustomExtensionObject *newObject()
{
m_objectCount++;
- QColor col = QColor::fromHsv(0, 511/(m_objectCount+1), 255);
+ QColor col = QColor::fromHsv(0, 511 / (m_objectCount + 1), 255);
return m_extension->createCustomObject(col.name(), QString::number(m_objectCount));
}
@@ -76,7 +78,7 @@ protected:
{
QPainter p(this);
p.setFont(m_font);
- p.fillRect(QRect(0,0,width(),height()),Qt::gray);
+ p.fillRect(QRect(0, 0, width(), height()), Qt::gray);
p.fillRect(rect1, QColor::fromString("#C0FFEE"));
p.drawText(rect1, Qt::TextWordWrap, "Press here to send spin request.");
p.fillRect(rect2, QColor::fromString("#decaff"));
@@ -88,6 +90,7 @@ protected:
}
+//! [mousePressEvent]
void mousePressEvent(QMouseEvent *ev) override
{
if (rect1.contains(ev->position()))
@@ -99,6 +102,7 @@ protected:
else if (rect4.contains(ev->position()))
newObject();
}
+//! [mousePressEvent]
private:
CustomExtension *m_extension = nullptr;
diff --git a/examples/wayland/custom-extension/doc/images/custom-extension.png b/examples/wayland/custom-extension/doc/images/custom-extension.png
new file mode 100644
index 000000000..95cddad12
--- /dev/null
+++ b/examples/wayland/custom-extension/doc/images/custom-extension.png
Binary files differ
diff --git a/examples/wayland/custom-extension/doc/src/custom-extension.qdoc b/examples/wayland/custom-extension/doc/src/custom-extension.qdoc
new file mode 100644
index 000000000..3b8e9b657
--- /dev/null
+++ b/examples/wayland/custom-extension/doc/src/custom-extension.qdoc
@@ -0,0 +1,147 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ * \title Custom Extension
+ * \example custom-extension
+ * \brief Custom Extension shows how to implement a custom Wayland extension.
+ * \ingroup qtwaylandcompositor-examples
+ *
+ * It's easy to write new extensions for Wayland. They are defined using a XML-based format and
+ * the \c wayland-scanner tool converts this to glue code in C. Qt expands on this with the
+ * \c qtwaylandscanner, which generates additional glue code in Qt and C++.
+ *
+ * \image custom-extension.png
+ *
+ * The Custom Extension example shows how to use these tools to extend the Wayland protocol and
+ * send custom requests and events between a Wayland client and a server.
+ *
+ * The example consists of four items:
+ * \list
+ * \li The definition of the protocol itself.
+ * \li A compositor that supports the extension.
+ * \li A C++-based client that supports the extension.
+ * \li A QML-based client that supports the extension.
+ * \endlist
+ *
+ * \section1 The Protocol Definition
+ *
+ * The XML file \c custom.xml defines the protocol. It contains an interface called
+ * "qt_example_extension". This is the name which will be broadcast from the server and which the
+ * client will attach to in order to send requests and receive events. This name should be unique,
+ * so it is good to use a prefix that sets it apart from official interfaces.
+ *
+ * An interface typically consists of two types of remote procedure calls:
+ * \e requests and \e events. "Requests" are calls the client makes on the server-side, and
+ * "events" are calls the server makes on the client-side.
+ *
+ * The example extension contains a set of \e requests which instructs the server to apply certain
+ * transforms to the client window. For instance, if the client sends a "bounce" request, then the
+ * server should respond to this by making the window bounce on the screen.
+ *
+ * Similarly, it has a set of \e events which the server can use to provide instructions for the
+ * client. For instance, the "set_font_size" event is an instruction for the client to set its
+ * default font size to a specific size.
+ *
+ * The protocol defines the existence of requests and events, as well as the arguments they
+ * take. When \c qtwaylandscanner is run on it, it will generate the code needed to marshall the
+ * procedure call and its arguments and to transmit this over the connection. On the other end, this
+ * becomes a call to a virtual function which can be implemented to provide the actual response.
+ *
+ * In order to have \c qtwaylandscanner run automatically as part of the build, we use the
+ * CMake functions \c qt6_generate_wayland_protocol_server_sources() and
+ * \c qt6_generate_wayland_protocol_client_sources() for generating the server-side and
+ * client-side glue code, respectively. (When using \c qmake, the \c WAYLANDSERVERSOURCES and
+ * \c WAYLANDCLIENTSOURCES variables achieve the same.)
+ *
+ * \section1 The Compositor Implementation
+ *
+ * The Compositor application itself is implemented using QML and Qt Quick, but the extension is
+ * implemented in C++.
+ *
+ * The first step is to create a subclass of the glue code generated by \c qtwaylandscanner so
+ * that we can access its functionality. We add the \l QML_ELEMENT macro to the class in order to
+ * make it accessible from QML.
+ *
+ * \snippet custom-extension/compositor/customextension.h CustomExtension
+ *
+ * In addition to inheriting from the generated class, we also inherit the class
+ * \l QWaylandCompositorExtensionTemplate which provides some additional convenience when dealing
+ * with extensions, using the
+ * l{https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern}{Curiously Recurring Template Pattern}.
+ *
+ * Note that the \l QWaylandCompositorExtensionTemplate must be first in the inheritance list, since
+ * it is a \l{QObject}-based class.
+ *
+ * The subclass has re-implementations of virtual functions in the generated base class, where
+ * we can handle requests issued by a client.
+ *
+ * \snippet custom-extension/compositor/customextension.h example_extension_bounce
+ *
+ * In these re-implementations, we simply translate the request to a \e signal emission, so that we
+ * can handle it in the actual QML code of the compositor.
+ *
+ * \snippet custom-extension/compositor/customextension.cpp example_extension_bounce
+ *
+ * In addition, the subclass defines \e slots for each of the events, so that these can be either
+ * called from QML or be connected to signals. The slots simply call the generated functions which
+ * send the events to the client.
+ *
+ * \snippet custom-extension/compositor/customextension.cpp setFontSize
+ *
+ * Since we added the \l QML_ELEMENT macro to the class definition (and added the corresponding
+ * build steps to the build system files), it can be instantiated in QML.
+ *
+ * We make it a direct child of the \l WaylandCompositor object in order for the compositor to
+ * register it as an extension.
+ *
+ * \snippet custom-extension/compositor/qml/main.qml CustomExtension
+ *
+ * The object has signal handlers for the requests it may get from the client and reacts to them
+ * accordingly. In addition, we can call its slots to send events.
+ *
+ * \snippet custom-extension/compositor/qml/main.qml setFontSize
+ *
+ * \section1 The C++ Client Implementation
+ *
+ * Both clients share the C++ implementation of the interface. Like in the compositor, we make
+ * a subclass of the generated code which also inherits from a template class. In this case,
+ * we inherit QWaylandClientExtensionTemplate.
+ *
+ * \snippet custom-extension/client-common/customextension.h CustomExtension
+ *
+ * The approach is very similar to that of the compositor, except inverted: Requests are implemented
+ * as slots which call the generated functions, and events virtual functions which we re-implement
+ * to emit signals.
+ *
+ * \snippet custom-extension/client-common/customextension.cpp sendBounce
+ *
+ * The client code itself is very simple and only intended to show how to trigger the behavior. In
+ * a custom paint event, it draws a set of rectangles and labels. When any of these are clicked, it
+ * issues requests to the server.
+ *
+ * \snippet custom-extension/cpp-client/main.cpp mousePressEvent
+ *
+ * To update the font size when the \c set_font_size event is received, the signal in our extension
+ * class is connected to a slot.
+ *
+ * \snippet custom-extension/cpp-client/main.cpp connection
+ *
+ * The slot will update the font size and repaint the window.
+ *
+ * \section1 The QML Client Implementation
+ *
+ * The QML client is similar to the C++ client. It relies on the same implementation of the custom
+ * extension as the C++ client, and instantiates this in QML to enable it.
+ *
+ * \snippet custom-extension/qml-client/main.qml CustomExtension
+ *
+ * The UI consists of some clickable rectangles, and uses \l TapHandler to send the corresponding
+ * requests when a rectangle is clicked.
+ *
+ * \snippet custom-extension/qml-client/main.qml sendBounce
+ *
+ * For simplicity, the example has been limited to only demonstrate the \c bounce and \c spin
+ * requests as well as the \c set_font_size event. Adding support for the additional features is
+ * left as an exercise for the reader.
+ */
diff --git a/examples/wayland/custom-extension/qml-client/CMakeLists.txt b/examples/wayland/custom-extension/qml-client/CMakeLists.txt
index 30c6c90d1..1ac276c2a 100644
--- a/examples/wayland/custom-extension/qml-client/CMakeLists.txt
+++ b/examples/wayland/custom-extension/qml-client/CMakeLists.txt
@@ -14,6 +14,7 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/custom-extension/qml-clie
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick WaylandClient)
+qt6_policy(SET QTP0001 NEW)
qt_add_executable(custom-extension-qml-client
../client-common/customextension.cpp ../client-common/customextension.h
main.cpp
@@ -50,6 +51,13 @@ qt6_add_resources(custom-extension-qml-client "qml"
${qml_resource_files}
)
+target_include_directories(custom-extension-qml-client PUBLIC ../client-common/)
+
+qt6_add_qml_module(custom-extension-qml-client
+ URI io.qt.examples.customextension
+ VERSION 1.0
+)
+
install(TARGETS custom-extension-qml-client
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/wayland/custom-extension/qml-client/main.cpp b/examples/wayland/custom-extension/qml-client/main.cpp
index 3fcc05fad..126c6b915 100644
--- a/examples/wayland/custom-extension/qml-client/main.cpp
+++ b/examples/wayland/custom-extension/qml-client/main.cpp
@@ -1,19 +1,16 @@
// Copyright (C) 2017 Erik Larsson.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QGuiApplication>
+#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
-
-#include <QtQml/qqml.h>
#include <QtQml/QQmlEngine>
+
#include "../client-common/customextension.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
- qmlRegisterType<CustomExtension>("io.qt.examples.customextension", 1, 0, "CustomExtension");
-
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
diff --git a/examples/wayland/custom-extension/qml-client/main.qml b/examples/wayland/custom-extension/qml-client/main.qml
index 6ceefda2f..da81055bc 100644
--- a/examples/wayland/custom-extension/qml-client/main.qml
+++ b/examples/wayland/custom-extension/qml-client/main.qml
@@ -1,4 +1,5 @@
// Copyright (C) 2017 Erik Larsson.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
@@ -7,59 +8,84 @@ import io.qt.examples.customextension
Window {
id: topLevelWindow
-
- property alias textItem: bounceText
-
title: "QML Client"
visible: true
+ width: 800
+ height: 600
- Rectangle {
- anchors.fill: parent
- color: "#f1eece"
- }
+ property real fontSize: height / 50
- Text {
- id: bounceText
- text: "press here to bounce"
- }
+ Column {
+ anchors.centerIn: parent
+ width: topLevelWindow.width / 4
+ height: 2 * (width + topLevelWindow.height / 12)
+ spacing: topLevelWindow.height / 12
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (customExtension.active)
- customExtension.sendBounce(topLevelWindow, 1000)
- }
- }
+ Rectangle {
+ id: rect1
+ color: "#C0FFEE"
+ width: parent.width
+ height: width
+ clip: true
- MouseArea {
- anchors.centerIn: parent
- width: 100; height: 100
- onClicked: {
- if (customExtension.active)
- customExtension.sendSpin(topLevelWindow, 500)
+ Text {
+ anchors.centerIn: parent
+ text: "Press here to send spin request."
+ font.pixelSize: fontSize
+ width: parent.width
+ height: parent.height
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+ }
+
+ TapHandler {
+ onTapped: {
+ if (customExtension.active)
+ customExtension.sendSpin(topLevelWindow, 500)
+ }
+ }
}
Rectangle {
- anchors.fill: parent
- color: "#fab1ed"
+ id: rect2
+ color: "#decaff"
+ width: parent.width
+ height: parent.height / 2
+ clip: true
+
Text {
- text: "spin"
+ anchors.centerIn: parent
+ text: "Press here to send bounce request."
+ font.pixelSize: fontSize
+ width: parent.width
+ height: parent.height
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+ }
+
+//! [sendBounce]
+ TapHandler {
+ onTapped: {
+ if (customExtension.active)
+ customExtension.sendBounce(topLevelWindow, 1000)
+ }
}
+//! [sendBounce]
}
}
+//! [CustomExtension]
CustomExtension {
id: customExtension
onActiveChanged: {
- console.log("Custom extension is active:", active)
registerWindow(topLevelWindow)
}
onFontSize: (window, pixelSize) => {
- // signal arguments: window and pixelSize
- // we are free to interpret the protocol as we want, so
- // let's change the font size of just one of the text items
- window.textItem.font.pixelSize = pixelSize
+ topLevelWindow.fontSize = pixelSize
}
}
+//! [CustomExtension]
}
diff --git a/examples/wayland/custom-extension/qml-client/qml-client.pro b/examples/wayland/custom-extension/qml-client/qml-client.pro
index bad4af2db..8bddb730b 100644
--- a/examples/wayland/custom-extension/qml-client/qml-client.pro
+++ b/examples/wayland/custom-extension/qml-client/qml-client.pro
@@ -2,6 +2,12 @@ TEMPLATE = app
QT += qml quick waylandclient gui-private
CONFIG += wayland-scanner
+CONFIG += qmltypes
+QML_IMPORT_NAME = io.qt.examples.customextension
+QML_IMPORT_MAJOR_VERSION = 1
+
+INCLUDEPATH += $$PWD/../client-common
+
WAYLANDCLIENTSOURCES += ../protocol/custom.xml
SOURCES += main.cpp \