summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@theqtcompany.com>2016-04-11 12:01:27 +0200
committerJohan Helsing <johan.helsing@qt.io>2016-10-10 14:24:18 +0000
commitacb37c995a93b208540d73dc9035d924db3d646d (patch)
tree9fb32428b257741ac823cc33954fe54816aeed64 /examples
parent4a792b169ed3810d60ddb5f8fab576368fbd7c4f (diff)
downloadqtwayland-acb37c995a93b208540d73dc9035d924db3d646d.tar.gz
Add a multi-screen compositor example
This example shows how shell surfaces can move across outputs in order to create traditional multi-monitor desktop functionality. Change-Id: Ie7c0aa1dc47c0c1a944dffcce5237dee92785396 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io> Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@hawaiios.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/wayland/multi-screen/main.cpp55
-rw-r--r--examples/wayland/multi-screen/multi-screen.pro18
-rw-r--r--examples/wayland/multi-screen/multi-screen.qrc7
-rw-r--r--examples/wayland/multi-screen/qml/Chrome.qml77
-rw-r--r--examples/wayland/multi-screen/qml/Screen.qml82
-rw-r--r--examples/wayland/multi-screen/qml/main.qml127
-rw-r--r--examples/wayland/wayland.pro1
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