summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikko Levonmaa <mikko.levonmaa@lge.com>2015-10-29 10:48:33 +0200
committerMikko Levonmaa <mikko.levonmaa@bitfactor.fi>2015-11-28 11:25:12 +0000
commitb0ae3f5473c1ad2e4a389297857dfb58fe933062 (patch)
tree1e73936f95e1292ec7b2a1b57ad20704344d0dad
parent5860ecb6a059c0c21d17b81f4ef3be836cf677c6 (diff)
Example app for subsurfaces
The example subsurface client can be used to test the sync modes. Space bar will toggle the sync mode, when in sync mode the cyan rectangle can be dragged to generate parent surface commits Change-Id: Ie5daa5bd5dc59eac54f05442e8f53026fc42c6e3 Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
-rw-r--r--.gitignore1
-rw-r--r--examples/wayland/subsurface/child.qml67
-rw-r--r--examples/wayland/subsurface/main.cpp131
-rw-r--r--examples/wayland/subsurface/main.qml72
-rw-r--r--examples/wayland/subsurface/qml.qrc6
-rw-r--r--examples/wayland/subsurface/shmwindow.cpp74
-rw-r--r--examples/wayland/subsurface/shmwindow.h60
-rw-r--r--examples/wayland/subsurface/subsurface.pro17
-rw-r--r--examples/wayland/wayland.pro2
9 files changed, 430 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index b33ca9077..7c6850242 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,7 @@ examples/wayland/server-buffer/compositor/qwayland-server-*.cpp
examples/wayland/server-buffer/compositor/qwayland-server-*.h
examples/wayland/server-buffer/compositor/*-server-protocol.h
examples/wayland/server-buffer/compositor/*-protocol.c
+examples/wayland/subsurface/subsurface
src/client/qwayland*.cpp
src/client/*-protocol.c
src/compositor/*-server-protocol.h
diff --git a/examples/wayland/subsurface/child.qml b/examples/wayland/subsurface/child.qml
new file mode 100644
index 000000000..b2e54054e
--- /dev/null
+++ b/examples/wayland/subsurface/child.qml
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 LG Electronics Inc, author: <mikko.levonmaa@lge.com>
+** Contact: http://www.qt.io/licensing/
+**
+** 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.4
+import QtQuick.Window 2.2
+
+Rectangle {
+ width: 300
+ height: 300
+
+ color: "darkgray"
+
+ Rectangle {
+ width: 100
+ height: 100
+ color: "magenta"
+
+ Text {
+ anchors.centerIn: parent
+ text: "quick"
+ }
+
+ RotationAnimation on rotation {
+ duration: 10000
+ loops: Animation.Infinite
+ from: 0
+ to: 360
+ }
+ }
+}
diff --git a/examples/wayland/subsurface/main.cpp b/examples/wayland/subsurface/main.cpp
new file mode 100644
index 000000000..c913c32fb
--- /dev/null
+++ b/examples/wayland/subsurface/main.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 LG Electronics Inc, author: <mikko.levonmaa@lge.com>
+** Contact: http://www.qt.io/licensing/
+**
+** 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 <QGuiApplication>
+#include <QQmlEngine>
+#include <QQmlFileSelector>
+#include <QQmlContext>
+#include <QQuickView>
+
+#include <QtPlatformHeaders/qwaylandwindowfunctions.h>
+
+#include "shmwindow.h"
+
+class Filter : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool sync READ getSync NOTIFY syncChanged)
+
+public:
+ Filter()
+ {
+ sync = false;
+ }
+
+ bool eventFilter(QObject *object, QEvent *event)
+ {
+ Q_UNUSED(object);
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Space) {
+ toggleSync(quick);
+ toggleSync(shm);
+ }
+ }
+ return false;
+ }
+
+ void toggleSync(QWindow *w)
+ {
+ sync = !QWaylandWindowFunctions::isSync(w);
+ if (QWaylandWindowFunctions::isSync(w))
+ QWaylandWindowFunctions::setDeSync(w);
+ else
+ QWaylandWindowFunctions::setSync(w);
+ emit syncChanged();
+ }
+
+ bool getSync() const
+ {
+ return sync;
+ }
+
+Q_SIGNALS:
+ void syncChanged();
+
+public:
+ QWindow *quick;
+ QWindow *shm;
+ bool sync;
+};
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+ QQuickView view;
+ view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+
+ Filter f;
+ view.rootContext()->setContextProperty("syncStatus", &f);
+ view.installEventFilter(&f);
+
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ QQuickView child(&view);
+ child.connect(child.engine(), SIGNAL(quit()), &app, SLOT(quit()));
+ child.setSource(QUrl("qrc:/child.qml"));
+ child.setResizeMode(QQuickView::SizeRootObjectToView);
+ child.setGeometry(QRect(150, 70, 100, 100));
+ child.show();
+
+ ShmWindow shm(&view);
+ shm.setGeometry(QRect(30, 30, 50, 50));
+ shm.show();
+
+ f.quick = &child;
+ f.shm = &shm;
+
+ return app.exec();
+}
+
+#include "main.moc"
+
diff --git a/examples/wayland/subsurface/main.qml b/examples/wayland/subsurface/main.qml
new file mode 100644
index 000000000..fa71d4b6b
--- /dev/null
+++ b/examples/wayland/subsurface/main.qml
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 LG Electronics Inc, author: <mikko.levonmaa@lge.com>
+** Contact: http://www.qt.io/licensing/
+**
+** 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.4
+import QtQuick.Window 2.2
+
+Rectangle {
+ id: root
+
+ width: 300
+ height: 300
+
+ color: "blue"
+
+ Rectangle {
+ id: r
+ width: 100
+ height: 100
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ color: "cyan"
+
+ MouseArea {
+ anchors.fill: parent
+ drag.target: r
+ drag.axis: Drag.XAndYAxis
+ }
+ }
+
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: syncStatus.sync ? "sync mode" : "de-sync mode"
+ }
+}
diff --git a/examples/wayland/subsurface/qml.qrc b/examples/wayland/subsurface/qml.qrc
new file mode 100644
index 000000000..f81739af9
--- /dev/null
+++ b/examples/wayland/subsurface/qml.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>main.qml</file>
+ <file>child.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/wayland/subsurface/shmwindow.cpp b/examples/wayland/subsurface/shmwindow.cpp
new file mode 100644
index 000000000..50452953a
--- /dev/null
+++ b/examples/wayland/subsurface/shmwindow.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 LG Electronics Ltd, author: <mikko.levonmaa@lge.com>
+** Contact: http://www.qt.io/licensing/
+**
+** 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 "shmwindow.h"
+
+#include <QPainter>
+#include <QDebug>
+
+ShmWindow::ShmWindow(QWindow *parent)
+ : QRasterWindow(parent)
+ , m_rotation(0)
+{
+ m_timer = startTimer(100);
+}
+
+void ShmWindow::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == m_timer) {
+ m_rotation++;
+ update();
+ }
+}
+
+void ShmWindow::paintEvent(QPaintEvent *event)
+{
+ Q_UNUSED(event);
+ QPainter painter(this);
+
+ painter.fillRect(0, 0, width(), height(), Qt::white);
+
+ qreal xc = width() * 0.5;
+ qreal yc = height() * 0.5;
+ painter.translate(xc, yc);
+ painter.rotate(m_rotation);
+ painter.drawText(QRectF(-xc, -yc, width(), height()), Qt::AlignCenter, QStringLiteral("SHM"));
+}
+
diff --git a/examples/wayland/subsurface/shmwindow.h b/examples/wayland/subsurface/shmwindow.h
new file mode 100644
index 000000000..451f5fc4a
--- /dev/null
+++ b/examples/wayland/subsurface/shmwindow.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 LG Electronics Ltd, author: <mikko.levonmaa@lge.com>
+** Contact: http://www.qt.io/licensing/
+**
+** 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$
+**
+****************************************************************************/
+
+#ifndef SHMWINDOW_H
+#define SHMWINDOW_H
+
+#include <QtGui>
+
+class ShmWindow : public QRasterWindow
+{
+ Q_OBJECT
+public:
+ explicit ShmWindow(QWindow *parent);
+
+protected:
+ void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
+
+private:
+ int m_rotation;
+ int m_timer;
+};
+#endif // SHMWINDOW_H
diff --git a/examples/wayland/subsurface/subsurface.pro b/examples/wayland/subsurface/subsurface.pro
new file mode 100644
index 000000000..5371ac5f5
--- /dev/null
+++ b/examples/wayland/subsurface/subsurface.pro
@@ -0,0 +1,17 @@
+TEMPLATE = app
+
+QT += \
+ gui gui-private core-private\
+ quick \
+ waylandclient \
+
+HEADERS += \
+ shmwindow.h \
+
+SOURCES += \
+ main.cpp \
+ shmwindow.cpp \
+
+RESOURCES += \
+ qml.qrc
+
diff --git a/examples/wayland/wayland.pro b/examples/wayland/wayland.pro
index d633fb924..be50cc782 100644
--- a/examples/wayland/wayland.pro
+++ b/examples/wayland/wayland.pro
@@ -11,3 +11,5 @@ contains(CONFIG, wayland-compositor) {
SUBDIRS += server-buffer
}
+
+SUBDIRS += subsurface