diff options
Diffstat (limited to 'examples/wayland/custom-extension/compositor')
7 files changed, 87 insertions, 301 deletions
diff --git a/examples/wayland/custom-extension/compositor/CMakeLists.txt b/examples/wayland/custom-extension/compositor/CMakeLists.txt index de5eafd96..200e7766d 100644 --- a/examples/wayland/custom-extension/compositor/CMakeLists.txt +++ b/examples/wayland/custom-extension/compositor/CMakeLists.txt @@ -1,25 +1,20 @@ -# Generated from compositor.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -cmake_minimum_required(VERSION 3.14) -project(custom-extension-compositor LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) +cmake_minimum_required(VERSION 3.16) +project(custom-extension-compositor) set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") + set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/wayland/custom-extension/compositor") -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Qml) -find_package(Qt6 COMPONENTS WaylandCompositor) +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 @@ -29,10 +24,12 @@ qt6_generate_wayland_protocol_server_sources(custom-extension-compositor FILES ${CMAKE_CURRENT_SOURCE_DIR}/../protocol/custom.xml ) + set_target_properties(custom-extension-compositor PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) + target_link_libraries(custom-extension-compositor PUBLIC Qt::Core Qt::Gui @@ -40,7 +37,6 @@ target_link_libraries(custom-extension-compositor PUBLIC Qt::WaylandCompositor ) - # Resources: set(compositor_resource_files "images/background.png" @@ -55,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 d9f637a12..0d19a62e2 100644 --- a/examples/wayland/custom-extension/compositor/customextension.cpp +++ b/examples/wayland/custom-extension/compositor/customextension.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 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$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "customextension.h" @@ -55,7 +8,7 @@ #include <QDebug> CustomExtension::CustomExtension(QWaylandCompositor *compositor) - :QWaylandCompositorExtensionTemplate(compositor) + : QWaylandCompositorExtensionTemplate(compositor) { } @@ -66,6 +19,7 @@ void CustomExtension::initialize() init(compositor->display(), 1); } +//! [setFontSize] void CustomExtension::setFontSize(QWaylandSurface *surface, uint pixelSize) { if (surface) { @@ -76,6 +30,7 @@ void CustomExtension::setFontSize(QWaylandSurface *surface, uint pixelSize) } } } +//! [setFontSize] void CustomExtension::showDecorations(QWaylandClient *client, bool shown) { @@ -86,7 +41,6 @@ void CustomExtension::showDecorations(QWaylandClient *client, bool shown) send_set_window_decoration(target->handle, shown); } } - } void CustomExtension::close(QWaylandSurface *surface) @@ -100,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); @@ -107,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) { @@ -137,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 dc44dfc2a..e377d5f57 100644 --- a/examples/wayland/custom-extension/compositor/customextension.h +++ b/examples/wayland/custom-extension/compositor/customextension.h @@ -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 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$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef CUSTOMEXTENSION_H #define CUSTOMEXTENSION_H @@ -56,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; @@ -72,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: @@ -80,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 91de8f798..69e34d2dc 100644 --- a/examples/wayland/custom-extension/compositor/main.cpp +++ b/examples/wayland/custom-extension/compositor/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 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$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include <QtCore/QUrl> #include <QtCore/QDebug> @@ -58,15 +11,12 @@ #include "customextension.h" -static void registerTypes() -{ - qmlRegisterType<CustomExtensionQuickExtension>("com.theqtcompany.customextension", 1, 0, "CustomExtension"); -} - int main(int argc, char *argv[]) { + // ShareOpenGLContexts is needed for using the threaded renderer + // on Nvidia EGLStreams + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); 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 3d3deca58..ea2cb9b16 100644 --- a/examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml +++ b/examples/wayland/custom-extension/compositor/qml/CompositorScreen.qml @@ -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 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$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtQuick.Window @@ -56,6 +9,7 @@ WaylandOutput { id: output property alias surfaceArea: background sizeFollowsWindow: true + window: Window { id: screen @@ -67,7 +21,7 @@ WaylandOutput { Rectangle { id: sidebar - width: 150 + width: 250 anchors.left: parent.left anchors.top: parent.top anchors.bottom: parent.bottom @@ -81,19 +35,20 @@ WaylandOutput { Repeater { model: comp.itemList Rectangle { - height: 36 + height: 54 width: sidebar.width - 5 color: "white" radius: 5 Text { - text: "window: " + modelData.shellSurface.title + "[" + modelData.shellSurface.className - + (modelData.isCustom ? "]\nfont size: " + modelData.fontSize :"]\n No extension") + text: "window: " + modelData.shellSurface.toplevel.title + "\n[" + + modelData.shellSurface.toplevel.appId + + (modelData.isCustom ? "]\nfont size: " + modelData.fontSize : "]\nNo extension") color: modelData.isCustom ? "black" : "darkgray" } MouseArea { enabled: modelData.isCustom anchors.fill: parent - onWheel: { + onWheel: (wheel) => { if (wheel.angleDelta.y > 0) modelData.fontSize++ else if (wheel.angleDelta.y < 0 && modelData.fontSize > 3) diff --git a/examples/wayland/custom-extension/compositor/qml/main.qml b/examples/wayland/custom-extension/compositor/qml/main.qml index fcd7eba79..9907263da 100644 --- a/examples/wayland/custom-extension/compositor/qml/main.qml +++ b/examples/wayland/custom-extension/compositor/qml/main.qml @@ -1,58 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause import QtQuick import QtWayland.Compositor -import QtWayland.Compositor.WlShell +import QtWayland.Compositor.XdgShell -import com.theqtcompany.customextension 1.0 +import io.qt.examples.customextension 1.0 WaylandCompositor { id: comp @@ -81,36 +34,38 @@ WaylandCompositor { property int fontSize: 12 onSurfaceDestroyed: { - var index = itemList.indexOf(chrome); + var index = itemList.indexOf(chrome) if (index > -1) { var listCopy = itemList - listCopy.splice(index, 1); + listCopy.splice(index, 1) itemList = listCopy } chrome.destroy() } + transform: [ Rotation { id: xRot - origin.x: chrome.width/2; origin.y: chrome.height/2; + origin.x: chrome.width / 2; origin.y: chrome.height / 2 angle: 0 axis { x: 1; y: 0; z: 0 } }, Rotation { id: yRot - origin.x: chrome.width/2; origin.y: chrome.height/2; + origin.x: chrome.width / 2; origin.y: chrome.height / 2 angle: 0 axis { x: 0; y: 1; z: 0 } } ] + NumberAnimation { id: spinAnimation running: false loops: 2 - target: yRot; - property: "angle"; - from: 0; to: 360; - duration: 400; + target: yRot + property: "angle" + from: 0; to: 360 + duration: 400 } function doSpin(ms) { @@ -129,18 +84,21 @@ WaylandCompositor { easing.type: Easing.OutBounce duration: 1000 } + function doBounce(ms) { console.log("bounce " + ms) // using the 'ms' argument is left as an exercise for the reader... bounceAnimation.start() } + +//! [setFontSize] onFontSizeChanged: { custom.setFontSize(surface, fontSize) } +//! [setFontSize] } } - Component { id: customObjectComponent Rectangle { @@ -150,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) @@ -167,53 +125,59 @@ WaylandCompositor { Connections { target: obj - onResourceDestroyed: { + function onResourceDestroyed() { customItem.destroy() } } } } - WlShell { - id: defaultShell - onWlShellSurfaceCreated: { - var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": shellSurface } ); - var w = defaultOutput.surfaceArea.width/2 - var h = defaultOutput.surfaceArea.height/2 - item.x = Math.random()*w - item.y = Math.random()*h + XdgShell { + onToplevelCreated: (toplevel, xdgSurface) => { + var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": xdgSurface } ) + var w = defaultOutput.surfaceArea.width / 2 + 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 listCopy.push(item) itemList = listCopy } } +//! [CustomExtension] CustomExtension { id: custom - onSurfaceAdded: { + onSurfaceAdded: (surface) => { var item = itemForSurface(surface) item.isCustom = true } - onBounce: { + + onBounce: (surface, ms) => { var item = itemForSurface(surface) item.doBounce(ms) } - onSpin: { + + onSpin: (surface, ms) => { var item = itemForSurface(surface) item.doSpin(ms) } - onCustomObjectCreated: { - var item = customObjectComponent.createObject(defaultOutput.surfaceArea, { "color": obj.color, "text": obj.text, "obj": obj } ); + + onCustomObjectCreated: (obj) => { + var item = customObjectComponent.createObject(defaultOutput.surfaceArea, + { "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] } |