diff options
author | Liang Qi <liang.qi@qt.io> | 2016-11-03 12:10:54 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-11-03 12:11:41 +0100 |
commit | 0e5b26942c9ff8b85322a63f577bd7a91ff0851a (patch) | |
tree | 01cbc798c813546af32e6d6de2cae923b23ba2d5 /examples | |
parent | d62667f43dcd535d9315394c4ffb2faec44684fe (diff) | |
parent | e05f6c01d2ac4b807c07a682927f75d70292595b (diff) | |
download | qtwayland-0e5b26942c9ff8b85322a63f577bd7a91ff0851a.tar.gz |
Merge remote-tracking branch 'origin/5.8' into dev
Change-Id: Ic2135c6ff27ca3fdef6a76dbdc72f73f5ca4d7fb
Diffstat (limited to 'examples')
-rw-r--r-- | examples/wayland/multi-screen/main.cpp | 55 | ||||
-rw-r--r-- | examples/wayland/multi-screen/multi-screen.pro | 18 | ||||
-rw-r--r-- | examples/wayland/multi-screen/multi-screen.qrc | 7 | ||||
-rw-r--r-- | examples/wayland/multi-screen/qml/Chrome.qml | 77 | ||||
-rw-r--r-- | examples/wayland/multi-screen/qml/Screen.qml | 82 | ||||
-rw-r--r-- | examples/wayland/multi-screen/qml/main.qml | 127 | ||||
-rw-r--r-- | examples/wayland/wayland.pro | 1 |
7 files changed, 367 insertions, 0 deletions
diff --git a/examples/wayland/multi-screen/main.cpp b/examples/wayland/multi-screen/main.cpp new file mode 100644 index 00000000..81adbc13 --- /dev/null +++ b/examples/wayland/multi-screen/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** 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 <QtCore/QUrl> +#include <QtCore/QDebug> + +#include <QtGui/QGuiApplication> + +#include <QtQml/QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine appEngine(QUrl("qrc:///qml/main.qml")); + + return app.exec(); +} diff --git a/examples/wayland/multi-screen/multi-screen.pro b/examples/wayland/multi-screen/multi-screen.pro new file mode 100644 index 00000000..29e1479d --- /dev/null +++ b/examples/wayland/multi-screen/multi-screen.pro @@ -0,0 +1,18 @@ +QT += gui qml + +SOURCES += \ + main.cpp + +OTHER_FILES = \ + qml/main.qml \ + +RESOURCES += multi-screen.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/wayland/multi-screen +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS multi-screen.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/wayland/multi-screen +INSTALLS += target sources + +DISTFILES += \ + qml/Screen.qml \ + qml/Chrome.qml diff --git a/examples/wayland/multi-screen/multi-screen.qrc b/examples/wayland/multi-screen/multi-screen.qrc new file mode 100644 index 00000000..57fcd3cf --- /dev/null +++ b/examples/wayland/multi-screen/multi-screen.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>qml/main.qml</file> + <file>qml/Screen.qml</file> + <file>qml/Chrome.qml</file> + </qresource> +</RCC> diff --git a/examples/wayland/multi-screen/qml/Chrome.qml b/examples/wayland/multi-screen/qml/Chrome.qml new file mode 100644 index 00000000..d91a9304 --- /dev/null +++ b/examples/wayland/multi-screen/qml/Chrome.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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.0 +import QtWayland.Compositor 1.0 + +Item { + id: chrome + property alias shellSurface: surfaceItem.shellSurface + property alias surfaceItem: surfaceItem + property alias moveItem: surfaceItem.moveItem + + x: surfaceItem.moveItem.x - surfaceItem.output.geometry.x + y: surfaceItem.moveItem.y - surfaceItem.output.geometry.y + + ShellSurfaceItem { + id: surfaceItem + onSurfaceDestroyed: chrome.destroy(); + } + + onXChanged: updatePrimary() + onYChanged: updatePrimary() + function updatePrimary() { + var w = surfaceItem.width + var h = surfaceItem.height + var area = w * h; + var screenW = surfaceItem.output.geometry.width; + var screenH = surfaceItem.output.geometry.height; + var x1 = Math.max(0, x); + var y1 = Math.max(0, y); + var x2 = Math.min(x + w, screenW); + var y2 = Math.min(y + h, screenH); + var w1 = Math.max(0, x2 - x1); + var h1 = Math.max(0, y2 - y1); + if (w1 * h1 * 2 > area) { + surfaceItem.setPrimary(); + } + } +} diff --git a/examples/wayland/multi-screen/qml/Screen.qml b/examples/wayland/multi-screen/qml/Screen.qml new file mode 100644 index 00000000..7e2eb01d --- /dev/null +++ b/examples/wayland/multi-screen/qml/Screen.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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$ +** 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.0 +import QtWayland.Compositor 1.0 +import QtQuick.Window 2.2 + +WaylandOutput { + id: screen + property variant viewsBySurface: ({}) + property alias surfaceArea: background + property alias text: t.text + sizeFollowsWindow: true + + window: Window { + width: 1024 + height: 760 + visible: true + + WaylandMouseTracker { + id: mouseTracker + anchors.fill: parent + windowSystemCursorEnabled: false + + Rectangle { + anchors.fill: parent + id: background + + Text { + id: t + anchors.centerIn: parent + font.pointSize: 72 + } + } + + WaylandCursorItem { + inputEventsEnabled: false + x: mouseTracker.mouseX + y: mouseTracker.mouseY + seat: comp.defaultSeat + visible: mouseTracker.containsMouse + } + } + } +} diff --git a/examples/wayland/multi-screen/qml/main.qml b/examples/wayland/multi-screen/qml/main.qml new file mode 100644 index 00000000..37350289 --- /dev/null +++ b/examples/wayland/multi-screen/qml/main.qml @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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.0 +import QtWayland.Compositor 1.0 + +WaylandCompositor { + id: comp + defaultOutput: middleScreen + + Screen { + id: leftScreen + position.x: -leftScreen.surfaceArea.width + position.y: 0 + surfaceArea.color: "#f00" + text: "Left" + compositor: comp + } + + Screen { + id: middleScreen + position.x: leftScreen.position.x + leftScreen.surfaceArea.width + position.y: 0 + text: "Middle" + surfaceArea.color: "#0f0" + compositor: comp + } + + Screen { + id: rightScreen + position.x: middleScreen.position.x + middleScreen.surfaceArea.width + position.y: 0 + surfaceArea.color: "#00f" + text: "Right" + compositor: comp + } + + Component { + id: chromeComponent + Chrome {} + } + + Component { + id: moveItemComponent + Item {} + } + + Item { + id: rootItem + x: leftScreen.position.x + y: leftScreen.position.y + width: leftScreen.surfaceArea.width + middleScreen.surfaceArea.width + rightScreen.surfaceArea.width + height: Math.max(leftScreen.surfaceArea.height, middleScreen.surfaceArea.height, rightScreen.surfaceArea.height) + } + + WlShell { + onWlShellSurfaceCreated: handleShellSurfaceCreated(shellSurface) + } + + XdgShellV5 { + onXdgSurfaceCreated: handleShellSurfaceCreated(xdgSurface) + onXdgPopupCreated: handleShellSurfaceCreated(xdgPopup) + } + + function createShellSurfaceItem(shellSurface, moveItem, output) { + var parentSurfaceItem = output.viewsBySurface[shellSurface.parentSurface]; + var parent = parentSurfaceItem || output.surfaceArea; + var item = chromeComponent.createObject(parent, { + "shellSurface": shellSurface, + "moveItem": moveItem, + "output": output + }); + if (parentSurfaceItem) { + item.x += output.position.x; + item.y += output.position.y; + } + output.viewsBySurface[shellSurface.surface] = item; + } + + function handleShellSurfaceCreated(shellSurface) { + var moveItem = moveItemComponent.createObject(rootItem, { + "width": Qt.binding(function() { return shellSurface.surface.width; }), + "height": Qt.binding(function() { return shellSurface.surface.height; }) + }); + createShellSurfaceItem(shellSurface, moveItem, middleScreen); + createShellSurfaceItem(shellSurface, moveItem, leftScreen); + createShellSurfaceItem(shellSurface, moveItem, rightScreen); + } +} diff --git a/examples/wayland/wayland.pro b/examples/wayland/wayland.pro index f36bf69e..2a539500 100644 --- a/examples/wayland/wayland.pro +++ b/examples/wayland/wayland.pro @@ -10,6 +10,7 @@ contains(QT_CONFIG, opengl):qtHaveModule(quick) { SUBDIRS += spanning-screens SUBDIRS += pure-qml SUBDIRS += multi-output + SUBDIRS += multi-screen SUBDIRS += custom-extension SUBDIRS += server-buffer SUBDIRS += ivi-compositor |