Clean up draganddrop and clipboard features

Don't assume that no-draganddrop implies no-clipboard. Introduce
a new private feature wayland-datadevice which contains the
common functionality. This feature cannot be controlled independently,
but is automatically disabled when both clipboard and draganddrop are
disabled.

Change-Id: I6aac09c7ee524e3b11f0a1caa4a6c62fc3f1d10f
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
This commit is contained in:
Paul Olav Tvete 2017-03-16 13:59:20 +01:00
parent c2f1a2dd89
commit 086b0a9a26
17 changed files with 72 additions and 57 deletions

View File

@ -40,9 +40,6 @@ SOURCES += qwaylandintegration.cpp \
qwaylandwindow.cpp \
qwaylandscreen.cpp \
qwaylandshmwindow.cpp \
qwaylanddataoffer.cpp \
qwaylanddatadevicemanager.cpp \
qwaylanddatasource.cpp \
qwaylandshellsurface.cpp \
qwaylandwlshellsurface.cpp \
qwaylandwlshellintegration.cpp \
@ -76,9 +73,6 @@ HEADERS += qwaylandintegration_p.h \
qwaylandinputdevice_p.h \
qwaylandbuffer_p.h \
qwaylandshmwindow_p.h \
qwaylanddataoffer_p.h \
qwaylanddatadevicemanager_p.h \
qwaylanddatasource_p.h \
qwaylandshellsurface_p.h \
qwaylandwlshellsurface_p.h \
qwaylandwlshellintegration_p.h \
@ -123,13 +117,25 @@ qtConfig(cursor) {
SOURCES += \
qwaylandcursor.cpp
}
qtConfig(wayland-datadevice) {
HEADERS += \
qwaylanddatadevice_p.h \
qwaylanddatadevicemanager_p.h \
qwaylanddataoffer_p.h \
qwaylanddatasource_p.h
SOURCES += \
qwaylanddatadevice.cpp \
qwaylanddatadevicemanager.cpp \
qwaylanddataoffer.cpp \
qwaylanddatasource.cpp
}
qtConfig(draganddrop) {
HEADERS += \
qwaylanddnd_p.h \
qwaylanddatadevice_p.h
qwaylanddnd_p.h
SOURCES += \
qwaylanddnd.cpp \
qwaylanddatadevice.cpp
qwaylanddnd.cpp
}
CONFIG += generated_privates

View File

@ -76,6 +76,10 @@
"condition": "!config.win32 && libs.wayland-client && libs.wayland-cursor && tests.wayland-scanner",
"output": [ "privateFeature" ]
},
"wayland-datadevice": {
"condition": "features.draganddrop || features.clipboard",
"output": [ "privateFeature" ]
},
"wayland-egl": {
"label": "EGL",
"condition": "features.wayland-client && features.opengl && features.egl && libs.wayland-egl",

View File

@ -44,8 +44,6 @@
#include "qwaylanddatasource_p.h"
#include "qwaylanddatadevice_p.h"
#if QT_CONFIG(draganddrop)
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -117,5 +115,3 @@ bool QWaylandClipboard::ownsMode(QClipboard::Mode mode) const
}
QT_END_NAMESPACE
#endif // draganddrop

View File

@ -57,7 +57,8 @@
#include <QtWaylandClient/qtwaylandclientglobal.h>
#if QT_CONFIG(draganddrop)
QT_REQUIRE_CONFIG(clipboard);
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -85,6 +86,4 @@ private:
QT_END_NAMESPACE
#endif // draganddrop
#endif // QWAYLANDCLIPBOARD_H

View File

@ -58,8 +58,6 @@
#include <qpa/qplatformdrag.h>
#include <qpa/qwindowsysteminterface.h>
#if QT_CONFIG(draganddrop)
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -103,6 +101,7 @@ void QWaylandDataDevice::setSelectionSource(QWaylandDataSource *source)
m_selectionSource.reset(source);
}
#if QT_CONFIG(draganddrop)
QWaylandDataOffer *QWaylandDataDevice::dragOffer() const
{
return m_dragOffer.data();
@ -124,12 +123,14 @@ void QWaylandDataDevice::cancelDrag()
{
m_dragSource.reset();
}
#endif
void QWaylandDataDevice::data_device_data_offer(struct ::wl_data_offer *id)
{
new QWaylandDataOffer(m_display, id);
}
#if QT_CONFIG(draganddrop)
void QWaylandDataDevice::data_device_drop()
{
QDrag *drag = static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->currentDrag();
@ -229,6 +230,7 @@ void QWaylandDataDevice::data_device_motion(uint32_t time, wl_fixed_t x, wl_fixe
wl_data_offer_accept(m_dragOffer->object(), m_enterSerial, 0);
}
}
#endif // QT_CONFIG(draganddrop)
void QWaylandDataDevice::data_device_selection(wl_data_offer *id)
{
@ -250,6 +252,7 @@ void QWaylandDataDevice::selectionSourceCancelled()
#endif
}
#if QT_CONFIG(draganddrop)
void QWaylandDataDevice::dragSourceCancelled()
{
m_dragSource.reset();
@ -272,9 +275,8 @@ QPoint QWaylandDataDevice::calculateDragPosition(int x, int y, QWindow *wnd) con
}
return pnt;
}
#endif // QT_CONFIG(draganddrop)
}
QT_END_NAMESPACE
#endif // draganddrop

View File

@ -52,14 +52,14 @@
// We mean it.
//
#include <qtwaylandclientglobal.h>
#include <qtwaylandclientglobal_p.h>
#include <QObject>
#include <QPointer>
#include <QPoint>
#include <QtWaylandClient/private/qwayland-wayland.h>
#if QT_CONFIG(draganddrop)
QT_REQUIRE_CONFIG(wayland_datadevice);
QT_BEGIN_NAMESPACE
@ -87,25 +87,35 @@ public:
QWaylandDataSource *selectionSource() const;
void setSelectionSource(QWaylandDataSource *source);
#if QT_CONFIG(draganddrop)
QWaylandDataOffer *dragOffer() const;
void startDrag(QMimeData *mimeData, QWaylandWindow *icon);
void cancelDrag();
#endif
protected:
void data_device_data_offer(struct ::wl_data_offer *id) override;
#if QT_CONFIG(draganddrop)
void data_device_drop() override;
void data_device_enter(uint32_t serial, struct ::wl_surface *surface, wl_fixed_t x, wl_fixed_t y, struct ::wl_data_offer *id) override;
void data_device_leave() override;
void data_device_motion(uint32_t time, wl_fixed_t x, wl_fixed_t y) override;
#endif
void data_device_selection(struct ::wl_data_offer *id) override;
private Q_SLOTS:
void selectionSourceCancelled();
#if QT_CONFIG(draganddrop)
void dragSourceCancelled();
void dragSourceTargetChanged(const QString &mimeType);
#endif
private:
#if QT_CONFIG(draganddrop)
QPoint calculateDragPosition(int x, int y, QWindow *wnd) const;
#endif
QWaylandDisplay *m_display;
QWaylandInputDevice *m_inputDevice;
@ -123,6 +133,4 @@ private:
QT_END_NAMESPACE
#endif // draganddrop
#endif // QWAYLANDDATADEVICE_H

View File

@ -46,8 +46,6 @@
#include <QtCore/QDebug>
#if QT_CONFIG(draganddrop)
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -82,5 +80,3 @@ QWaylandDisplay *QWaylandDataDeviceManager::display() const
}
QT_END_NAMESPACE
#endif // draganddrop

View File

@ -51,10 +51,10 @@
// We mean it.
//
#include <QtWaylandClient/qtwaylandclientglobal.h>
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
#include <QtWaylandClient/private/qwayland-wayland.h>
#if QT_CONFIG(draganddrop)
QT_REQUIRE_CONFIG(wayland_datadevice);
QT_BEGIN_NAMESPACE
@ -83,6 +83,4 @@ private:
QT_END_NAMESPACE
#endif // draganddrop
#endif // QWAYLANDDATADEVICEMANAGER_H

View File

@ -47,8 +47,6 @@
#include <QtCore/QDebug>
#if QT_CONFIG(draganddrop)
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -183,5 +181,3 @@ int QWaylandMimeData::readData(int fd, QByteArray &data) const
}
QT_END_NAMESPACE
#endif // draganddrop

View File

@ -53,10 +53,11 @@
#include <QtGui/private/qdnd_p.h>
#include <QtWaylandClient/qtwaylandclientglobal.h>
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
#include <QtWaylandClient/private/qwayland-wayland.h>
#if QT_CONFIG(draganddrop)
QT_REQUIRE_CONFIG(wayland_datadevice);
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -106,5 +107,4 @@ private:
}
QT_END_NAMESPACE
#endif // draganddrop
#endif

View File

@ -50,8 +50,6 @@
#include <unistd.h>
#include <signal.h>
#if QT_CONFIG(draganddrop)
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
@ -108,5 +106,3 @@ void QWaylandDataSource::data_source_target(const QString &mime_type)
}
QT_END_NAMESPACE
#endif // draganddrop

View File

@ -54,9 +54,9 @@
#include <QObject>
#include <QtWaylandClient/private/qwayland-wayland.h>
#include <QtWaylandClient/qtwaylandclientglobal.h>
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
#if QT_CONFIG(draganddrop)
QT_REQUIRE_CONFIG(wayland_datadevice);
QT_BEGIN_NAMESPACE
@ -94,6 +94,4 @@ private:
QT_END_NAMESPACE
#endif // draganddrop
#endif // QWAYLANDDATASOURCE_H

View File

@ -47,7 +47,9 @@
#if QT_CONFIG(clipboard)
#include "qwaylandclipboard_p.h"
#endif
#if QT_CONFIG(wayland_datadevice)
#include "qwaylanddatadevicemanager_p.h"
#endif
#include "qwaylandhardwareintegration_p.h"
#include "qwaylandxdgshell_p.h"
#include "qwaylandxdgsurface_p.h"
@ -122,7 +124,7 @@ QWaylandWindowManagerIntegration *QWaylandDisplay::windowManagerIntegration() co
QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration)
: mWaylandIntegration(waylandIntegration)
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(wayland_datadevice)
, mDndSelectionHandler(0)
#endif
, mWindowExtension(0)
@ -162,7 +164,7 @@ QWaylandDisplay::~QWaylandDisplay(void)
mWaylandIntegration->destroyScreen(screen);
}
mScreens.clear();
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(wayland_datadevice)
delete mDndSelectionHandler.take();
#endif
wl_display_disconnect(mDisplay);
@ -257,7 +259,7 @@ 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);
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(wayland_datadevice)
} else if (interface == QStringLiteral("wl_data_device_manager")) {
mDndSelectionHandler.reset(new QWaylandDataDeviceManager(this, id));
#endif

View File

@ -61,7 +61,7 @@
#include <wayland-client.h>
#include <QtWaylandClient/private/qwayland-wayland.h>
#include <QtWaylandClient/qtwaylandclientglobal.h>
#include <QtWaylandClient/private/qtwaylandclientglobal_p.h>
#include <QtWaylandClient/private/qwayland-xdg-shell.h>
#include <QtWaylandClient/private/qwaylandshm_p.h>
@ -137,7 +137,7 @@ public:
QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
QWaylandInputDevice *defaultInputDevice() const;
QWaylandInputDevice *currentInputDevice() const { return defaultInputDevice(); }
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(wayland_datadevice)
QWaylandDataDeviceManager *dndSelectionHandler() const { return mDndSelectionHandler.data(); }
#endif
QtWayland::qt_surface_extension *windowExtension() const { return mWindowExtension.data(); }
@ -202,7 +202,7 @@ private:
QList<QWaylandInputDevice *> mInputDevices;
QList<Listener> mRegistryListeners;
QWaylandIntegration *mWaylandIntegration;
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(wayland_datadevice)
QScopedPointer<QWaylandDataDeviceManager> mDndSelectionHandler;
#endif
QScopedPointer<QtWayland::qt_surface_extension> mWindowExtension;

View File

@ -42,8 +42,10 @@
#include "qwaylandintegration_p.h"
#include "qwaylandwindow_p.h"
#include "qwaylandbuffer_p.h"
#if QT_CONFIG(wayland_datadevice)
#include "qwaylanddatadevice_p.h"
#include "qwaylanddatadevicemanager_p.h"
#endif
#include "qwaylandtouch_p.h"
#include "qwaylandscreen_p.h"
#include "qwaylandcursor_p.h"
@ -187,7 +189,9 @@ QWaylandInputDevice::QWaylandInputDevice(QWaylandDisplay *display, int version,
, mDisplay(display->wl_display())
, mVersion(qMin(version, 4))
, mCaps(0)
#if QT_CONFIG(wayland_datadevice)
, mDataDevice(0)
#endif
, mKeyboard(0)
, mPointer(0)
, mTouch(0)
@ -196,7 +200,7 @@ QWaylandInputDevice::QWaylandInputDevice(QWaylandDisplay *display, int version,
, mSerial(0)
, mTouchDevice(0)
{
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(wayland_datadevice)
if (mQDisplay->dndSelectionHandler()) {
mDataDevice = mQDisplay->dndSelectionHandler()->getDataDevice(this);
}
@ -286,6 +290,7 @@ void QWaylandInputDevice::handleEndDrag()
mPointer->releaseButtons();
}
#if QT_CONFIG(wayland_datadevice)
void QWaylandInputDevice::setDataDevice(QWaylandDataDevice *device)
{
mDataDevice = device;
@ -296,6 +301,7 @@ QWaylandDataDevice *QWaylandInputDevice::dataDevice() const
Q_ASSERT(mDataDevice);
return mDataDevice;
}
#endif
void QWaylandInputDevice::setTextInput(QWaylandTextInput *textInput)
{

View File

@ -111,8 +111,10 @@ public:
void handleWindowDestroyed(QWaylandWindow *window);
void handleEndDrag();
#if QT_CONFIG(wayland_datadevice)
void setDataDevice(QWaylandDataDevice *device);
QWaylandDataDevice *dataDevice() const;
#endif
void setTextInput(QWaylandTextInput *textInput);
QWaylandTextInput *textInput() const;
@ -143,7 +145,9 @@ private:
struct wl_surface *pointerSurface;
#if QT_CONFIG(wayland_datadevice)
QWaylandDataDevice *mDataDevice;
#endif
Keyboard *mKeyboard;
Pointer *mPointer;

View File

@ -40,7 +40,6 @@
#include "qwaylandwindow_p.h"
#include "qwaylandbuffer_p.h"
#include "qwaylanddatadevice_p.h"
#include "qwaylanddisplay_p.h"
#include "qwaylandinputdevice_p.h"
#include "qwaylandscreen_p.h"
@ -54,6 +53,11 @@
#include "qwaylanddecorationfactory_p.h"
#include "qwaylandshmbackingstore_p.h"
#if QT_CONFIG(wayland_datadevice)
#include "qwaylanddatadevice_p.h"
#endif
#include <QtCore/QFileInfo>
#include <QtCore/QPointer>
#include <QtCore/QRegularExpression>
@ -825,7 +829,7 @@ void QWaylandWindow::requestActivateWindow()
void QWaylandWindow::unfocus()
{
#if QT_CONFIG(draganddrop)
#if QT_CONFIG(clipboard)
QWaylandInputDevice *inputDevice = mDisplay->currentInputDevice();
if (inputDevice && inputDevice->dataDevice()) {
inputDevice->dataDevice()->invalidateSelectionOffer();