diff --git a/src/client/client.pro b/src/client/client.pro
index 59234b14e74efeaf4bb7d217c8ae05437d6f5a05..d2d12d9fd0eddd803a29a71d5ffb0dbc4a9f2d47 100644
--- a/src/client/client.pro
+++ b/src/client/client.pro
@@ -59,8 +59,10 @@ SOURCES +=  qwaylandintegration.cpp \
             qwaylanddatasource.cpp \
             qwaylandshellsurface.cpp \
             qwaylandwlshellsurface.cpp \
+            qwaylandwlshellintegration.cpp \
             qwaylandxdgshell.cpp \
             qwaylandxdgsurface.cpp \
+            qwaylandxdgshellintegration.cpp \
             qwaylandextendedsurface.cpp \
             qwaylandsubsurface.cpp \
             qwaylandtouch.cpp \
@@ -92,8 +94,10 @@ HEADERS +=  qwaylandintegration_p.h \
             qwaylanddatasource_p.h \
             qwaylandshellsurface_p.h \
             qwaylandwlshellsurface_p.h \
+            qwaylandwlshellintegration_p.h \
             qwaylandxdgshell_p.h \
             qwaylandxdgsurface_p.h \
+            qwaylandxdgshellintegration_p.h \
             qwaylandextendedsurface_p.h \
             qwaylandsubsurface_p.h \
             qwaylandtouch_p.h \
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
index 682172bf8bf374e149f4c54a793d5ca821b31ee6..7225d24af9d752d83c74462421f7b61ef2638b46 100644
--- a/src/client/qwaylanddisplay.cpp
+++ b/src/client/qwaylanddisplay.cpp
@@ -77,16 +77,8 @@ struct wl_surface *QWaylandDisplay::createSurface(void *handle)
 
 QWaylandShellSurface *QWaylandDisplay::createShellSurface(QWaylandWindow *window)
 {
-    if (mWaylandIntegration->shellIntegration())
-        return mWaylandIntegration->shellIntegration()->createShellSurface(window);
-
-    if (shellXdg()) {
-        return new QWaylandXdgSurface(shellXdg()->get_xdg_surface(window->object()), window);
-    } else if (shell()) {
-        return new QWaylandWlShellSurface(shell()->get_shell_surface(window->object()), window);
-    }
-
-    return Q_NULLPTR;
+    Q_ASSERT(mWaylandIntegration->shellIntegration());
+    return mWaylandIntegration->shellIntegration()->createShellSurface(window);
 }
 
 struct ::wl_region *QWaylandDisplay::createRegion(const QRegion &qregion)
@@ -248,11 +240,6 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
         mCompositor.init(registry, id, mCompositorVersion);
     } else if (interface == QStringLiteral("wl_shm")) {
         mShm = static_cast<struct wl_shm *>(wl_registry_bind(registry, id, &wl_shm_interface,1));
-    } else if (interface == QStringLiteral("xdg_shell")
-               && qEnvironmentVariableIsSet("QT_WAYLAND_USE_XDG_SHELL")) {
-        mShellXdg.reset(new QWaylandXdgShell(registry,id));
-    } else if (interface == QStringLiteral("wl_shell")){
-        mShell.reset(new QtWayland::wl_shell(registry, id, 1));
     } else if (interface == QStringLiteral("wl_seat")) {
         QWaylandInputDevice *inputDevice = mWaylandIntegration->createInputDevice(this, version, id);
         mInputDevices.append(inputDevice);
@@ -301,6 +288,15 @@ void QWaylandDisplay::registry_global_remove(uint32_t id)
     }
 }
 
+bool QWaylandDisplay::hasRegistryGlobal(const QString &interfaceName)
+{
+    Q_FOREACH (const RegistryGlobal &global, mGlobals)
+        if (global.interface == interfaceName)
+            return true;
+
+    return false;
+}
+
 void QWaylandDisplay::addRegistryListener(RegistryListener listener, void *data)
 {
     Listener l = { listener, data };
@@ -356,11 +352,6 @@ void QWaylandDisplay::forceRoundTrip()
         wl_callback_destroy(callback);
 }
 
-QtWayland::xdg_shell *QWaylandDisplay::shellXdg()
-{
-    return mShellXdg.data();
-}
-
 bool QWaylandDisplay::supportsWindowDecoration() const
 {
     static bool disabled = qgetenv("QT_WAYLAND_DISABLE_WINDOWDECORATION").toInt();
diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h
index 3f5538ec22eaca0909b4b87501a2dbda41423288..ea127d2f4f06a8f7fce6fa7a716fda7f7c194687 100644
--- a/src/client/qwaylanddisplay_p.h
+++ b/src/client/qwaylanddisplay_p.h
@@ -128,9 +128,6 @@ public:
     QtWayland::wl_compositor *compositor() { return &mCompositor; }
     int compositorVersion() const { return mCompositorVersion; }
 
-    QtWayland::wl_shell *shell() { return mShell.data(); }
-    QtWayland::xdg_shell *shellXdg();
-
     QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
     QWaylandInputDevice *defaultInputDevice() const;
     QWaylandInputDevice *currentInputDevice() const { return defaultInputDevice(); }
@@ -151,6 +148,7 @@ public:
             : id(id_), interface(interface_), version(version_), registry(registry_) { }
     };
     QList<RegistryGlobal> globals() const { return mGlobals; }
+    bool hasRegistryGlobal(const QString &interfaceName);
 
     /* wl_registry_add_listener does not add but rather sets a listener, so this function is used
      * to enable many listeners at once. */
@@ -193,8 +191,6 @@ private:
     struct wl_display *mDisplay;
     QtWayland::wl_compositor mCompositor;
     struct wl_shm *mShm;
-    QScopedPointer<QtWayland::wl_shell> mShell;
-    QScopedPointer<QWaylandXdgShell> mShellXdg;
     QList<QWaylandScreen *> mScreens;
     QList<QWaylandInputDevice *> mInputDevices;
     QList<Listener> mRegistryListeners;
diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp
index 39fff533d32b4c0c6543654b21202d47cf432d63..e62ef87f1984adf5cc2cad95b3e8d9d15d6cf5c7 100644
--- a/src/client/qwaylandintegration.cpp
+++ b/src/client/qwaylandintegration.cpp
@@ -69,6 +69,8 @@
 
 #include "qwaylandshellintegration_p.h"
 #include "qwaylandshellintegrationfactory_p.h"
+#include "qwaylandxdgshellintegration_p.h"
+#include "qwaylandwlshellintegration_p.h"
 
 #include "qwaylandinputdeviceintegration_p.h"
 #include "qwaylandinputdeviceintegrationfactory_p.h"
@@ -360,17 +362,29 @@ void QWaylandIntegration::initializeShellIntegration()
     QByteArray integrationName = qgetenv("QT_WAYLAND_SHELL_INTEGRATION");
     QString targetKey = QString::fromLocal8Bit(integrationName);
 
-    if (targetKey.isEmpty()) {
-        return;
+    if (!targetKey.isEmpty()) {
+        QStringList keys = QWaylandShellIntegrationFactory::keys();
+        if (keys.contains(targetKey)) {
+            qDebug("Using the '%s' shell integration", qPrintable(targetKey));
+            mShellIntegration = QWaylandShellIntegrationFactory::create(targetKey, QStringList());
+        }
+    } else {
+        QStringList preferredShells;
+        if (qEnvironmentVariableIsSet("QT_WAYLAND_USE_XDG_SHELL"))
+            preferredShells << QLatin1String("xdg_shell");
+        preferredShells << QLatin1String("wl_shell");
+
+        Q_FOREACH (QString preferredShell, preferredShells) {
+            if (mDisplay->hasRegistryGlobal(preferredShell)) {
+                mShellIntegration = createShellIntegration(preferredShell);
+                break;
+            }
+        }
     }
 
-    QStringList keys = QWaylandShellIntegrationFactory::keys();
-    if (keys.contains(targetKey)) {
-        mShellIntegration = QWaylandShellIntegrationFactory::create(targetKey, QStringList());
-    }
-    if (mShellIntegration && mShellIntegration->initialize(mDisplay)) {
-        qDebug("Using the '%s' shell integration", qPrintable(targetKey));
-    } else {
+    Q_ASSERT(mShellIntegration);
+
+    if (!mShellIntegration->initialize(mDisplay)) {
         delete mShellIntegration;
         mShellIntegration = Q_NULLPTR;
         qWarning("Failed to load shell integration %s", qPrintable(targetKey));
@@ -403,6 +417,17 @@ void QWaylandIntegration::initializeInputDeviceIntegration()
     }
 }
 
+QWaylandShellIntegration *QWaylandIntegration::createShellIntegration(const QString &interfaceName)
+{
+    if (interfaceName == QLatin1Literal("wl_shell")) {
+        return new QWaylandWlShellIntegration(mDisplay);
+    } else if (interfaceName == QLatin1Literal("xdg_shell")) {
+        return new QWaylandXdgShellIntegration(mDisplay);
+    } else {
+        return Q_NULLPTR;
+    }
+}
+
 }
 
 QT_END_NAMESPACE
diff --git a/src/client/qwaylandintegration_p.h b/src/client/qwaylandintegration_p.h
index 987d80599f8a6727e2aec12decbe7cb6afe911a9..671f7de2884f30e2d790ef8055424426fea7db72 100644
--- a/src/client/qwaylandintegration_p.h
+++ b/src/client/qwaylandintegration_p.h
@@ -115,6 +115,7 @@ private:
     void initializeServerBufferIntegration();
     void initializeShellIntegration();
     void initializeInputDeviceIntegration();
+    QWaylandShellIntegration *createShellIntegration(const QString& interfaceName);
 
     QPlatformFontDatabase *mFontDb;
     QPlatformClipboard *mClipboard;
diff --git a/src/client/qwaylandwlshellintegration.cpp b/src/client/qwaylandwlshellintegration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6a9220d264843332aef82a7b42f5a4728b649bcd
--- /dev/null
+++ b/src/client/qwaylandwlshellintegration.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwaylandwlshellintegration_p.h"
+
+#include <QtWaylandClient/private/qwaylandwindow_p.h>
+#include <QtWaylandClient/private/qwaylanddisplay_p.h>
+#include <QtWaylandClient/private/qwaylandwlshellsurface_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtWaylandClient {
+
+QWaylandWlShellIntegration::QWaylandWlShellIntegration(QWaylandDisplay *display)
+    : m_wlShell(Q_NULLPTR)
+{
+    Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) {
+        if (global.interface == QLatin1String("wl_shell")) {
+            m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1);
+            break;
+        }
+    }
+}
+
+QWaylandShellSurface *QWaylandWlShellIntegration::createShellSurface(QWaylandWindow *window)
+{
+    return new QWaylandWlShellSurface(m_wlShell->get_shell_surface(window->object()), window);
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/client/qwaylandwlshellintegration_p.h b/src/client/qwaylandwlshellintegration_p.h
new file mode 100644
index 0000000000000000000000000000000000000000..8531eb3aad18231023496b692d329191e57bffe0
--- /dev/null
+++ b/src/client/qwaylandwlshellintegration_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWAYLANDWLSHELLINTEGRATION_P_H
+#define QWAYLANDWLSHELLINTEGRATION_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <wayland-client.h>
+#include <private/qwayland-wayland.h>
+
+#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtWaylandClient {
+
+class Q_WAYLAND_CLIENT_EXPORT QWaylandWlShellIntegration : public QWaylandShellIntegration
+{
+public:
+    QWaylandWlShellIntegration(QWaylandDisplay* display);
+    bool initialize(QWaylandDisplay *) Q_DECL_OVERRIDE { return m_wlShell != Q_NULLPTR; }
+    QWaylandShellSurface *createShellSurface(QWaylandWindow *window) Q_DECL_OVERRIDE;
+
+private:
+    QtWayland::wl_shell *m_wlShell;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif // QWAYLANDWLSHELLINTEGRATION_P_H
diff --git a/src/client/qwaylandxdgshell.cpp b/src/client/qwaylandxdgshell.cpp
index 65fafcead774fda0f7277e3502334e03c728e03b..9b351da6a6b28cb80fece0cb864719fd71657534 100644
--- a/src/client/qwaylandxdgshell.cpp
+++ b/src/client/qwaylandxdgshell.cpp
@@ -37,6 +37,7 @@
 #include "qwaylandwindow_p.h"
 #include "qwaylandinputdevice_p.h"
 #include "qwaylandscreen_p.h"
+#include "qwaylandxdgsurface_p.h"
 
 #include <QtCore/QDebug>
 
@@ -60,6 +61,10 @@ QWaylandXdgShell::~QWaylandXdgShell()
     xdg_shell_destroy(object());
 }
 
+QWaylandXdgSurface *QWaylandXdgShell::createXdgSurface(QWaylandWindow *window)
+{
+    return new QWaylandXdgSurface(this, window);
+}
 
 void QWaylandXdgShell::xdg_shell_ping(uint32_t serial)
 {
diff --git a/src/client/qwaylandxdgshell_p.h b/src/client/qwaylandxdgshell_p.h
index 3fd248fc462621378c22aa793d5ae12b7eb3610e..cd16564150edd2991bac78ee45729e794ed44e4a 100644
--- a/src/client/qwaylandxdgshell_p.h
+++ b/src/client/qwaylandxdgshell_p.h
@@ -61,15 +61,17 @@ namespace QtWaylandClient {
 
 class QWaylandWindow;
 class QWaylandInputDevice;
+class QWaylandXdgSurface;
 
 class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShell : public QtWayland::xdg_shell
 {
 public:
     QWaylandXdgShell(struct ::xdg_shell *shell);
     QWaylandXdgShell(struct ::wl_registry *registry, uint32_t id);
-
     virtual ~QWaylandXdgShell();
 
+    QWaylandXdgSurface *createXdgSurface(QWaylandWindow *window);
+
 private:
     void xdg_shell_ping(uint32_t serial) Q_DECL_OVERRIDE;
 };
diff --git a/src/client/qwaylandxdgshellintegration.cpp b/src/client/qwaylandxdgshellintegration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5a569129feac8c019a18051b3e6deb27dc4d15c1
--- /dev/null
+++ b/src/client/qwaylandxdgshellintegration.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwaylandxdgshellintegration_p.h"
+
+#include <QtWaylandClient/private/qwaylandwindow_p.h>
+#include <QtWaylandClient/private/qwaylanddisplay_p.h>
+#include <QtWaylandClient/private/qwaylandxdgsurface_p.h>
+#include <QtWaylandClient/private/qwaylandxdgshell_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtWaylandClient {
+
+QWaylandXdgShellIntegration::QWaylandXdgShellIntegration(QWaylandDisplay *display)
+    : m_xdgShell(Q_NULLPTR)
+{
+    Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) {
+        if (global.interface == QLatin1String("xdg_shell")) {
+            m_xdgShell = new QWaylandXdgShell(display->wl_registry(), global.id);
+            break;
+        }
+    }
+}
+
+QWaylandShellSurface *QWaylandXdgShellIntegration::createShellSurface(QWaylandWindow *window)
+{
+    return m_xdgShell->createXdgSurface(window);
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/client/qwaylandxdgshellintegration_p.h b/src/client/qwaylandxdgshellintegration_p.h
new file mode 100644
index 0000000000000000000000000000000000000000..29374ff1d6dc42a16f2862b06ba5c782d24db753
--- /dev/null
+++ b/src/client/qwaylandxdgshellintegration_p.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWAYLANDXDGSHELLINTEGRATION_P_H
+#define QWAYLANDXDGSHELLINTEGRATION_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <wayland-client.h>
+
+#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtWaylandClient {
+
+class QWaylandXdgShell;
+
+class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShellIntegration : public QWaylandShellIntegration
+{
+public:
+    QWaylandXdgShellIntegration(QWaylandDisplay *display);
+    bool initialize(QWaylandDisplay *) Q_DECL_OVERRIDE { return m_xdgShell != Q_NULLPTR; }
+    QWaylandShellSurface *createShellSurface(QWaylandWindow *window) Q_DECL_OVERRIDE;
+
+private:
+    QWaylandXdgShell *m_xdgShell;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif // QWAYLANDXDGSHELLINTEGRATION_P_H
diff --git a/src/client/qwaylandxdgsurface.cpp b/src/client/qwaylandxdgsurface.cpp
index bbda03dc3cc2622fd4d20e3d340bc93a8b7ebbf4..f44e2d9feca9a0f6b9fc19b620e0e70fa38ca53e 100644
--- a/src/client/qwaylandxdgsurface.cpp
+++ b/src/client/qwaylandxdgsurface.cpp
@@ -39,16 +39,18 @@
 #include "qwaylandabstractdecoration_p.h"
 #include "qwaylandscreen_p.h"
 #include "qwaylandextendedsurface_p.h"
+#include "qwaylandxdgshell_p.h"
 
 
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
 
-QWaylandXdgSurface::QWaylandXdgSurface(struct ::xdg_surface *xdg_surface, QWaylandWindow *window)
+QWaylandXdgSurface::QWaylandXdgSurface(QWaylandXdgShell *shell, QWaylandWindow *window)
     : QWaylandShellSurface(window)
-    , QtWayland::xdg_surface(xdg_surface)
+    , QtWayland::xdg_surface(shell->get_xdg_surface(window->object()))
     , m_window(window)
+    , m_shell(shell)
     , m_maximized(false)
     , m_minimized(false)
     , m_fullscreen(false)
@@ -130,8 +132,7 @@ void QWaylandXdgSurface::updateTransientParent(QWindow *parent)
     QWaylandWindow *parent_wayland_window = static_cast<QWaylandWindow *>(parent->handle());
     if (!parent_wayland_window)
         return;
-    QtWayland::xdg_shell *shell = parent_wayland_window->display()->shellXdg();
-    set_parent(shell->get_xdg_surface(parent_wayland_window->object()));
+    set_parent(m_shell->get_xdg_surface(parent_wayland_window->object()));
 }
 
 void QWaylandXdgSurface::setTitle(const QString & title)
diff --git a/src/client/qwaylandxdgsurface_p.h b/src/client/qwaylandxdgsurface_p.h
index bc72820a144552e1e92baa84a236815e47c6cc7b..51c658ea43f6705f62f149a90c28ee35f4e7c5a1 100644
--- a/src/client/qwaylandxdgsurface_p.h
+++ b/src/client/qwaylandxdgsurface_p.h
@@ -63,13 +63,14 @@ namespace QtWaylandClient {
 class QWaylandWindow;
 class QWaylandInputDevice;
 class QWaylandExtendedSurface;
+class QWaylandXdgShell;
 
 class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgSurface : public QWaylandShellSurface
         , public QtWayland::xdg_surface
 {
     Q_OBJECT
 public:
-    QWaylandXdgSurface(struct ::xdg_surface *shell_surface, QWaylandWindow *window);
+    QWaylandXdgSurface(QWaylandXdgShell *shell, QWaylandWindow *window);
     virtual ~QWaylandXdgSurface();
 
     using QtWayland::xdg_surface::resize;
@@ -105,6 +106,7 @@ private:
 
 private:
     QWaylandWindow *m_window;
+    QWaylandXdgShell* m_shell;
     bool m_maximized;
     bool m_minimized;
     bool m_fullscreen;