[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwayland] /: Add support for wl_subcompositor and wl_subsurface
From:       Martin_Gräßlin <mgraesslin () kde ! org>
Date:       2014-10-16 6:20:55
Message-ID: E1XeeQh-0006Dw-Ht () scm ! kde ! org
[Download RAW message or body]

Git commit 8445847002c4da022f2e8403931631c3234594b9 by Martin Gräßlin.
Committed on 14/10/2014 at 12:04.
Pushed by graesslin into branch 'master'.

Add support for wl_subcompositor and wl_subsurface

This implements the subcompositor and subsurface protocol on both
Client and Server side.

Client:
New classes SubCompositor and SubSurface. The SubCompositor can be
created through the Registry and creates the SubSurface which is
bound to a Surface and has a parent Surface. The SubSurface class
provides convenient wrappers for all calls exposed in the
wl_subsurface interface.

Server:
New classes SubCompositorInterface and SubSurfaceInterface. Support
for all commands is added, though the API probably still can need
some fine tuning. The synchronized vs. desynchronized behavior is
not yet exposed in the API. This could also be delegated towards
the user of the library.

M  +23   -0    autotests/client/CMakeLists.txt
M  +23   -0    autotests/client/test_wayland_registry.cpp
A  +173  -0    autotests/client/test_wayland_subcompositor.cpp     [License: BSD]
A  +560  -0    autotests/client/test_wayland_subsurface.cpp     [License: BSD]
M  +4    -0    src/client/CMakeLists.txt
M  +25   -0    src/client/registry.cpp
M  +39   -1    src/client/registry.h
A  +106  -0    src/client/subcompositor.cpp     [License: BSD]
A  +112  -0    src/client/subcompositor.h     [License: BSD]
A  +203  -0    src/client/subsurface.cpp     [License: BSD]
A  +192  -0    src/client/subsurface.h     [License: BSD]
M  +1    -0    src/server/CMakeLists.txt
M  +8    -0    src/server/display.cpp
M  +2    -0    src/server/display.h
A  +337  -0    src/server/subcompositor_interface.cpp     [License: BSD]
A  +97   -0    src/server/subcompositor_interface.h     [License: BSD]
A  +75   -0    src/server/subsurface_interface_p.h     [License: BSD]
M  +105  -59   src/server/surface_interface.cpp
M  +12   -0    src/server/surface_interface.h
A  +100  -0    src/server/surface_interface_p.h     [License: BSD]

http://commits.kde.org/kwayland/8445847002c4da022f2e8403931631c3234594b9

diff --git a/autotests/client/CMakeLists.txt b/autotests/client/CMakeLists.txt
index c7dc316..b593d17 100644
--- a/autotests/client/CMakeLists.txt
+++ b/autotests/client/CMakeLists.txt
@@ -100,3 +100,26 @@ add_executable(testCompositor ${testCompositor_SRCS})
 target_link_libraries( testCompositor Qt5::Test Qt5::Gui KF5::WaylandClient \
KF5::WaylandServer)  add_test(kwayland-testCompositor testCompositor)
 ecm_mark_as_test(testCompositor)
+
+########################################################
+# Test SubCompositor
+########################################################
+set( testSubCompositor_SRCS
+        test_wayland_subcompositor.cpp
+    )
+add_executable(testSubCompositor ${testSubCompositor_SRCS})
+target_link_libraries( testSubCompositor Qt5::Test Qt5::Gui KF5::WaylandClient \
KF5::WaylandServer) +add_test(kwayland-testSubCompositor testSubCompositor)
+ecm_mark_as_test(testSubCompositor)
+
+
+########################################################
+# Test SubSurface
+########################################################
+set( testSubSurface_SRCS
+        test_wayland_subsurface.cpp
+    )
+add_executable(testSubSurface ${testSubSurface_SRCS})
+target_link_libraries( testSubSurface Qt5::Test Qt5::Gui KF5::WaylandClient \
KF5::WaylandServer Wayland::Client) +add_test(kwayland-testSubSurface testSubSurface)
+ecm_mark_as_test(testSubSurface)
diff --git a/autotests/client/test_wayland_registry.cpp \
b/autotests/client/test_wayland_registry.cpp index 7765873..1bc07b8 100644
--- a/autotests/client/test_wayland_registry.cpp
+++ b/autotests/client/test_wayland_registry.cpp
@@ -28,6 +28,7 @@ License along with this library.  If not, see \
<http://www.gnu.org/licenses/>.  #include "../../src/server/output_interface.h"
 #include "../../src/server/seat_interface.h"
 #include "../../src/server/shell_interface.h"
+#include "../../src/server/subcompositor_interface.h"
 // Wayland
 #include <wayland-client-protocol.h>
 
@@ -46,6 +47,7 @@ private Q_SLOTS:
     void testBindOutput();
     void testBindShm();
     void testBindSeat();
+    void testBindSubCompositor();
     void testGlobalSync();
     void testGlobalSyncThreaded();
     void testRemoval();
@@ -57,6 +59,7 @@ private:
     KWayland::Server::OutputInterface *m_output;
     KWayland::Server::SeatInterface *m_seat;
     KWayland::Server::ShellInterface *m_shell;
+    KWayland::Server::SubCompositorInterface *m_subcompositor;
 };
 
 static const QString s_socketName = QStringLiteral("kwin-test-wayland-registry-0");
@@ -68,6 +71,7 @@ TestWaylandRegistry::TestWaylandRegistry(QObject *parent)
     , m_output(nullptr)
     , m_seat(nullptr)
     , m_shell(nullptr)
+    , m_subcompositor(nullptr)
 {
 }
 
@@ -85,6 +89,8 @@ void TestWaylandRegistry::init()
     m_seat->create();
     m_shell = m_display->createShell();
     m_shell->create();
+    m_subcompositor = m_display->createSubCompositor();
+    m_subcompositor->create();
 }
 
 void TestWaylandRegistry::cleanup()
@@ -168,6 +174,11 @@ void TestWaylandRegistry::testBindShm()
     TEST_BIND(KWayland::Client::Registry::Interface::Shm, \
SIGNAL(shmAnnounced(quint32,quint32)), bindShm, wl_shm_destroy)  }
 
+void TestWaylandRegistry::testBindSubCompositor()
+{
+    TEST_BIND(KWayland::Client::Registry::Interface::SubCompositor, \
SIGNAL(subCompositorAnnounced(quint32,quint32)), bindSubCompositor, \
wl_subcompositor_destroy) +}
+
 #undef TEST_BIND
 
 void TestWaylandRegistry::testRemoval()
@@ -194,6 +205,8 @@ void TestWaylandRegistry::testRemoval()
     QVERIFY(shellAnnouncedSpy.isValid());
     QSignalSpy seatAnnouncedSpy(&registry, SIGNAL(seatAnnounced(quint32,quint32)));
     QVERIFY(seatAnnouncedSpy.isValid());
+    QSignalSpy subCompositorAnnouncedSpy(&registry, \
SIGNAL(subCompositorAnnounced(quint32,quint32))); +    \
QVERIFY(subCompositorAnnouncedSpy.isValid());  
     QVERIFY(!registry.isValid());
     registry.create(connection.display());
@@ -204,12 +217,14 @@ void TestWaylandRegistry::testRemoval()
     QVERIFY(!outputAnnouncedSpy.isEmpty());
     QVERIFY(!shellAnnouncedSpy.isEmpty());
     QVERIFY(!seatAnnouncedSpy.isEmpty());
+    QVERIFY(!subCompositorAnnouncedSpy.isEmpty());
 
     QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Compositor));
                
     QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Output));
     QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Seat));
     QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Shell));
     QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Shm));
+    QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::SubCompositor));
                
     QVERIFY(!registry.hasInterface(KWayland::Client::Registry::Interface::FullscreenShell));
  
     QSignalSpy seatRemovedSpy(&registry, SIGNAL(seatRemoved(quint32)));
@@ -244,6 +259,14 @@ void TestWaylandRegistry::testRemoval()
     QCOMPARE(compositorRemovedSpy.first().first(), \
                compositorAnnouncedSpy.first().first());
     QVERIFY(!registry.hasInterface(KWayland::Client::Registry::Interface::Compositor));
  
+    QSignalSpy subCompositorRemovedSpy(&registry, \
SIGNAL(subCompositorRemoved(quint32))); +    \
QVERIFY(subCompositorRemovedSpy.isValid()); +
+    delete m_subcompositor;
+    QVERIFY(subCompositorRemovedSpy.wait());
+    QCOMPARE(subCompositorRemovedSpy.first().first(), \
subCompositorAnnouncedSpy.first().first()); +    \
QVERIFY(!registry.hasInterface(KWayland::Client::Registry::Interface::SubCompositor));
 +
     // cannot test shmRemoved as there is no functionality for it
 }
 
diff --git a/autotests/client/test_wayland_subcompositor.cpp \
b/autotests/client/test_wayland_subcompositor.cpp new file mode 100644
index 0000000..2e848f8
--- /dev/null
+++ b/autotests/client/test_wayland_subcompositor.cpp
@@ -0,0 +1,173 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+// Qt
+#include <QtTest/QtTest>
+// KWin
+#include "../../src/client/connection_thread.h"
+#include "../../src/client/event_queue.h"
+#include "../../src/client/registry.h"
+#include "../../src/client/subcompositor.h"
+#include "../../src/server/display.h"
+#include "../../src/server/subcompositor_interface.h"
+
+class TestSubCompositor : public QObject
+{
+    Q_OBJECT
+public:
+    explicit TestSubCompositor(QObject *parent = nullptr);
+private Q_SLOTS:
+    void init();
+    void cleanup();
+
+    void testDestroy();
+    void testCast();
+
+private:
+    KWayland::Server::Display *m_display;
+    KWayland::Server::SubCompositorInterface *m_subcompositorInterface;
+    KWayland::Client::ConnectionThread *m_connection;
+    KWayland::Client::SubCompositor *m_subCompositor;
+    KWayland::Client::EventQueue *m_queue;
+    QThread *m_thread;
+};
+
+static const QString s_socketName = \
QStringLiteral("kwayland-test-wayland-subcompositor-0"); +
+TestSubCompositor::TestSubCompositor(QObject *parent)
+    : QObject(parent)
+    , m_display(nullptr)
+    , m_subcompositorInterface(nullptr)
+    , m_connection(nullptr)
+    , m_subCompositor(nullptr)
+    , m_queue(nullptr)
+    , m_thread(nullptr)
+{
+}
+
+void TestSubCompositor::init()
+{
+    using namespace KWayland::Server;
+    delete m_display;
+    m_display = new Display(this);
+    m_display->setSocketName(s_socketName);
+    m_display->start();
+    QVERIFY(m_display->isRunning());
+
+    // setup connection
+    m_connection = new KWayland::Client::ConnectionThread;
+    QSignalSpy connectedSpy(m_connection, SIGNAL(connected()));
+    m_connection->setSocketName(s_socketName);
+
+    m_thread = new QThread(this);
+    m_connection->moveToThread(m_thread);
+    m_thread->start();
+
+    m_connection->initConnection();
+    QVERIFY(connectedSpy.wait());
+
+    m_queue = new KWayland::Client::EventQueue(this);
+    QVERIFY(!m_queue->isValid());
+    m_queue->setup(m_connection);
+    QVERIFY(m_queue->isValid());
+
+    KWayland::Client::Registry registry;
+    QSignalSpy subCompositorSpy(&registry, \
SIGNAL(subCompositorAnnounced(quint32,quint32))); +    \
QVERIFY(subCompositorSpy.isValid()); +    QVERIFY(!registry.eventQueue());
+    registry.setEventQueue(m_queue);
+    QCOMPARE(registry.eventQueue(), m_queue);
+    registry.create(m_connection->display());
+    QVERIFY(registry.isValid());
+    registry.setup();
+
+    m_subcompositorInterface = m_display->createSubCompositor(m_display);
+    QVERIFY(m_subcompositorInterface);
+    m_subcompositorInterface->create();
+    QVERIFY(m_subcompositorInterface->isValid());
+
+    QVERIFY(subCompositorSpy.wait());
+    m_subCompositor = \
registry.createSubCompositor(subCompositorSpy.first().first().value<quint32>(), \
subCompositorSpy.first().last().value<quint32>(), this); +}
+
+void TestSubCompositor::cleanup()
+{
+    if (m_subCompositor) {
+        delete m_subCompositor;
+        m_subCompositor = nullptr;
+    }
+    if (m_queue) {
+        delete m_queue;
+        m_queue = nullptr;
+    }
+    if (m_thread) {
+        m_thread->quit();
+        m_thread->wait();
+        delete m_thread;
+        m_thread = nullptr;
+    }
+    delete m_connection;
+    m_connection = nullptr;
+
+    delete m_display;
+    m_display = nullptr;
+}
+
+void TestSubCompositor::testDestroy()
+{
+    using namespace KWayland::Client;
+    connect(m_connection, &ConnectionThread::connectionDied, m_subCompositor, \
&SubCompositor::destroy); +    connect(m_connection, \
&ConnectionThread::connectionDied, m_queue, &EventQueue::destroy); +    \
QVERIFY(m_subCompositor->isValid()); +
+    QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied()));
+    QVERIFY(connectionDiedSpy.isValid());
+    delete m_display;
+    m_display = nullptr;
+    QVERIFY(connectionDiedSpy.wait());
+
+    // now the pool should be destroyed;
+    QVERIFY(!m_subCompositor->isValid());
+
+    // calling destroy again should not fail
+    m_subCompositor->destroy();
+}
+
+void TestSubCompositor::testCast()
+{
+    using namespace KWayland::Client;
+    Registry registry;
+    QSignalSpy subCompositorSpy(&registry, \
SIGNAL(subCompositorAnnounced(quint32,quint32))); +    \
registry.create(m_connection->display()); +    QVERIFY(registry.isValid());
+    registry.setup();
+
+    QVERIFY(subCompositorSpy.wait());
+
+    SubCompositor c;
+    auto wlSubComp = \
registry.bindSubCompositor(subCompositorSpy.first().first().value<quint32>(), \
subCompositorSpy.first().last().value<quint32>()); +    c.setup(wlSubComp);
+    QCOMPARE((wl_subcompositor*)c, wlSubComp);
+
+    const SubCompositor &c2(c);
+    QCOMPARE((wl_subcompositor*)c2, wlSubComp);
+}
+
+QTEST_MAIN(TestSubCompositor)
+#include "test_wayland_subcompositor.moc"
diff --git a/autotests/client/test_wayland_subsurface.cpp \
b/autotests/client/test_wayland_subsurface.cpp new file mode 100644
index 0000000..c94ebfb
--- /dev/null
+++ b/autotests/client/test_wayland_subsurface.cpp
@@ -0,0 +1,560 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+// Qt
+#include <QtTest/QtTest>
+// KWin
+#include "../../src/client/compositor.h"
+#include "../../src/client/connection_thread.h"
+#include "../../src/client/event_queue.h"
+#include "../../src/client/registry.h"
+#include "../../src/client/subcompositor.h"
+#include "../../src/client/subsurface.h"
+#include "../../src/client/surface.h"
+#include "../../src/server/display.h"
+#include "../../src/server/compositor_interface.h"
+#include "../../src/server/subcompositor_interface.h"
+#include "../../src/server/surface_interface.h"
+// Wayland
+#include <wayland-client.h>
+
+class TestSubSurface : public QObject
+{
+    Q_OBJECT
+public:
+    explicit TestSubSurface(QObject *parent = nullptr);
+private Q_SLOTS:
+    void init();
+    void cleanup();
+
+    void testCreate();
+    void testMode();
+    void testPosition();
+    void testPlaceAbove();
+    void testPlaceBelow();
+    void testDestroy();
+    void testCast();
+
+private:
+    KWayland::Server::Display *m_display;
+    KWayland::Server::CompositorInterface *m_compositorInterface;
+    KWayland::Server::SubCompositorInterface *m_subcompositorInterface;
+    KWayland::Client::ConnectionThread *m_connection;
+    KWayland::Client::Compositor *m_compositor;
+    KWayland::Client::SubCompositor *m_subCompositor;
+    KWayland::Client::EventQueue *m_queue;
+    QThread *m_thread;
+};
+
+static const QString s_socketName = \
QStringLiteral("kwayland-test-wayland-subsurface-0"); +
+TestSubSurface::TestSubSurface(QObject *parent)
+    : QObject(parent)
+    , m_display(nullptr)
+    , m_compositorInterface(nullptr)
+    , m_subcompositorInterface(nullptr)
+    , m_connection(nullptr)
+    , m_compositor(nullptr)
+    , m_subCompositor(nullptr)
+    , m_queue(nullptr)
+    , m_thread(nullptr)
+{
+}
+
+void TestSubSurface::init()
+{
+    using namespace KWayland::Server;
+    delete m_display;
+    m_display = new Display(this);
+    m_display->setSocketName(s_socketName);
+    m_display->start();
+    QVERIFY(m_display->isRunning());
+
+    // setup connection
+    m_connection = new KWayland::Client::ConnectionThread;
+    QSignalSpy connectedSpy(m_connection, SIGNAL(connected()));
+    m_connection->setSocketName(s_socketName);
+
+    m_thread = new QThread(this);
+    m_connection->moveToThread(m_thread);
+    m_thread->start();
+
+    m_connection->initConnection();
+    QVERIFY(connectedSpy.wait());
+
+    m_queue = new KWayland::Client::EventQueue(this);
+    QVERIFY(!m_queue->isValid());
+    m_queue->setup(m_connection);
+    QVERIFY(m_queue->isValid());
+
+    KWayland::Client::Registry registry;
+    QSignalSpy compositorSpy(&registry, \
SIGNAL(compositorAnnounced(quint32,quint32))); +    QVERIFY(compositorSpy.isValid());
+    QSignalSpy subCompositorSpy(&registry, \
SIGNAL(subCompositorAnnounced(quint32,quint32))); +    \
QVERIFY(subCompositorSpy.isValid()); +    QVERIFY(!registry.eventQueue());
+    registry.setEventQueue(m_queue);
+    QCOMPARE(registry.eventQueue(), m_queue);
+    registry.create(m_connection->display());
+    QVERIFY(registry.isValid());
+    registry.setup();
+
+    m_compositorInterface = m_display->createCompositor(m_display);
+    m_compositorInterface->create();
+    QVERIFY(m_compositorInterface->isValid());
+
+    m_subcompositorInterface = m_display->createSubCompositor(m_display);
+    QVERIFY(m_subcompositorInterface);
+    m_subcompositorInterface->create();
+    QVERIFY(m_subcompositorInterface->isValid());
+
+    QVERIFY(subCompositorSpy.wait());
+    m_subCompositor = \
registry.createSubCompositor(subCompositorSpy.first().first().value<quint32>(), \
subCompositorSpy.first().last().value<quint32>(), this); +
+    if (compositorSpy.isEmpty()) {
+        QVERIFY(compositorSpy.wait());
+    }
+    m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), \
compositorSpy.first().last().value<quint32>(), this); +}
+
+void TestSubSurface::cleanup()
+{
+    if (m_subCompositor) {
+        delete m_subCompositor;
+        m_subCompositor = nullptr;
+    }
+    if (m_compositor) {
+        delete m_compositor;
+        m_compositor = nullptr;
+    }
+    if (m_queue) {
+        delete m_queue;
+        m_queue = nullptr;
+    }
+    if (m_thread) {
+        m_thread->quit();
+        m_thread->wait();
+        delete m_thread;
+        m_thread = nullptr;
+    }
+    delete m_connection;
+    m_connection = nullptr;
+
+    delete m_display;
+    m_display = nullptr;
+}
+
+void TestSubSurface::testCreate()
+{
+    using namespace KWayland::Client;
+    using namespace KWayland::Server;
+    QSignalSpy surfaceCreatedSpy(m_compositorInterface, \
SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); +    \
QVERIFY(surfaceCreatedSpy.isValid()); +
+    // create two Surfaces
+    QScopedPointer<Surface> surface(m_compositor->createSurface());
+    QVERIFY(surfaceCreatedSpy.wait());
+    SurfaceInterface *serverSurface = \
surfaceCreatedSpy.first().first().value<KWayland::Server::SurfaceInterface*>(); +    \
QVERIFY(serverSurface); +
+    surfaceCreatedSpy.clear();
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+    QVERIFY(surfaceCreatedSpy.wait());
+    SurfaceInterface *serverParentSurface = \
surfaceCreatedSpy.first().first().value<KWayland::Server::SurfaceInterface*>(); +    \
QVERIFY(serverParentSurface); +
+    QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, \
SIGNAL(subSurfaceCreated(KWayland::Server::SubSurfaceInterface*))); +    \
QVERIFY(subSurfaceCreatedSpy.isValid()); +
+    // create subSurface for surface of parent
+    QScopedPointer<SubSurface> \
subSurface(m_subCompositor->createSubSurface(QPointer<Surface>(surface.data()), \
QPointer<Surface>(parent.data()))); +
+    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface); +    \
QCOMPARE(serverSubSurface->parentSurface().data(), serverParentSurface); +    \
QCOMPARE(serverSubSurface->surface().data(), serverSurface); +    \
QCOMPARE(serverSurface->subSurface().data(), serverSubSurface); +    // children are \
only added after committing the surface +    \
QCOMPARE(serverParentSurface->childSubSurfaces().count(), 0); +    // so let's commit \
the surface, to apply the stacking change +    \
parent->commit(Surface::CommitFlag::None); +    \
wl_display_flush(m_connection->display()); +    QCoreApplication::processEvents();
+    QCOMPARE(serverParentSurface->childSubSurfaces().count(), 1);
+    QCOMPARE(serverParentSurface->childSubSurfaces().first().data(), \
serverSubSurface); +
+    // and let's destroy it again
+    QSignalSpy destroyedSpy(serverSubSurface, SIGNAL(destroyed(QObject*)));
+    QVERIFY(destroyedSpy.isValid());
+    subSurface.reset();
+    QVERIFY(destroyedSpy.wait());
+    QCOMPARE(serverSurface->subSurface(), QPointer<SubSurfaceInterface>());
+    // only applied after next commit
+    QCOMPARE(serverParentSurface->childSubSurfaces().count(), 1);
+    // but the surface should be invalid
+    QVERIFY(serverParentSurface->childSubSurfaces().first().isNull());
+    // committing the state should solve it
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverParentSurface->childSubSurfaces().count(), 0);
+}
+
+void TestSubSurface::testMode()
+{
+    using namespace KWayland::Client;
+    using namespace KWayland::Server;
+    // create two Surface
+    QScopedPointer<Surface> surface(m_compositor->createSurface());
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+
+    QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, \
SIGNAL(subSurfaceCreated(KWayland::Server::SubSurfaceInterface*))); +    \
QVERIFY(subSurfaceCreatedSpy.isValid()); +
+    // create the SubSurface for surface of parent
+    QScopedPointer<SubSurface> \
subSurface(m_subCompositor->createSubSurface(QPointer<Surface>(surface.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface); +
+    // both client and server subsurface should be in synchronized mode
+    QCOMPARE(subSurface->mode(), SubSurface::Mode::Synchronized);
+    QCOMPARE(serverSubSurface->mode(), SubSurfaceInterface::Mode::Synchronized);
+
+    // verify that we can change to desynchronized
+    QSignalSpy modeChangedSpy(serverSubSurface, \
SIGNAL(modeChanged(KWayland::Server::SubSurfaceInterface::Mode))); +    \
QVERIFY(modeChangedSpy.isValid()); +
+    subSurface->setMode(SubSurface::Mode::Desynchronized);
+    QCOMPARE(subSurface->mode(), SubSurface::Mode::Desynchronized);
+
+    QVERIFY(modeChangedSpy.wait());
+    QCOMPARE(modeChangedSpy.first().first().value<KWayland::Server::SubSurfaceInterface::Mode>(), \
SubSurfaceInterface::Mode::Desynchronized); +    QCOMPARE(serverSubSurface->mode(), \
SubSurfaceInterface::Mode::Desynchronized); +
+    // setting the same again won't change
+    subSurface->setMode(SubSurface::Mode::Desynchronized);
+    QCOMPARE(subSurface->mode(), SubSurface::Mode::Desynchronized);
+    // not testing the signal, we do that after changing to synchronized
+
+    // and change back to synchronized
+    subSurface->setMode(SubSurface::Mode::Synchronized);
+    QCOMPARE(subSurface->mode(), SubSurface::Mode::Synchronized);
+
+    QVERIFY(modeChangedSpy.wait());
+    QCOMPARE(modeChangedSpy.count(), 2);
+    QCOMPARE(modeChangedSpy.first().first().value<KWayland::Server::SubSurfaceInterface::Mode>(), \
SubSurfaceInterface::Mode::Desynchronized); +    \
QCOMPARE(modeChangedSpy.last().first().value<KWayland::Server::SubSurfaceInterface::Mode>(), \
SubSurfaceInterface::Mode::Synchronized); +    QCOMPARE(serverSubSurface->mode(), \
SubSurfaceInterface::Mode::Synchronized); +}
+
+void TestSubSurface::testPosition()
+{
+    using namespace KWayland::Client;
+    using namespace KWayland::Server;
+    // create two Surface
+    QScopedPointer<Surface> surface(m_compositor->createSurface());
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+
+    QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, \
SIGNAL(subSurfaceCreated(KWayland::Server::SubSurfaceInterface*))); +    \
QVERIFY(subSurfaceCreatedSpy.isValid()); +
+    // create the SubSurface for surface of parent
+    QScopedPointer<SubSurface> \
subSurface(m_subCompositor->createSubSurface(QPointer<Surface>(surface.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface); +
+    // both client and server should have a default position
+    QCOMPARE(subSurface->position(), QPoint());
+    QCOMPARE(serverSubSurface->position(), QPoint());
+
+    QSignalSpy positionChangedSpy(serverSubSurface, \
SIGNAL(positionChanged(QPoint))); +    QVERIFY(positionChangedSpy.isValid());
+
+    // changing the position should not trigger a direct update on server side
+    subSurface->setPosition(QPoint(10, 20));
+    QCOMPARE(subSurface->position(), QPoint(10, 20));
+    // ensure it's processed on server side
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface->position(), QPoint());
+    // changing once more
+    subSurface->setPosition(QPoint(20, 30));
+    QCOMPARE(subSurface->position(), QPoint(20, 30));
+    // ensure it's processed on server side
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface->position(), QPoint());
+
+    // committing the parent surface should update the position
+    parent->commit(Surface::CommitFlag::None);
+    QVERIFY(positionChangedSpy.wait());
+    QCOMPARE(positionChangedSpy.count(), 1);
+    QCOMPARE(positionChangedSpy.first().first().toPoint(), QPoint(20, 30));
+    QCOMPARE(serverSubSurface->position(), QPoint(20, 30));
+}
+
+void TestSubSurface::testPlaceAbove()
+{
+    using namespace KWayland::Client;
+    using namespace KWayland::Server;
+    // create needed Surfaces (one parent, three client
+    QScopedPointer<Surface> surface1(m_compositor->createSurface());
+    QScopedPointer<Surface> surface2(m_compositor->createSurface());
+    QScopedPointer<Surface> surface3(m_compositor->createSurface());
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+
+    QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, \
SIGNAL(subSurfaceCreated(KWayland::Server::SubSurfaceInterface*))); +    \
QVERIFY(subSurfaceCreatedSpy.isValid()); +
+    // create the SubSurfaces for surface of parent
+    QScopedPointer<SubSurface> \
subSurface1(m_subCompositor->createSubSurface(QPointer<Surface>(surface1.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface1 = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface1); +    subSurfaceCreatedSpy.clear();
+    QScopedPointer<SubSurface> \
subSurface2(m_subCompositor->createSubSurface(QPointer<Surface>(surface2.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface2 = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface2); +    subSurfaceCreatedSpy.clear();
+    QScopedPointer<SubSurface> \
subSurface3(m_subCompositor->createSubSurface(QPointer<Surface>(surface3.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface3 = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface3); +    subSurfaceCreatedSpy.clear();
+
+    // so far the stacking order should still be empty
+    QVERIFY(serverSubSurface1->parentSurface()->childSubSurfaces().isEmpty());
+
+    // commiting the parent should create the stacking order
+    parent->commit(Surface::CommitFlag::None);
+    // ensure it's processed on server side
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface3); +
+    // raising subsurface1 should place it to top of stack
+    subSurface1->raise();
+    // ensure it's processed on server side
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    // but as long as parent is not committed it shouldn't change on server side
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    // after commit it's changed
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface1); +
+    // try placing 3 above 1, should result in 2, 1, 3
+    subSurface3->placeAbove(QPointer<SubSurface>(subSurface1.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface3); +
+    // try placing 3 above 2, should result in 2, 3, 1
+    subSurface3->placeAbove(QPointer<SubSurface>(subSurface2.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface1); +
+    // try placing 1 above 3 - shouldn't change
+    subSurface1->placeAbove(QPointer<SubSurface>(subSurface3.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface1); +
+    // and 2 above 3 - > 3, 2, 1
+    subSurface2->placeAbove(QPointer<SubSurface>(subSurface3.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface1); +}
+
+void TestSubSurface::testPlaceBelow()
+{
+    using namespace KWayland::Client;
+    using namespace KWayland::Server;
+    // create needed Surfaces (one parent, three client
+    QScopedPointer<Surface> surface1(m_compositor->createSurface());
+    QScopedPointer<Surface> surface2(m_compositor->createSurface());
+    QScopedPointer<Surface> surface3(m_compositor->createSurface());
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+
+    QSignalSpy subSurfaceCreatedSpy(m_subcompositorInterface, \
SIGNAL(subSurfaceCreated(KWayland::Server::SubSurfaceInterface*))); +    \
QVERIFY(subSurfaceCreatedSpy.isValid()); +
+    // create the SubSurfaces for surface of parent
+    QScopedPointer<SubSurface> \
subSurface1(m_subCompositor->createSubSurface(QPointer<Surface>(surface1.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface1 = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface1); +    subSurfaceCreatedSpy.clear();
+    QScopedPointer<SubSurface> \
subSurface2(m_subCompositor->createSubSurface(QPointer<Surface>(surface2.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface2 = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface2); +    subSurfaceCreatedSpy.clear();
+    QScopedPointer<SubSurface> \
subSurface3(m_subCompositor->createSubSurface(QPointer<Surface>(surface3.data()), \
QPointer<Surface>(parent.data()))); +    QVERIFY(subSurfaceCreatedSpy.wait());
+    SubSurfaceInterface *serverSubSurface3 = \
subSurfaceCreatedSpy.first().first().value<KWayland::Server::SubSurfaceInterface*>(); \
+    QVERIFY(serverSubSurface3); +    subSurfaceCreatedSpy.clear();
+
+    // so far the stacking order should still be empty
+    QVERIFY(serverSubSurface1->parentSurface()->childSubSurfaces().isEmpty());
+
+    // commiting the parent should create the stacking order
+    parent->commit(Surface::CommitFlag::None);
+    // ensure it's processed on server side
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface3); +
+    // lowering subsurface3 should place it to the bottom of stack
+    subSurface3->lower();
+    // ensure it's processed on server side
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    // but as long as parent is not committed it shouldn't change on server side
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    // after commit it's changed
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface2); +
+    // place 1 below 3 -> 1, 3, 2
+    subSurface1->placeBelow(QPointer<SubSurface>(subSurface3.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface2); +
+    // 2 below 3 -> 1, 2, 3
+    subSurface2->placeBelow(QPointer<SubSurface>(subSurface3.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface3); +
+    // 1 below 2 -> shouldn't change
+    subSurface1->placeBelow(QPointer<SubSurface>(subSurface2.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface2); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface3); +
+    // and 3 below 1 -> 3, 1, 2
+    subSurface3->placeBelow(QPointer<SubSurface>(subSurface1.data()));
+    parent->commit(Surface::CommitFlag::None);
+    wl_display_flush(m_connection->display());
+    QCoreApplication::processEvents();
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().count(), 3);
+    QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(0).data(), \
serverSubSurface3); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(1).data(), \
serverSubSurface1); +    \
QCOMPARE(serverSubSurface1->parentSurface()->childSubSurfaces().at(2).data(), \
serverSubSurface2); +}
+
+void TestSubSurface::testDestroy()
+{
+    using namespace KWayland::Client;
+
+    // create two Surfaces
+    QScopedPointer<Surface> surface(m_compositor->createSurface());
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+    // create subSurface for surface of parent
+    QScopedPointer<SubSurface> \
subSurface(m_subCompositor->createSubSurface(QPointer<Surface>(surface.data()), \
QPointer<Surface>(parent.data()))); +
+    connect(m_connection, &ConnectionThread::connectionDied, m_compositor, \
&Compositor::destroy); +    connect(m_connection, &ConnectionThread::connectionDied, \
m_subCompositor, &SubCompositor::destroy); +    connect(m_connection, \
&ConnectionThread::connectionDied, m_queue, &EventQueue::destroy); +    \
connect(m_connection, &ConnectionThread::connectionDied, surface.data(), \
&Surface::destroy); +    connect(m_connection, &ConnectionThread::connectionDied, \
parent.data(), &Surface::destroy); +    connect(m_connection, \
&ConnectionThread::connectionDied, subSurface.data(), &SubSurface::destroy); +    \
QVERIFY(subSurface->isValid()); +
+    QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied()));
+    QVERIFY(connectionDiedSpy.isValid());
+    delete m_display;
+    m_display = nullptr;
+    QVERIFY(connectionDiedSpy.wait());
+
+    // now the pool should be destroyed;
+    QVERIFY(!subSurface->isValid());
+
+    // calling destroy again should not fail
+    subSurface->destroy();
+}
+
+void TestSubSurface::testCast()
+{
+    using namespace KWayland::Client;
+
+    // create two Surfaces
+    QScopedPointer<Surface> surface(m_compositor->createSurface());
+    QScopedPointer<Surface> parent(m_compositor->createSurface());
+    // create subSurface for surface of parent
+    QScopedPointer<SubSurface> \
subSurface(m_subCompositor->createSubSurface(QPointer<Surface>(surface.data()), \
QPointer<Surface>(parent.data()))); +
+    QCOMPARE(SubSurface::get(*(subSurface.data())), \
QPointer<SubSurface>(subSurface.data())); +}
+
+QTEST_MAIN(TestSubSurface)
+#include "test_wayland_subsurface.moc"
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
index 46d2c65..b146fcc 100644
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -39,6 +39,8 @@ set(CLIENT_LIB_SRCS
     seat.cpp
     shell.cpp
     shm_pool.cpp
+    subcompositor.cpp
+    subsurface.cpp
     surface.cpp
 )
 
@@ -86,6 +88,8 @@ install(FILES
   seat.h
   shell.h
   shm_pool.h
+  subcompositor.h
+  subsurface.h
   surface.h
   DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KWayland/Client COMPONENT Devel
 )
diff --git a/src/client/registry.cpp b/src/client/registry.cpp
index 4470d16..2120c8d 100644
--- a/src/client/registry.cpp
+++ b/src/client/registry.cpp
@@ -26,6 +26,7 @@ License along with this library.  If not, see \
<http://www.gnu.org/licenses/>.  #include "seat.h"
 #include "shell.h"
 #include "shm_pool.h"
+#include "subcompositor.h"
 #include "wayland_pointer_p.h"
 // Qt
 #include <QDebug>
@@ -43,6 +44,7 @@ static const quint32 s_outputMaxVersion = 2;
 static const quint32 s_shmMaxVersion = 1;
 static const quint32 s_seatMaxVersion = 3;
 static const quint32 s_shellMaxVersion = 1;
+static const quint32 s_subcompositorMaxVersion = 1;
 
 class Registry::Private
 {
@@ -203,6 +205,8 @@ static Registry::Interface nameToInterface(const char *interface)
         return Registry::Interface::Output;
     } else if (strcmp(interface, "_wl_fullscreen_shell") == 0) {
         return Registry::Interface::FullscreenShell;
+    } else if (strcmp(interface, "wl_subcompositor") == 0) {
+        return Registry::Interface::SubCompositor;
     }
     return Registry::Interface::Unknown;
 }
@@ -236,6 +240,9 @@ void Registry::Private::handleAnnounce(uint32_t name, const char \
*interface, uin  case Interface::FullscreenShell:
         emit q->fullscreenShellAnnounced(name, version);
         break;
+    case Interface::SubCompositor:
+        emit q->subCompositorAnnounced(name, version);
+        break;
     case Interface::Unknown:
     default:
         // nothing
@@ -272,6 +279,9 @@ void Registry::Private::handleRemove(uint32_t name)
         case Interface::FullscreenShell:
             emit q->fullscreenShellRemoved(data.name);
             break;
+        case Interface::SubCompositor:
+            emit q->subCompositorRemoved(data.name);
+            break;
         case Interface::Unknown:
         default:
             // nothing
@@ -321,6 +331,11 @@ wl_shm *Registry::bindShm(uint32_t name, uint32_t version) const
     return d->bind<wl_shm>(Interface::Shm, name, qMin(s_shmMaxVersion, version));
 }
 
+wl_subcompositor *Registry::bindSubCompositor(uint32_t name, uint32_t version) const
+{
+    return d->bind<wl_subcompositor>(Interface::SubCompositor, name, \
qMin(s_subcompositorMaxVersion, version)); +}
+
 _wl_fullscreen_shell *Registry::bindFullscreenShell(uint32_t name, uint32_t version) \
const  {
     return d->bind<_wl_fullscreen_shell>(Interface::FullscreenShell, name, version);
@@ -372,6 +387,14 @@ ShmPool *Registry::createShmPool(quint32 name, quint32 version, \
QObject *parent)  return s;
 }
 
+SubCompositor *Registry::createSubCompositor(quint32 name, quint32 version, QObject \
*parent) +{
+    auto s = new SubCompositor(parent);
+    s->setEventQueue(d->queue);
+    s->setup(bindSubCompositor(name, version));
+    return s;
+}
+
 static const wl_interface *wlInterface(Registry::Interface interface)
 {
     switch (interface) {
@@ -387,6 +410,8 @@ static const wl_interface *wlInterface(Registry::Interface \
interface)  return &wl_shm_interface;
     case Registry::Interface::FullscreenShell:
         return &_wl_fullscreen_shell_interface;
+    case Registry::Interface::SubCompositor:
+        return &wl_subcompositor_interface;
     case Registry::Interface::Unknown:
     default:
         return nullptr;
diff --git a/src/client/registry.h b/src/client/registry.h
index 0368ca7..4ddb61d 100644
--- a/src/client/registry.h
+++ b/src/client/registry.h
@@ -32,6 +32,7 @@ struct wl_registry;
 struct wl_seat;
 struct wl_shell;
 struct wl_shm;
+struct wl_subcompositor;
 struct _wl_fullscreen_shell;
 
 namespace KWayland
@@ -47,6 +48,7 @@ class Output;
 class Seat;
 class Shell;
 class ShmPool;
+class SubCompositor;
 
 /**
  * @short Wrapper for the wl_registry interface.
@@ -89,7 +91,8 @@ public:
         Seat,       ///< Refers to the wl_seat interface
         Shm,        ///< Refers to the wl_shm interface
         Output,     ///< Refers to the wl_output interface
-        FullscreenShell ///< Refers to the _wl_fullscreen_shell interface
+        FullscreenShell, ///< Refers to the _wl_fullscreen_shell interface
+        SubCompositor ///< Refers to the wl_subcompositor interface;
     };
     explicit Registry(QObject *parent = nullptr);
     virtual ~Registry();
@@ -194,6 +197,15 @@ public:
      **/
     wl_shm *bindShm(uint32_t name, uint32_t version) const;
     /**
+     * Binds the wl_subcompositor with @p name and @p version.
+     * If the @p name does not exist or is not for the subcompositor interface,
+     * @c null will be returned.
+     *
+     * Prefer using createSubCompositor instead.
+     * @see createSubCompositor
+     **/
+    wl_subcompositor *bindSubCompositor(uint32_t name, uint32_t version) const;
+    /**
      * Binds the wl_output with @p name and @p version.
      * If the @p name does not exist or is not for the output interface,
      * @c null will be returned.
@@ -273,6 +285,21 @@ public:
      **/
     ShmPool *createShmPool(quint32 name, quint32 version, QObject *parent = \
nullptr);  /**
+     * Creates a SubCompositor and sets it up to manage the interface identified by
+     * @p name and @p version.
+     *
+     * Note: in case @p name is invalid or isn't for the wl_subcompositor interface,
+     * the returned SubCompositor will not be valid. Therefore it's recommended to \
call +     * isValid on the created instance.
+     *
+     * @param name The name of the wl_subcompositor interface to bind
+     * @param version The version or the wl_subcompositor interface to use
+     * @param parent The parent for SubCompositor
+     *
+     * @returns The created SubCompositor.
+     **/
+    SubCompositor *createSubCompositor(quint32 name, quint32 version, QObject \
*parent = nullptr); +    /**
      * Creates an Output and sets it up to manage the interface identified by
      * @p name and @p version.
      *
@@ -333,6 +360,12 @@ Q_SIGNALS:
      **/
     void shmAnnounced(quint32 name, quint32 version);
     /**
+     * Emitted whenever a wl_subcompositor interface gets announced.
+     * @param name The name for the announced interface
+     * @param version The maximum supported version of the announced interface
+     **/
+    void subCompositorAnnounced(quint32 name, quint32 version);
+    /**
      * Emitted whenever a wl_output interface gets announced.
      * @param name The name for the announced interface
      * @param version The maximum supported version of the announced interface
@@ -365,6 +398,11 @@ Q_SIGNALS:
      **/
     void shmRemoved(quint32 name);
     /**
+     * Emitted whenever a wl_subcompositor interface gets removed.
+     * @param name The name for the removed interface
+     **/
+    void subCompositorRemoved(quint32 name);
+    /**
      * Emitted whenever a wl_output interface gets removed.
      * @param name The name for the removed interface
      **/
diff --git a/src/client/subcompositor.cpp b/src/client/subcompositor.cpp
new file mode 100644
index 0000000..7484567
--- /dev/null
+++ b/src/client/subcompositor.cpp
@@ -0,0 +1,106 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#include "subcompositor.h"
+#include "event_queue.h"
+#include "subsurface.h"
+#include "surface.h"
+#include "wayland_pointer_p.h"
+// Wayland
+#include <wayland-client-protocol.h>
+
+namespace KWayland
+{
+namespace Client
+{
+
+class SubCompositor::Private
+{
+public:
+    WaylandPointer<wl_subcompositor, wl_subcompositor_destroy> subCompositor;
+    EventQueue *queue = nullptr;
+};
+
+SubCompositor::SubCompositor(QObject *parent)
+    : QObject(parent)
+    , d(new Private)
+{
+}
+
+SubCompositor::~SubCompositor()
+{
+    release();
+}
+
+void SubCompositor::release()
+{
+    d->subCompositor.release();
+}
+
+void SubCompositor::destroy()
+{
+    d->subCompositor.destroy();
+}
+
+void SubCompositor::setup(wl_subcompositor *subcompositor)
+{
+    Q_ASSERT(subcompositor);
+    Q_ASSERT(!d->subCompositor.isValid());
+    d->subCompositor.setup(subcompositor);
+}
+
+SubSurface *SubCompositor::createSubSurface(QPointer<Surface> surface, \
QPointer<Surface> parentSurface, QObject *parent) +{
+    Q_ASSERT(isValid());
+    SubSurface *s = new SubSurface(surface, parentSurface, parent);
+    auto w = wl_subcompositor_get_subsurface(d->subCompositor, *surface, \
*parentSurface); +    if (d->queue) {
+        d->queue->addProxy(w);
+    }
+    s->setup(w);
+    return s;
+}
+
+bool SubCompositor::isValid() const
+{
+    return d->subCompositor.isValid();
+}
+
+SubCompositor::operator wl_subcompositor*()
+{
+    return d->subCompositor;
+}
+
+SubCompositor::operator wl_subcompositor*() const
+{
+    return d->subCompositor;
+}
+
+EventQueue *SubCompositor::eventQueue()
+{
+    return d->queue;
+}
+
+void SubCompositor::setEventQueue(EventQueue *queue)
+{
+    d->queue = queue;
+}
+
+}
+}
diff --git a/src/client/subcompositor.h b/src/client/subcompositor.h
new file mode 100644
index 0000000..16bf893
--- /dev/null
+++ b/src/client/subcompositor.h
@@ -0,0 +1,112 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#ifndef WAYLAND_SUBCOMPOSITOR_H
+#define WAYLAND_SUBCOMPOSITOR_H
+
+#include <QObject>
+#include <QPointer>
+
+#include <KWayland/Client/kwaylandclient_export.h>
+
+struct wl_subcompositor;
+
+namespace KWayland
+{
+namespace Client
+{
+
+class EventQueue;
+class SubSurface;
+class Surface;
+
+/**
+ * @short Wrapper for the wl_subcompositor interface.
+ *
+ * This class is a convenient wrapper for the wl_subcompositor interface.
+ * The main purpose of this class is to create SubSurfaces.
+ *
+ * To create an instance use Registry::createSubCompositor.
+ *
+ * @see Registry
+ **/
+class KWAYLANDCLIENT_EXPORT SubCompositor : public QObject
+{
+    Q_OBJECT
+public:
+    explicit SubCompositor(QObject *parent = nullptr);
+    virtual ~SubCompositor();
+
+    /**
+     * @returns @c true if managing a wl_subcompositor.
+     **/
+    bool isValid() const;
+    /**
+     * Setup this SubCompositor to manage the @p subcompositor.
+     * When using Registry::createSubCompositor there is no need to call this
+     * method.
+     **/
+    void setup(wl_subcompositor *subcompositor);
+    /**
+     * Releases the wl_subcompositor interface.
+     * After the interface has been released the SubCompositor instance is no
+     * longer valid and can be setup with another wl_subcompositor interface.
+     **/
+    void release();
+    /**
+     * Destroys the data hold by this SubCompositor.
+     * This method is supposed to be used when the connection to the Wayland
+     * server goes away. If the connection is not valid any more, it's not
+     * possible to call release any more as that calls into the Wayland
+     * connection and the call would fail. This method cleans up the data, so
+     * that the instance can be deleted or setup to a new wl_subcompositor interface
+     * once there is a new connection available.
+     *
+     * @see release
+     **/
+    void destroy();
+
+    /**
+     * Sets the @p queue to use for creating a SubSurface.
+     **/
+    void setEventQueue(EventQueue *queue);
+    /**
+     * @returns The event queue to use for creating a SubSurface.
+     **/
+    EventQueue *eventQueue();
+
+    /**
+     * Creates and setup a new SubSurface with @p parent.
+     * @param parent The parent to pass to the Surface.
+     * @returns The new created Surface
+     **/
+    SubSurface *createSubSurface(QPointer<Surface> surface, QPointer<Surface> \
parentSurface, QObject *parent = nullptr); +
+    operator wl_subcompositor*();
+    operator wl_subcompositor*() const;
+
+private:
+    class Private;
+    QScopedPointer<Private> d;
+};
+
+}
+}
+
+#endif
diff --git a/src/client/subsurface.cpp b/src/client/subsurface.cpp
new file mode 100644
index 0000000..d74e5d3
--- /dev/null
+++ b/src/client/subsurface.cpp
@@ -0,0 +1,203 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#include "subsurface.h"
+#include "surface.h"
+#include "wayland_pointer_p.h"
+// Wayland
+#include <wayland-client-protocol.h>
+
+namespace KWayland
+{
+namespace Client
+{
+
+class SubSurface::Private
+{
+public:
+    Private(QPointer<Surface> surface, QPointer<Surface> parentSurface, SubSurface \
*q); +    void setup(wl_subsurface *subsurface);
+
+    WaylandPointer<wl_subsurface, wl_subsurface_destroy> subSurface;
+    QPointer<Surface> surface;
+    QPointer<Surface> parentSurface;
+    Mode mode = Mode::Synchronized;
+    QPoint pos = QPoint(0, 0);
+
+    static SubSurface *cast(wl_subsurface *native);
+
+private:
+    SubSurface *q;
+};
+
+SubSurface::Private::Private(QPointer< Surface > surface, QPointer< Surface > \
parentSurface, SubSurface *q) +    : surface(surface)
+    , parentSurface(parentSurface)
+    , q(q)
+{
+}
+
+void SubSurface::Private::setup(wl_subsurface *subsurface)
+{
+    Q_ASSERT(subsurface);
+    Q_ASSERT(!subSurface.isValid());
+    subSurface.setup(subsurface);
+    wl_subsurface_set_user_data(subsurface, this);
+}
+
+SubSurface *SubSurface::Private::cast(wl_subsurface *native)
+{
+    return reinterpret_cast<Private*>(wl_subsurface_get_user_data(native))->q;
+}
+
+SubSurface::SubSurface(QPointer< Surface > surface, QPointer< Surface > \
parentSurface, QObject *parent) +    : QObject(parent)
+    , d(new Private(surface, parentSurface, this))
+{
+}
+
+SubSurface::~SubSurface()
+{
+    release();
+}
+
+void SubSurface::setup(wl_subsurface *subsurface)
+{
+    d->setup(subsurface);
+}
+
+void SubSurface::destroy()
+{
+    d->subSurface.destroy();
+}
+
+void SubSurface::release()
+{
+    d->subSurface.release();
+}
+
+bool SubSurface::isValid() const
+{
+    return d->subSurface.isValid();
+}
+
+QPointer< Surface > SubSurface::surface() const
+{
+    return d->surface;
+}
+
+QPointer< Surface > SubSurface::parentSurface() const
+{
+    return d->parentSurface;
+}
+
+void SubSurface::setMode(SubSurface::Mode mode)
+{
+    if (mode == d->mode) {
+        return;
+    }
+    d->mode = mode;
+    switch (d->mode) {
+    case Mode::Synchronized:
+        wl_subsurface_set_sync(d->subSurface);
+        break;
+    case Mode::Desynchronized:
+        wl_subsurface_set_desync(d->subSurface);
+        break;
+    }
+}
+
+SubSurface::Mode SubSurface::mode() const
+{
+    return d->mode;
+}
+
+void SubSurface::setPosition(const QPoint &pos)
+{
+    if (pos == d->pos) {
+        return;
+    }
+    d->pos = pos;
+    wl_subsurface_set_position(d->subSurface, pos.x(), pos.y());
+}
+
+QPoint SubSurface::position() const
+{
+    return d->pos;
+}
+
+void SubSurface::raise()
+{
+    placeAbove(d->parentSurface);
+}
+
+void SubSurface::placeAbove(QPointer< SubSurface > sibling)
+{
+    if (sibling.isNull()) {
+        return;
+    }
+    placeAbove(sibling->surface());
+}
+
+void SubSurface::placeAbove(QPointer< Surface > sibling)
+{
+    if (sibling.isNull()) {
+        return;
+    }
+    wl_subsurface_place_above(d->subSurface, *sibling);
+}
+
+void SubSurface::lower()
+{
+    placeBelow(d->parentSurface);
+}
+
+void SubSurface::placeBelow(QPointer< Surface > sibling)
+{
+    if (sibling.isNull()) {
+        return;
+    }
+    wl_subsurface_place_below(d->subSurface, *sibling);
+}
+
+void SubSurface::placeBelow(QPointer< SubSurface > sibling)
+{
+    if (sibling.isNull()) {
+        return;
+    }
+    placeBelow(sibling->surface());
+}
+
+QPointer< SubSurface > SubSurface::get(wl_subsurface *native)
+{
+    return QPointer<SubSurface>(Private::cast(native));
+}
+
+SubSurface::operator wl_subsurface*() const
+{
+    return d->subSurface;
+}
+
+SubSurface::operator wl_subsurface*()
+{
+    return d->subSurface;
+}
+
+}
+}
diff --git a/src/client/subsurface.h b/src/client/subsurface.h
new file mode 100644
index 0000000..9393bd8
--- /dev/null
+++ b/src/client/subsurface.h
@@ -0,0 +1,192 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#ifndef WAYLAND_SUBSURFACE_H
+#define WAYLAND_SUBSURFACE_H
+
+#include <QObject>
+#include <QPointer>
+
+#include <KWayland/Client/kwaylandclient_export.h>
+
+struct wl_subsurface;
+
+namespace KWayland
+{
+namespace Client
+{
+
+class Surface;
+
+/**
+ * @short Wrapper for the wl_subsurface interface.
+ *
+ * This class is a convenient wrapper for the wl_subsurface interface.
+ * To create a SubSurface call SubCompositor::createSubSurface.
+ *
+ * A SubSurface is bound to a Surface and has a parent Surface.
+ * A SubSurface can only be created for a Surface not already used in onther way,
+ * e.g. as a ShellSurface.
+ *
+ * The SubSurface has a position in local coordinates to the parent Surface.
+ * Please note that changing the position is a double buffered state and is only
+ * applied once the parent surface is committed. The same applies for manipulating
+ * the stacking order of the SubSurface's siblings.
+ *
+ * @see SubCompositor
+ * @see Surface
+ **/
+class KWAYLANDCLIENT_EXPORT SubSurface : public QObject
+{
+    Q_OBJECT
+public:
+    explicit SubSurface(QPointer<Surface> surface, QPointer<Surface> parentSurface, \
QObject *parent = nullptr); +    virtual ~SubSurface();
+
+    /**
+     * @returns @c true if managing a wl_subsurface.
+     **/
+    bool isValid() const;
+    /**
+     * Setup this SubSurface to manage the @p subsurface.
+     * When using SubCompositor::createSubSurface there is no need to call this
+     * method.
+     **/
+    void setup(wl_subsurface *subsurface);
+    /**
+     * Releases the wl_subsurface interface.
+     * After the interface has been released the SubSurface instance is no
+     * longer valid and can be setup with another wl_subsurface interface.
+     **/
+    void release();
+    /**
+     * Destroys the data hold by this SubSurface.
+     * This method is supposed to be used when the connection to the Wayland
+     * server goes away. If the connection is not valid any more, it's not
+     * possible to call release any more as that calls into the Wayland
+     * connection and the call would fail. This method cleans up the data, so
+     * that the instance can be deleted or setup to a new wl_subsurface interface
+     * once there is a new connection available.
+     *
+     * @see release
+     **/
+    void destroy();
+
+    /**
+     * Operation Mode on how the Surface's commit should behave.
+     **/
+    enum class Mode {
+        Synchronized,
+        Desynchronized
+    };
+
+    /**
+     * Sets the operation mode to @p mode.
+     * Initially a SubSurface is in Synchronized Mode.
+     **/
+    void setMode(Mode mode);
+    Mode mode() const;
+
+    /**
+     * Sets the position in relative coordinates to the parent surface to @p pos.
+     *
+     * The change is only applied after the parent Surface got committed.
+     **/
+    void setPosition(const QPoint &pos);
+    QPoint position() const;
+
+    /**
+     * Raises this SubSurface above all siblings.
+     * This is the same as calling placeAbove with the parent surface
+     * as argument.
+     *
+     * The change is only applied after the parent surface got committed.
+     * @see placeAbove
+     **/
+    void raise();
+    /**
+     * Places the SubSurface above the @p sibling.
+     *
+     * The change is only applied after the parent surface got committed.
+     * @param sibling The SubSurface on top of which this SubSurface should be \
placed +     **/
+    void placeAbove(QPointer<SubSurface> sibling);
+    /**
+     * Places the SubSurface above the @p referenceSurface.
+     *
+     * In case @p referenceSurface is the parent surface this SubSurface is
+     * raised to the top of the stacking order. Otherwise it is put directly
+     * above the @p referenceSurface in the stacking order.
+     *
+     * The change is only applied after the parent surface got committed.
+     * @param referenceSurface Either a sibling or parent Surface
+     **/
+    void placeAbove(QPointer<Surface> referenceSurface);
+
+    /**
+     * Lowers this SubSurface below all siblings.
+     * This is the same as calling placeBelow with the parent surface
+     * as argument.
+     *
+     * The change is only applied after the parent surface got committed.
+     * @see placeBelow
+     **/
+    void lower();
+    /**
+     * Places the SubSurface below the @p sibling.
+     *
+     * The change is only applied after the parent surface got committed.
+     * @param sibling The SubSurface under which the SubSurface should be put
+     **/
+    void placeBelow(QPointer<SubSurface> sibling);
+    /**
+     * Places the SubSurface below the @p referenceSurface.
+     *
+     * In case @p referenceSurface is the parent surface this SubSurface is
+     * lowered to the bottom of the stacking order. Otherwise it is put directly
+     * below the @p referenceSurface in the stacking order.
+     *
+     * The change is only applied after the parent surface got committed.
+     * @param referenceSurface Either a sibling or parent Surface
+     **/
+    void placeBelow(QPointer<Surface> referenceSurface);
+
+    /**
+     * @returns The Surface for which this SubSurface got created.
+     **/
+    QPointer<Surface> surface() const;
+    /**
+     * @returns The parent Surface of this SubSurface.
+     **/
+    QPointer<Surface> parentSurface() const;
+
+    static QPointer<SubSurface> get(wl_subsurface *native);
+
+    operator wl_subsurface*();
+    operator wl_subsurface*() const;
+
+private:
+    class Private;
+    QScopedPointer<Private> d;
+};
+
+}
+}
+
+#endif
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt
index ab21e99..53b1a91 100644
--- a/src/server/CMakeLists.txt
+++ b/src/server/CMakeLists.txt
@@ -6,6 +6,7 @@ set(SERVER_LIB_SRCS
     seat_interface.cpp
     shell_interface.cpp
     surface_interface.cpp
+    subcompositor_interface.cpp
 )
 
 add_library(KF5WaylandServer ${SERVER_LIB_SRCS})
diff --git a/src/server/display.cpp b/src/server/display.cpp
index 07a08b6..fe71df5 100644
--- a/src/server/display.cpp
+++ b/src/server/display.cpp
@@ -22,6 +22,7 @@ License along with this library.  If not, see \
<http://www.gnu.org/licenses/>.  #include "output_interface.h"
 #include "seat_interface.h"
 #include "shell_interface.h"
+#include "subcompositor_interface.h"
 
 #include <QCoreApplication>
 #include <QDebug>
@@ -164,6 +165,13 @@ SeatInterface *Display::createSeat(QObject *parent)
     return seat;
 }
 
+SubCompositorInterface *Display::createSubCompositor(QObject *parent)
+{
+    auto c = new SubCompositorInterface(this, parent);
+    connect(this, &Display::aboutToTerminate, c, [this,c] { delete c; });
+    return c;
+}
+
 void Display::createShm()
 {
     Q_ASSERT(d->running);
diff --git a/src/server/display.h b/src/server/display.h
index a47ece8..553ed14 100644
--- a/src/server/display.h
+++ b/src/server/display.h
@@ -37,6 +37,7 @@ class CompositorInterface;
 class OutputInterface;
 class SeatInterface;
 class ShellInterface;
+class SubCompositorInterface;
 
 class KWAYLANDSERVER_EXPORT Display : public QObject
 {
@@ -68,6 +69,7 @@ public:
     void createShm();
     ShellInterface *createShell(QObject *parent = nullptr);
     SeatInterface *createSeat(QObject *parent = nullptr);
+    SubCompositorInterface *createSubCompositor(QObject *parent = nullptr);
 
 Q_SIGNALS:
     void socketNameChanged(const QString&);
diff --git a/src/server/subcompositor_interface.cpp \
b/src/server/subcompositor_interface.cpp new file mode 100644
index 0000000..a7bcacb
--- /dev/null
+++ b/src/server/subcompositor_interface.cpp
@@ -0,0 +1,337 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#include "subcompositor_interface.h"
+#include "subsurface_interface_p.h"
+#include "display.h"
+#include "surface_interface_p.h"
+// Wayland
+#include <wayland-server.h>
+
+namespace KWayland
+{
+namespace Server
+{
+
+static const quint32 s_version = 1;
+
+class SubCompositorInterface::Private
+{
+public:
+    Private(SubCompositorInterface *q, Display *d);
+    void create();
+
+    Display *display;
+    wl_global *compositor;
+
+private:
+    void bind(wl_client *client, uint32_t version, uint32_t id);
+    void subsurface(wl_client *client, wl_resource *resource, uint32_t id, \
wl_resource *surface, wl_resource *parent); +
+    static void bind(wl_client *client, void *data, uint32_t version, uint32_t id);
+    static void unbind(wl_resource *resource);
+    static void destroyCallback(wl_client *client, wl_resource *resource);
+    static void subsurfaceCallback(wl_client *client, wl_resource *resource, \
uint32_t id, wl_resource *surface, wl_resource *parent); +
+    static Private *cast(wl_resource *r) {
+        return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
+    }
+
+    SubCompositorInterface *q;
+    static const struct wl_subcompositor_interface s_interface;
+};
+
+const struct wl_subcompositor_interface SubCompositorInterface::Private::s_interface \
= { +    destroyCallback,
+    subsurfaceCallback
+};
+
+SubCompositorInterface::Private::Private(SubCompositorInterface *q, Display *d)
+    : display(d)
+    , compositor(nullptr)
+    , q(q)
+{
+}
+
+void SubCompositorInterface::Private::create()
+{
+    Q_ASSERT(!compositor);
+    compositor = wl_global_create(*display, &wl_subcompositor_interface, s_version, \
this, bind); +}
+
+void SubCompositorInterface::Private::bind(wl_client *client, void *data, uint32_t \
version, uint32_t id) +{
+    reinterpret_cast<SubCompositorInterface::Private*>(data)->bind(client, version, \
id); +}
+
+void SubCompositorInterface::Private::bind(wl_client *client, uint32_t version, \
uint32_t id) +{
+    wl_resource *resource = wl_resource_create(client, &wl_subcompositor_interface, \
qMin(version, s_version), id); +    if (!resource) {
+        wl_client_post_no_memory(client);
+        return;
+    }
+    wl_resource_set_implementation(resource, &s_interface, this, unbind);
+}
+
+void SubCompositorInterface::Private::unbind(wl_resource *resource)
+{
+    Q_UNUSED(resource)
+}
+
+void SubCompositorInterface::Private::destroyCallback(wl_client *client, wl_resource \
*resource) +{
+    Q_UNUSED(client)
+    Q_UNUSED(resource)
+}
+
+void SubCompositorInterface::Private::subsurfaceCallback(wl_client *client, \
wl_resource *resource, uint32_t id, wl_resource *surface, wl_resource *sparent) +{
+    cast(resource)->subsurface(client, resource, id, surface, sparent);
+}
+
+void SubCompositorInterface::Private::subsurface(wl_client *client, wl_resource \
*resource, uint32_t id, wl_resource *nativeSurface, wl_resource *nativeParentSurface) \
+{ +    Q_UNUSED(client)
+    SurfaceInterface *surface = SurfaceInterface::get(nativeSurface);
+    SurfaceInterface *parentSurface = SurfaceInterface::get(nativeParentSurface);
+    if (!surface || !parentSurface) {
+        wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, \
"Surface or parent surface not found"); +        return;
+    }
+    if (surface == parentSurface) {
+        wl_resource_post_error(resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, "Cannot \
become sub composite to same surface"); +        return;
+    }
+    // TODO: add check that surface is not already used in an interface (e.g. Shell)
+    // TODO: add check that parentSurface is not a child of surface
+    SubSurfaceInterface *s = new SubSurfaceInterface(q);
+    s->d->create(client, wl_resource_get_version(resource), id, surface, \
parentSurface); +    if (!s->subSurface()) {
+        wl_resource_post_no_memory(resource);
+        delete s;
+        return;
+    }
+    emit q->subSurfaceCreated(s);
+}
+
+SubCompositorInterface::SubCompositorInterface(Display *display, QObject *parent)
+    : QObject(parent)
+    , d(new Private(this, display))
+{
+}
+
+SubCompositorInterface::~SubCompositorInterface()
+{
+    destroy();
+}
+
+void SubCompositorInterface::destroy()
+{
+    if (!d->compositor) {
+        return;
+    }
+    wl_global_destroy(d->compositor);
+    d->compositor = nullptr;
+}
+
+void SubCompositorInterface::create()
+{
+    d->create();
+}
+
+bool SubCompositorInterface::isValid() const
+{
+    return d->compositor != nullptr;
+}
+
+const struct wl_subsurface_interface SubSurfaceInterface::Private::s_interface = {
+    destroyCallback,
+    setPositionCallback,
+    placeAboveCallback,
+    placeBelowCallback,
+    setSyncCallback,
+    setDeSyncCallback
+};
+
+SubSurfaceInterface::Private *SubSurfaceInterface::Private::cast(wl_resource *r)
+{
+    return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
+}
+
+SubSurfaceInterface::Private::Private(SubSurfaceInterface *q)
+    : q(q)
+{
+}
+
+SubSurfaceInterface::Private::~Private()
+{
+    // no need to notify the surface as it's tracking a QPointer which will be reset \
automatically +    if (parent) {
+        parent->d->removeChild(QPointer<SubSurfaceInterface>(q));
+    }
+    if (subSurface) {
+        wl_resource_destroy(subSurface);
+    }
+}
+
+void SubSurfaceInterface::Private::create(wl_client *client, quint32 version, \
quint32 id, SurfaceInterface *s, SurfaceInterface *p) +{
+    Q_ASSERT(!subSurface);
+    subSurface = wl_resource_create(client, &wl_subsurface_interface, version, id);
+    if (!subSurface) {
+        return;
+    }
+    surface = s;
+    parent = p;
+    surface->d->subSurface = QPointer<SubSurfaceInterface>(q);
+    parent->d->addChild(QPointer<SubSurfaceInterface>(q));
+    wl_resource_set_implementation(subSurface, &s_interface, this, unbind);
+}
+
+void SubSurfaceInterface::Private::commit()
+{
+    if (scheduledPosChange) {
+        scheduledPosChange = false;
+        pos = scheduledPos;
+        scheduledPos = QPoint();
+        emit q->positionChanged(pos);
+    }
+}
+
+void SubSurfaceInterface::Private::unbind(wl_resource *r)
+{
+    auto s = cast(r);
+    s->subSurface = nullptr;
+    s->q->deleteLater();
+}
+
+void SubSurfaceInterface::Private::destroyCallback(wl_client *client, wl_resource \
*resource) +{
+    Q_UNUSED(client)
+    cast(resource)->q->deleteLater();
+}
+
+void SubSurfaceInterface::Private::setPositionCallback(wl_client *client, \
wl_resource *resource, int32_t x, int32_t y) +{
+    Q_UNUSED(client)
+    // TODO: is this a fixed position?
+    cast(resource)->setPosition(QPoint(x, y));
+}
+
+void SubSurfaceInterface::Private::setPosition(const QPoint &p)
+{
+    if (scheduledPos == p) {
+        return;
+    }
+    scheduledPos = p;
+    scheduledPosChange = true;
+}
+
+void SubSurfaceInterface::Private::placeAboveCallback(wl_client *client, wl_resource \
*resource, wl_resource *sibling) +{
+    Q_UNUSED(client)
+    cast(resource)->placeAbove(SurfaceInterface::get(sibling));
+}
+
+void SubSurfaceInterface::Private::placeAbove(SurfaceInterface *sibling)
+{
+    if (parent.isNull()) {
+        // TODO: raise error
+        return;
+    }
+    if (!parent->d->raiseChild(QPointer<SubSurfaceInterface>(q), sibling)) {
+        wl_resource_post_error(subSurface, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, \
"Incorrect sibling"); +    }
+}
+
+void SubSurfaceInterface::Private::placeBelowCallback(wl_client *client, wl_resource \
*resource, wl_resource *sibling) +{
+    Q_UNUSED(client)
+    cast(resource)->placeBelow(SurfaceInterface::get(sibling));
+}
+
+void SubSurfaceInterface::Private::placeBelow(SurfaceInterface *sibling)
+{
+    if (parent.isNull()) {
+        // TODO: raise error
+        return;
+    }
+    if (!parent->d->lowerChild(QPointer<SubSurfaceInterface>(q), sibling)) {
+        wl_resource_post_error(subSurface, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, \
"Incorrect sibling"); +    }
+}
+
+void SubSurfaceInterface::Private::setSyncCallback(wl_client *client, wl_resource \
*resource) +{
+    Q_UNUSED(client)
+    cast(resource)->setMode(Mode::Synchronized);
+}
+
+void SubSurfaceInterface::Private::setDeSyncCallback(wl_client *client, wl_resource \
*resource) +{
+    Q_UNUSED(client)
+    cast(resource)->setMode(Mode::Desynchronized);
+}
+
+void SubSurfaceInterface::Private::setMode(Mode m)
+{
+    if (mode == m) {
+        return;
+    }
+    mode = m;
+    emit q->modeChanged(m);
+}
+
+SubSurfaceInterface::SubSurfaceInterface(SubCompositorInterface *parent)
+    : QObject(/*parent*/)
+    , d(new Private(this))
+{
+    Q_UNUSED(parent)
+}
+
+SubSurfaceInterface::~SubSurfaceInterface() = default;
+
+QPoint SubSurfaceInterface::position() const
+{
+    return d->pos;
+}
+
+wl_resource *SubSurfaceInterface::subSurface()
+{
+    return d->subSurface;
+}
+
+QPointer<SurfaceInterface> SubSurfaceInterface::surface()
+{
+    return d->surface;
+}
+
+QPointer<SurfaceInterface> SubSurfaceInterface::parentSurface()
+{
+    return d->parent;
+}
+
+SubSurfaceInterface::Mode SubSurfaceInterface::mode() const
+{
+    return d->mode;
+}
+
+}
+}
diff --git a/src/server/subcompositor_interface.h \
b/src/server/subcompositor_interface.h new file mode 100644
index 0000000..7ff142c
--- /dev/null
+++ b/src/server/subcompositor_interface.h
@@ -0,0 +1,97 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#ifndef WAYLAND_SERVER_SUBCOMPOSITOR_INTERFACE_H
+#define WAYLAND_SERVER_SUBCOMPOSITOR_INTERFACE_H
+
+#include <QObject>
+#include <QPointer>
+
+#include <KWayland/Server/kwaylandserver_export.h>
+
+struct wl_resource;
+
+namespace KWayland
+{
+namespace Server
+{
+
+class Display;
+class SurfaceInterface;
+class SubSurfaceInterface;
+
+class KWAYLANDSERVER_EXPORT SubCompositorInterface : public QObject
+{
+    Q_OBJECT
+public:
+    virtual ~SubCompositorInterface();
+
+    void create();
+    void destroy();
+    bool isValid() const;
+
+Q_SIGNALS:
+    void subSurfaceCreated(KWayland::Server::SubSurfaceInterface*);
+
+private:
+    explicit SubCompositorInterface(Display *display, QObject *parent = nullptr);
+    friend class Display;
+    class Private;
+    QScopedPointer<Private> d;
+};
+
+class KWAYLANDSERVER_EXPORT SubSurfaceInterface : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(QPoint position READ position NOTIFY positionChanged)
+    Q_PROPERTY(KWayland::Server::SubSurfaceInterface::Mode mode READ mode NOTIFY \
modeChanged) +public:
+    virtual ~SubSurfaceInterface();
+
+    QPoint position() const;
+
+    enum class Mode {
+        Synchronized,
+        Desynchronized
+    };
+    Mode mode() const;
+
+    wl_resource *subSurface();
+    QPointer<SurfaceInterface> surface();
+    QPointer<SurfaceInterface> parentSurface();
+
+Q_SIGNALS:
+    void positionChanged(const QPoint&);
+    void modeChanged(KWayland::Server::SubSurfaceInterface::Mode);
+
+private:
+    friend class SubCompositorInterface;
+    friend class SurfaceInterface;
+    explicit SubSurfaceInterface(SubCompositorInterface *parent);
+
+    class Private;
+    QScopedPointer<Private> d;
+};
+
+}
+}
+
+Q_DECLARE_METATYPE(KWayland::Server::SubSurfaceInterface::Mode)
+
+#endif
diff --git a/src/server/subsurface_interface_p.h \
b/src/server/subsurface_interface_p.h new file mode 100644
index 0000000..82bf573
--- /dev/null
+++ b/src/server/subsurface_interface_p.h
@@ -0,0 +1,75 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#ifndef WAYLAND_SERVER_SUBSURFACE_INTERFACE_P_H
+#define WAYLAND_SERVER_SUBSURFACE_INTERFACE_P_H
+
+#include "subcompositor_interface.h"
+// Qt
+#include <QPoint>
+// Wayland
+#include <wayland-server.h>
+
+namespace KWayland
+{
+namespace Server
+{
+
+class SubSurfaceInterface::Private
+{
+public:
+    Private(SubSurfaceInterface *q);
+    ~Private();
+
+    void create(wl_client *client, quint32 version, quint32 id, SurfaceInterface \
*surface, SurfaceInterface *parent); +    void commit();
+
+    QPoint pos = QPoint(0, 0);
+    QPoint scheduledPos = QPoint();
+    bool scheduledPosChange = false;
+    Mode mode = Mode::Synchronized;
+    wl_resource *subSurface = nullptr;
+    QPointer<SurfaceInterface> surface;
+    QPointer<SurfaceInterface> parent;
+
+private:
+    void setMode(Mode mode);
+    void setPosition(const QPoint &pos);
+    void placeAbove(SurfaceInterface *sibling);
+    void placeBelow(SurfaceInterface *sibling);
+
+    static void unbind(wl_resource *r);
+    static void destroyCallback(wl_client *client, wl_resource *resource);
+    static void setPositionCallback(wl_client *client, wl_resource *resource, \
int32_t x, int32_t y); +    static void placeAboveCallback(wl_client *client, \
wl_resource *resource, wl_resource *sibling); +    static void \
placeBelowCallback(wl_client *client, wl_resource *resource, wl_resource *sibling); + \
static void setSyncCallback(wl_client *client, wl_resource *resource); +    static \
void setDeSyncCallback(wl_client *client, wl_resource *resource); +
+    static Private *cast(wl_resource *r);
+
+    SubSurfaceInterface *q;
+
+    static const struct wl_subsurface_interface s_interface;
+};
+
+}
+}
+
+#endif
diff --git a/src/server/surface_interface.cpp b/src/server/surface_interface.cpp
index a983f4d..79a74e1 100644
--- a/src/server/surface_interface.cpp
+++ b/src/server/surface_interface.cpp
@@ -18,75 +18,21 @@ You should have received a copy of the GNU Lesser General Public
 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *********************************************************************/
 #include "surface_interface.h"
+#include "surface_interface_p.h"
 #include "buffer_interface.h"
 #include "compositor_interface.h"
+#include "subcompositor_interface.h"
+#include "subsurface_interface_p.h"
 // Wayland
 #include <wayland-server.h>
+// std
+#include <algorithm>
 
 namespace KWayland
 {
 namespace Server
 {
 
-class SurfaceInterface::Private
-{
-public:
-    struct State {
-        QRegion damage = QRegion();
-        QRegion opaque = QRegion();
-        QRegion input = QRegion();
-        qint32 scale = 1;
-        OutputInterface::Transform transform = OutputInterface::Transform::Normal;
-        QList<wl_resource*> callbacks = QList<wl_resource*>();
-        QPoint offset = QPoint();
-        BufferInterface *buffer = nullptr;
-    };
-    Private(SurfaceInterface *q, CompositorInterface *c);
-    ~Private();
-
-    void create(wl_client *client, quint32 version, quint32 id);
-    void destroy();
-
-    static SurfaceInterface *get(wl_resource *native);
-
-    CompositorInterface *compositor;
-    wl_resource *surface = nullptr;
-    wl_client *client = nullptr;
-    State current;
-    State pending;
-
-private:
-    void commit();
-    void damage(const QRect &rect);
-    void setScale(qint32 scale);
-    void setTransform(OutputInterface::Transform transform);
-    void addFrameCallback(uint32_t callback);
-    void attachBuffer(wl_resource *buffer, const QPoint &offset);
-
-    static Private *cast(wl_resource *r) {
-        return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
-    }
-
-    static void unbind(wl_resource *r);
-    static void destroyFrameCallback(wl_resource *r);
-
-    static void destroyCallback(wl_client *client, wl_resource *resource);
-    static void attachCallback(wl_client *client, wl_resource *resource, wl_resource \
                *buffer, int32_t sx, int32_t sy);
-    static void damageCallback(wl_client *client, wl_resource *resource, int32_t x, \
                int32_t y, int32_t width, int32_t height);
-    static void frameCallaback(wl_client *client, wl_resource *resource, uint32_t \
                callback);
-    static void opaqueRegionCallback(wl_client *client, wl_resource *resource, \
                wl_resource *region);
-    static void inputRegionCallback(wl_client *client, wl_resource *resource, \
                wl_resource *region);
-    static void commitCallback(wl_client *client, wl_resource *resource);
-    // since version 2
-    static void bufferTransformCallback(wl_client *client, wl_resource *resource, \
                int32_t transform);
-    // since version 3
-    static void bufferScaleCallback(wl_client *client, wl_resource *resource, \
                int32_t scale);
-
-    SurfaceInterface *q;
-    static const struct wl_surface_interface s_interface;
-    static QList<SurfaceInterface::Private*> s_allSurfaces;
-};
-
 QList<SurfaceInterface::Private*> SurfaceInterface::Private::s_allSurfaces;
 
 SurfaceInterface::Private::Private(SurfaceInterface *q, CompositorInterface *c)
@@ -102,6 +48,88 @@ SurfaceInterface::Private::~Private()
     s_allSurfaces.removeAll(this);
 }
 
+SurfaceInterface::Private *SurfaceInterface::Private::cast(wl_resource *r)
+{
+    return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
+}
+
+void SurfaceInterface::Private::addChild(QPointer< SubSurfaceInterface > subSurface)
+{
+    pending.children.append(subSurface);
+}
+
+void SurfaceInterface::Private::removeChild(QPointer< SubSurfaceInterface > \
subSurface) +{
+    pending.children.removeAll(subSurface);
+}
+
+bool SurfaceInterface::Private::raiseChild(QPointer<SubSurfaceInterface> subsurface, \
SurfaceInterface *sibling) +{
+    auto it = std::find(pending.children.begin(), pending.children.end(), \
subsurface); +    if (it == pending.children.end()) {
+        return false;
+    }
+    if (pending.children.count() == 1) {
+        // nothing to do
+        return true;
+    }
+    if (sibling == q) {
+        // it's to the parent, so needs to become last item
+        pending.children.append(*it);
+        pending.children.erase(it);
+        return true;
+    }
+    if (!sibling->subSurface()) {
+        // not a sub surface
+        return false;
+    }
+    auto siblingIt = std::find(pending.children.begin(), pending.children.end(), \
sibling->subSurface()); +    if (siblingIt == pending.children.end() || siblingIt == \
it) { +        // not a sibling
+        return false;
+    }
+    auto value = (*it);
+    pending.children.erase(it);
+    // find the iterator again
+    siblingIt = std::find(pending.children.begin(), pending.children.end(), \
sibling->subSurface()); +    pending.children.insert(++siblingIt, value);
+    return true;
+}
+
+bool SurfaceInterface::Private::lowerChild(QPointer<SubSurfaceInterface> subsurface, \
SurfaceInterface *sibling) +{
+    auto it = std::find(pending.children.begin(), pending.children.end(), \
subsurface); +    if (it == pending.children.end()) {
+        return false;
+    }
+    if (pending.children.count() == 1) {
+        // nothing to do
+        return true;
+    }
+    if (sibling == q) {
+        // it's to the parent, so needs to become first item
+        auto value = *it;
+        pending.children.erase(it);
+        pending.children.prepend(value);
+        return true;
+    }
+    if (!sibling->subSurface()) {
+        // not a sub surface
+        return false;
+    }
+    auto siblingIt = std::find(pending.children.begin(), pending.children.end(), \
sibling->subSurface()); +    if (siblingIt == pending.children.end() || siblingIt == \
it) { +        // not a sibling
+        return false;
+    }
+    auto value = (*it);
+    pending.children.erase(it);
+    // find the iterator again
+    siblingIt = std::find(pending.children.begin(), pending.children.end(), \
sibling->subSurface()); +    pending.children.insert(siblingIt, value);
+    return true;
+}
+
 SurfaceInterface *SurfaceInterface::Private::get(wl_resource *native)
 {
     auto it = std::find_if(s_allSurfaces.constBegin(), s_allSurfaces.constEnd(), \
[native](Private *s) { @@ -202,6 +230,14 @@ void SurfaceInterface::Private::commit()
     // copy values
     current = pending;
     pending = State{};
+    pending.children = current.children;
+    // commit all subSurfaces to apply position changes
+    for (auto it = current.children.constBegin(); it != current.children.constEnd(); \
++it) { +        if (!(*it)) {
+            continue;
+        }
+        (*it)->d->commit();
+    }
     if (opaqueRegionChanged) {
         emit q->opaqueChanged(current.opaque);
     }
@@ -371,5 +407,15 @@ SurfaceInterface *SurfaceInterface::get(wl_resource *native)
     return Private::get(native);
 }
 
+QList< QPointer< SubSurfaceInterface > > SurfaceInterface::childSubSurfaces() const
+{
+    return d->current.children;
+}
+
+QPointer< SubSurfaceInterface > SurfaceInterface::subSurface() const
+{
+    return d->subSurface;
+}
+
 }
 }
diff --git a/src/server/surface_interface.h b/src/server/surface_interface.h
index c98cc93..92f0629 100644
--- a/src/server/surface_interface.h
+++ b/src/server/surface_interface.h
@@ -23,6 +23,7 @@ License along with this library.  If not, see \
<http://www.gnu.org/licenses/>.  #include "output_interface.h"
 
 #include <QObject>
+#include <QPointer>
 #include <QRegion>
 
 #include <KWayland/Server/kwaylandserver_export.h>
@@ -33,6 +34,7 @@ namespace Server
 {
 class BufferInterface;
 class CompositorInterface;
+class SubSurfaceInterface;
 
 class KWAYLANDSERVER_EXPORT SurfaceInterface : public QObject
 {
@@ -60,6 +62,15 @@ public:
     BufferInterface *buffer();
     QPoint offset() const;
 
+    /**
+     * @returns The SubSurface for this Surface in case there is one.
+     **/
+    QPointer<SubSurfaceInterface> subSurface() const;
+    /**
+     * @returns Children in stacking order from bottom (first) to top (last).
+     **/
+    QList<QPointer<SubSurfaceInterface>> childSubSurfaces() const;
+
     static SurfaceInterface *get(wl_resource *native);
 
 Q_SIGNALS:
@@ -71,6 +82,7 @@ Q_SIGNALS:
 
 private:
     friend class CompositorInterface;
+    friend class SubSurfaceInterface;
     explicit SurfaceInterface(CompositorInterface *parent);
 
     class Private;
diff --git a/src/server/surface_interface_p.h b/src/server/surface_interface_p.h
new file mode 100644
index 0000000..530cd17
--- /dev/null
+++ b/src/server/surface_interface_p.h
@@ -0,0 +1,100 @@
+/********************************************************************
+Copyright 2014  Martin Gräßlin <mgraesslin@kde.org>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) version 3, or any
+later version accepted by the membership of KDE e.V. (or its
+successor approved by the membership of KDE e.V.), which shall
+act as a proxy defined in Section 6 of version 3 of the license.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#ifndef WAYLAND_SERVER_SURFACE_INTERFACE_P_H
+#define WAYLAND_SERVER_SURFACE_INTERFACE_P_H
+
+#include "surface_interface.h"
+// Wayland
+#include <wayland-server.h>
+
+namespace KWayland
+{
+namespace Server
+{
+
+class SurfaceInterface::Private
+{
+public:
+    struct State {
+        QRegion damage = QRegion();
+        QRegion opaque = QRegion();
+        QRegion input = QRegion();
+        qint32 scale = 1;
+        OutputInterface::Transform transform = OutputInterface::Transform::Normal;
+        QList<wl_resource*> callbacks = QList<wl_resource*>();
+        QPoint offset = QPoint();
+        BufferInterface *buffer = nullptr;
+        // stacking order: bottom (first) -> top (last)
+        QList<QPointer<SubSurfaceInterface>> children;
+    };
+    Private(SurfaceInterface *q, CompositorInterface *c);
+    ~Private();
+
+    void create(wl_client *client, quint32 version, quint32 id);
+    void destroy();
+
+    void addChild(QPointer<SubSurfaceInterface> subsurface);
+    void removeChild(QPointer<SubSurfaceInterface> subsurface);
+    bool raiseChild(QPointer<SubSurfaceInterface> subsurface, SurfaceInterface \
*sibling); +    bool lowerChild(QPointer<SubSurfaceInterface> subsurface, \
SurfaceInterface *sibling); +
+    static SurfaceInterface *get(wl_resource *native);
+
+    CompositorInterface *compositor;
+    wl_resource *surface = nullptr;
+    wl_client *client = nullptr;
+    State current;
+    State pending;
+    QPointer<SubSurfaceInterface> subSurface;
+
+private:
+    void commit();
+    void damage(const QRect &rect);
+    void setScale(qint32 scale);
+    void setTransform(OutputInterface::Transform transform);
+    void addFrameCallback(uint32_t callback);
+    void attachBuffer(wl_resource *buffer, const QPoint &offset);
+
+    static Private *cast(wl_resource *r);
+
+    static void unbind(wl_resource *r);
+    static void destroyFrameCallback(wl_resource *r);
+
+    static void destroyCallback(wl_client *client, wl_resource *resource);
+    static void attachCallback(wl_client *client, wl_resource *resource, wl_resource \
*buffer, int32_t sx, int32_t sy); +    static void damageCallback(wl_client *client, \
wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height); +    \
static void frameCallaback(wl_client *client, wl_resource *resource, uint32_t \
callback); +    static void opaqueRegionCallback(wl_client *client, wl_resource \
*resource, wl_resource *region); +    static void inputRegionCallback(wl_client \
*client, wl_resource *resource, wl_resource *region); +    static void \
commitCallback(wl_client *client, wl_resource *resource); +    // since version 2
+    static void bufferTransformCallback(wl_client *client, wl_resource *resource, \
int32_t transform); +    // since version 3
+    static void bufferScaleCallback(wl_client *client, wl_resource *resource, \
int32_t scale); +
+    SurfaceInterface *q;
+    static const struct wl_surface_interface s_interface;
+    static QList<SurfaceInterface::Private*> s_allSurfaces;
+};
+
+}
+}
+
+#endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic