From 18eedea179ef4636f114b38832330cb424090f73 Mon Sep 17 00:00:00 2001
From: Paul Olav Tvete <paul.tvete@qt.io>
Date: Wed, 2 Nov 2016 14:24:52 +0100
Subject: [PATCH] Fix build when some features are disabled

Make QtWaylandClient compile when Qt is configured with:

-no-opengl -no-accessibility -D QT_NO_CLIPBOARD -D QT_NO_DRAGANDDROP -D QT_NO_SESSIONMANAGER

Task-number: QTBUG-56192
Change-Id: Idc6aae6b36a35515109a27bed31a22e3e909ef27
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
---
 src/client/qwaylandclipboard.cpp         | 4 ++++
 src/client/qwaylandclipboard_p.h         | 3 +++
 src/client/qwaylanddatadevice.cpp        | 4 ++++
 src/client/qwaylanddatadevice_p.h        | 4 ++++
 src/client/qwaylanddatadevicemanager.cpp | 4 ++++
 src/client/qwaylanddatadevicemanager_p.h | 4 ++++
 src/client/qwaylanddataoffer.cpp         | 4 ++++
 src/client/qwaylanddataoffer_p.h         | 3 ++-
 src/client/qwaylanddatasource.cpp        | 4 ++++
 src/client/qwaylanddatasource_p.h        | 4 ++++
 src/client/qwaylanddisplay.cpp           | 6 ++++++
 src/client/qwaylanddisplay_p.h           | 6 ++++--
 src/client/qwaylanddnd.cpp               | 4 ++--
 src/client/qwaylanddnd_p.h               | 4 ++--
 src/client/qwaylandinputdevice.cpp       | 3 ++-
 src/client/qwaylandintegration.cpp       | 7 ++++++-
 src/client/qwaylandintegration_p.h       | 7 ++++---
 src/client/qwaylandnativeinterface.cpp   | 2 ++
 src/client/qwaylandnativeinterface_p.h   | 3 ++-
 src/client/qwaylandwindow.cpp            | 2 ++
 20 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/src/client/qwaylandclipboard.cpp b/src/client/qwaylandclipboard.cpp
index 5399e79d..c661c1b6 100644
--- a/src/client/qwaylandclipboard.cpp
+++ b/src/client/qwaylandclipboard.cpp
@@ -38,6 +38,8 @@
 #include "qwaylanddatasource_p.h"
 #include "qwaylanddatadevice_p.h"
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -109,3 +111,5 @@ bool QWaylandClipboard::ownsMode(QClipboard::Mode mode) const
 }
 
 QT_END_NAMESPACE
+
+#endif // QT_NO_DRAGANDDROP
diff --git a/src/client/qwaylandclipboard_p.h b/src/client/qwaylandclipboard_p.h
index e9344c5f..d3553574 100644
--- a/src/client/qwaylandclipboard_p.h
+++ b/src/client/qwaylandclipboard_p.h
@@ -51,6 +51,7 @@
 
 #include <QtWaylandClient/private/qwaylandclientexport_p.h>
 
+#ifndef QT_NO_DRAGANDDROP
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -78,4 +79,6 @@ private:
 
 QT_END_NAMESPACE
 
+#endif // QT_NO_DRAGANDDROP
+
 #endif // QWAYLANDCLIPBOARD_H
diff --git a/src/client/qwaylanddatadevice.cpp b/src/client/qwaylanddatadevice.cpp
index 255b13f4..10033126 100644
--- a/src/client/qwaylanddatadevice.cpp
+++ b/src/client/qwaylanddatadevice.cpp
@@ -55,6 +55,8 @@
 #include <qpa/qplatformdrag.h>
 #include <qpa/qwindowsysteminterface.h>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -254,3 +256,5 @@ void QWaylandDataDevice::dragSourceTargetChanged(const QString &mimeType)
 }
 
 QT_END_NAMESPACE
+
+#endif // QT_NO_DRAGANDDROP
diff --git a/src/client/qwaylanddatadevice_p.h b/src/client/qwaylanddatadevice_p.h
index b87529e9..04ff7b38 100644
--- a/src/client/qwaylanddatadevice_p.h
+++ b/src/client/qwaylanddatadevice_p.h
@@ -57,6 +57,8 @@
 
 #include <QtWaylandClient/private/qwayland-wayland.h>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 class QMimeData;
@@ -117,4 +119,6 @@ private:
 
 QT_END_NAMESPACE
 
+#endif // QT_NO_DRAGANDDROP
+
 #endif // QWAYLANDDATADEVICE_H
diff --git a/src/client/qwaylanddatadevicemanager.cpp b/src/client/qwaylanddatadevicemanager.cpp
index b5a98b09..b3053d3c 100644
--- a/src/client/qwaylanddatadevicemanager.cpp
+++ b/src/client/qwaylanddatadevicemanager.cpp
@@ -40,6 +40,8 @@
 
 #include <QtCore/QDebug>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -74,3 +76,5 @@ QWaylandDisplay *QWaylandDataDeviceManager::display() const
 }
 
 QT_END_NAMESPACE
+
+#endif // QT_NO_DRAGANDDROP
diff --git a/src/client/qwaylanddatadevicemanager_p.h b/src/client/qwaylanddatadevicemanager_p.h
index 85b4b3f7..63451d82 100644
--- a/src/client/qwaylanddatadevicemanager_p.h
+++ b/src/client/qwaylanddatadevicemanager_p.h
@@ -48,6 +48,8 @@
 #include <QtWaylandClient/private/qwaylandclientexport_p.h>
 #include <QtWaylandClient/private/qwayland-wayland.h>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -75,4 +77,6 @@ private:
 
 QT_END_NAMESPACE
 
+#endif // QT_NO_DRAGANDDROP
+
 #endif // QWAYLANDDATADEVICEMANAGER_H
diff --git a/src/client/qwaylanddataoffer.cpp b/src/client/qwaylanddataoffer.cpp
index 167b647d..4c4ac3d8 100644
--- a/src/client/qwaylanddataoffer.cpp
+++ b/src/client/qwaylanddataoffer.cpp
@@ -41,6 +41,8 @@
 
 #include <QtCore/QDebug>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -175,3 +177,5 @@ int QWaylandMimeData::readData(int fd, QByteArray &data) const
 }
 
 QT_END_NAMESPACE
+
+#endif // QT_NO_DRAGANDDROP
diff --git a/src/client/qwaylanddataoffer_p.h b/src/client/qwaylanddataoffer_p.h
index b22681f7..d30a5fba 100644
--- a/src/client/qwaylanddataoffer_p.h
+++ b/src/client/qwaylanddataoffer_p.h
@@ -50,6 +50,7 @@
 #include <QtWaylandClient/private/qwaylandclientexport_p.h>
 #include <QtWaylandClient/private/qwayland-wayland.h>
 
+#ifndef QT_NO_DRAGANDDROP
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -99,5 +100,5 @@ private:
 }
 
 QT_END_NAMESPACE
-
+#endif // QT_NO_DRAGANDDROP
 #endif
diff --git a/src/client/qwaylanddatasource.cpp b/src/client/qwaylanddatasource.cpp
index ad43b069..30b7e620 100644
--- a/src/client/qwaylanddatasource.cpp
+++ b/src/client/qwaylanddatasource.cpp
@@ -43,6 +43,8 @@
 
 #include <unistd.h>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 namespace QtWaylandClient {
@@ -90,3 +92,5 @@ void QWaylandDataSource::data_source_target(const QString &mime_type)
 }
 
 QT_END_NAMESPACE
+
+#endif // QT_NO_DRAGANDDROP
diff --git a/src/client/qwaylanddatasource_p.h b/src/client/qwaylanddatasource_p.h
index c753c4f6..72530d0b 100644
--- a/src/client/qwaylanddatasource_p.h
+++ b/src/client/qwaylanddatasource_p.h
@@ -50,6 +50,8 @@
 #include <QtWaylandClient/private/qwayland-wayland.h>
 #include <QtWaylandClient/private/qwaylandclientexport_p.h>
 
+#ifndef QT_NO_DRAGANDDROP
+
 QT_BEGIN_NAMESPACE
 
 class QMimeData;
@@ -86,4 +88,6 @@ private:
 
 QT_END_NAMESPACE
 
+#endif // QT_NO_DRAGANDDROP
+
 #endif // QWAYLANDDATASOURCE_H
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
index f9a556f4..534ae494 100644
--- a/src/client/qwaylanddisplay.cpp
+++ b/src/client/qwaylanddisplay.cpp
@@ -112,7 +112,9 @@ QWaylandWindowManagerIntegration *QWaylandDisplay::windowManagerIntegration() co
 
 QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration)
     : mWaylandIntegration(waylandIntegration)
+#ifndef QT_NO_DRAGANDDROP
     , mDndSelectionHandler(0)
+#endif
     , mWindowExtension(0)
     , mSubCompositor(0)
     , mTouchExtension(0)
@@ -150,7 +152,9 @@ QWaylandDisplay::~QWaylandDisplay(void)
         mWaylandIntegration->destroyScreen(screen);
     }
     mScreens.clear();
+#ifndef QT_NO_DRAGANDDROP
     delete mDndSelectionHandler.take();
+#endif
     wl_display_disconnect(mDisplay);
 }
 
@@ -243,8 +247,10 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
     } else if (interface == QStringLiteral("wl_seat")) {
         QWaylandInputDevice *inputDevice = mWaylandIntegration->createInputDevice(this, version, id);
         mInputDevices.append(inputDevice);
+#ifndef QT_NO_DRAGANDDROP
     } else if (interface == QStringLiteral("wl_data_device_manager")) {
         mDndSelectionHandler.reset(new QWaylandDataDeviceManager(this, id));
+#endif
     } else if (interface == QStringLiteral("qt_surface_extension")) {
         mWindowExtension.reset(new QtWayland::qt_surface_extension(registry, id, 1));
     } else if (interface == QStringLiteral("wl_subcompositor")) {
diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h
index a6591648..cc1308ba 100644
--- a/src/client/qwaylanddisplay_p.h
+++ b/src/client/qwaylanddisplay_p.h
@@ -131,9 +131,9 @@ public:
     QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
     QWaylandInputDevice *defaultInputDevice() const;
     QWaylandInputDevice *currentInputDevice() const { return defaultInputDevice(); }
-
+#ifndef QT_NO_DRAGANDDROP
     QWaylandDataDeviceManager *dndSelectionHandler() const { return mDndSelectionHandler.data(); }
-
+#endif
     QtWayland::qt_surface_extension *windowExtension() const { return mWindowExtension.data(); }
     QWaylandTouchExtension *touchExtension() const { return mTouchExtension.data(); }
     QtWayland::wl_text_input_manager *textInputManager() const { return mTextInputManager.data(); }
@@ -196,7 +196,9 @@ private:
     QList<QWaylandInputDevice *> mInputDevices;
     QList<Listener> mRegistryListeners;
     QWaylandIntegration *mWaylandIntegration;
+#ifndef QT_NO_DRAGANDDROP
     QScopedPointer<QWaylandDataDeviceManager> mDndSelectionHandler;
+#endif
     QScopedPointer<QtWayland::qt_surface_extension> mWindowExtension;
     QScopedPointer<QtWayland::wl_subcompositor> mSubCompositor;
     QScopedPointer<QWaylandTouchExtension> mTouchExtension;
diff --git a/src/client/qwaylanddnd.cpp b/src/client/qwaylanddnd.cpp
index e195d193..31b1c491 100644
--- a/src/client/qwaylanddnd.cpp
+++ b/src/client/qwaylanddnd.cpp
@@ -44,7 +44,7 @@
 #include <QDebug>
 
 QT_BEGIN_NAMESPACE
-
+#ifndef QT_NO_DRAGANDDROP
 namespace QtWaylandClient {
 
 QWaylandDrag::QWaylandDrag(QWaylandDisplay *display)
@@ -124,5 +124,5 @@ void QWaylandDrag::finishDrag(const QPlatformDropQtResponse &response)
 }
 
 }
-
+#endif // QT_NO_DRAGANDDROP
 QT_END_NAMESPACE
diff --git a/src/client/qwaylanddnd_p.h b/src/client/qwaylanddnd_p.h
index 42848a1d..a4fd91e9 100644
--- a/src/client/qwaylanddnd_p.h
+++ b/src/client/qwaylanddnd_p.h
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
 namespace QtWaylandClient {
 
 class QWaylandDisplay;
-
+#ifndef QT_NO_DRAGANDDROP
 class Q_WAYLAND_CLIENT_EXPORT QWaylandDrag : public QBasicDrag
 {
 public:
@@ -82,7 +82,7 @@ protected:
 private:
     QWaylandDisplay *m_display;
 };
-
+#endif
 }
 
 QT_END_NAMESPACE
diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp
index 5eaed9ea..6c72c59d 100644
--- a/src/client/qwaylandinputdevice.cpp
+++ b/src/client/qwaylandinputdevice.cpp
@@ -178,10 +178,11 @@ QWaylandInputDevice::QWaylandInputDevice(QWaylandDisplay *display, int version,
     , mSerial(0)
     , mTouchDevice(0)
 {
+#ifndef QT_NO_DRAGANDDROP
     if (mQDisplay->dndSelectionHandler()) {
         mDataDevice = mQDisplay->dndSelectionHandler()->getDataDevice(this);
     }
-
+#endif
 }
 
 QWaylandInputDevice::~QWaylandInputDevice()
diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp
index 17b3f681..106e54c6 100644
--- a/src/client/qwaylandintegration.cpp
+++ b/src/client/qwaylandintegration.cpp
@@ -126,9 +126,10 @@ QWaylandIntegration::QWaylandIntegration()
 {
     initializeInputDeviceIntegration();
     mDisplay = new QWaylandDisplay(this);
+#ifndef QT_NO_DRAGANDDROP
     mClipboard = new QWaylandClipboard(mDisplay);
     mDrag = new QWaylandDrag(mDisplay);
-
+#endif
     QString icStr = QPlatformInputContextFactory::requested();
     icStr.isNull() ? mInputContext.reset(new QWaylandInputContext(mDisplay))
                    : mInputContext.reset(QPlatformInputContextFactory::create(icStr));
@@ -136,8 +137,10 @@ QWaylandIntegration::QWaylandIntegration()
 
 QWaylandIntegration::~QWaylandIntegration()
 {
+#ifndef QT_NO_DRAGANDDROP
     delete mDrag;
     delete mClipboard;
+#endif
 #ifndef QT_NO_ACCESSIBILITY
     delete mAccessibility;
 #endif
@@ -213,6 +216,7 @@ QPlatformFontDatabase *QWaylandIntegration::fontDatabase() const
     return mFontDb;
 }
 
+#ifndef QT_NO_DRAGANDDROP
 QPlatformClipboard *QWaylandIntegration::clipboard() const
 {
     return mClipboard;
@@ -222,6 +226,7 @@ QPlatformDrag *QWaylandIntegration::drag() const
 {
     return mDrag;
 }
+#endif // QT_NO_DRAGANDDROP
 
 QPlatformInputContext *QWaylandIntegration::inputContext() const
 {
diff --git a/src/client/qwaylandintegration_p.h b/src/client/qwaylandintegration_p.h
index b6a71535..8d975924 100644
--- a/src/client/qwaylandintegration_p.h
+++ b/src/client/qwaylandintegration_p.h
@@ -79,11 +79,10 @@ public:
     QPlatformFontDatabase *fontDatabase() const Q_DECL_OVERRIDE;
 
     QPlatformNativeInterface *nativeInterface() const Q_DECL_OVERRIDE;
-
+#ifndef QT_NO_DRAGANDDROP
     QPlatformClipboard *clipboard() const Q_DECL_OVERRIDE;
-
     QPlatformDrag *drag() const Q_DECL_OVERRIDE;
-
+#endif
     QPlatformInputContext *inputContext() const Q_DECL_OVERRIDE;
 
     QVariant styleHint(StyleHint hint) const Q_DECL_OVERRIDE;
@@ -120,8 +119,10 @@ private:
     QWaylandShellIntegration *createShellIntegration(const QString& interfaceName);
 
     QPlatformFontDatabase *mFontDb;
+#ifndef QT_NO_DRAGANDDROP
     QPlatformClipboard *mClipboard;
     QPlatformDrag *mDrag;
+#endif
     QWaylandDisplay *mDisplay;
     QPlatformNativeInterface *mNativeInterface;
     QScopedPointer<QPlatformInputContext> mInputContext;
diff --git a/src/client/qwaylandnativeinterface.cpp b/src/client/qwaylandnativeinterface.cpp
index 98e1a736..aad69de3 100644
--- a/src/client/qwaylandnativeinterface.cpp
+++ b/src/client/qwaylandnativeinterface.cpp
@@ -106,6 +106,7 @@ void *QWaylandNativeInterface::nativeResourceForScreen(const QByteArray &resourc
     return NULL;
 }
 
+#ifndef QT_NO_OPENGL
 void *QWaylandNativeInterface::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)
 {
     QByteArray lowerCaseResource = resource.toLower();
@@ -121,6 +122,7 @@ void *QWaylandNativeInterface::nativeResourceForContext(const QByteArray &resour
 
     return 0;
 }
+#endif // QT_NO_OPENGL
 
 QVariantMap QWaylandNativeInterface::windowProperties(QPlatformWindow *window) const
 {
diff --git a/src/client/qwaylandnativeinterface_p.h b/src/client/qwaylandnativeinterface_p.h
index b4cb8fcb..cace9c33 100644
--- a/src/client/qwaylandnativeinterface_p.h
+++ b/src/client/qwaylandnativeinterface_p.h
@@ -66,8 +66,9 @@ public:
                                   QWindow *window) Q_DECL_OVERRIDE;
     void *nativeResourceForScreen(const QByteArray &resourceString,
                                   QScreen *screen) Q_DECL_OVERRIDE;
+#ifndef QT_NO_OPENGL
     void *nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) Q_DECL_OVERRIDE;
-
+#endif
     QVariantMap windowProperties(QPlatformWindow *window) const Q_DECL_OVERRIDE;
     QVariant windowProperty(QPlatformWindow *window, const QString &name) const Q_DECL_OVERRIDE;
     QVariant windowProperty(QPlatformWindow *window, const QString &name, const QVariant &defaultValue) const Q_DECL_OVERRIDE;
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index 4c00110b..354e97f2 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/qwaylandwindow.cpp
@@ -782,10 +782,12 @@ void QWaylandWindow::requestActivateWindow()
 
 void QWaylandWindow::unfocus()
 {
+#ifndef QT_NO_DRAGANDDROP
     QWaylandInputDevice *inputDevice = mDisplay->currentInputDevice();
     if (inputDevice && inputDevice->dataDevice()) {
         inputDevice->dataDevice()->invalidateSelectionOffer();
     }
+#endif
 }
 
 bool QWaylandWindow::isExposed() const
-- 
GitLab