diff --git a/src/3rdparty/wayland/protocols/qt-toplevel-drag-v1.xml b/src/3rdparty/wayland/protocols/qt-toplevel-drag-v1.xml
new file mode 100644
index 00000000000..72a22cbbde1
--- /dev/null
+++ b/src/3rdparty/wayland/protocols/qt-toplevel-drag-v1.xml
@@ -0,0 +1,83 @@
+
+
+
+
+ Copyright 2022 David Redondo <kde@david-redondo.de>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+
+
+
+
+ This protocol enhances normal drag and drop with the ability to move a
+ window at the same time. This allows having detachable windows that
+ can also be reattached when dragged back to another window or some special
+ zone.
+
+ Warning! The protocol described in this file is currently in the testing
+ phase. Backward compatible changes may be added together with the
+ corresponding interface version bump. Backward incompatible changes can
+ only be done by creating a new major version of the extension.
+
+
+
+
+ Create an qt_toplevel_drag for a drag and drop operation that is going
+ to be started with data_source.
+ This request can only be made on sources used in drag-and-drop, so it
+ must be performed before wl_data_device.start_drag. Attempting to use
+ the source other than for drag-and-drop will raise an invalid_source error.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Request that the window will be moved with the cursor during the drag operation. The offset
+ describes how the toplevel will be positioned relative to the cursor hotspot
+ in surface local coordinates.
+ Issuing this request after the drag has ended will result in a drag_ended protocol error.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/plugins/platforms/wayland/CMakeLists.txt b/src/plugins/platforms/wayland/CMakeLists.txt
index d42259fc0c0..4fab5b3198d 100644
--- a/src/plugins/platforms/wayland/CMakeLists.txt
+++ b/src/plugins/platforms/wayland/CMakeLists.txt
@@ -93,6 +93,8 @@ qt6_generate_wayland_protocol_client_sources(WaylandClient
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/xdg-output-unstable-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/fractional-scale-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/viewporter.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/qt-toplevel-drag-v1.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/xdg-shell.xml
${CMAKE_CURRENT_SOURCE_DIR}/../extensions/qt-key-unstable-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../extensions/qt-text-input-method-unstable-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../extensions/qt-windowmanager.xml
diff --git a/src/plugins/platforms/wayland/qwaylanddatadevice.cpp b/src/plugins/platforms/wayland/qwaylanddatadevice.cpp
index a7014f7a1a5..e9d82100fad 100644
--- a/src/plugins/platforms/wayland/qwaylanddatadevice.cpp
+++ b/src/plugins/platforms/wayland/qwaylanddatadevice.cpp
@@ -13,6 +13,8 @@
#include "qwaylandabstractdecoration_p.h"
#include "qwaylandsurface_p.h"
+#include
+
#include
#include
#include
@@ -27,6 +29,8 @@ QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
+using namespace Qt::StringLiterals;
+
QWaylandDataDevice::QWaylandDataDevice(QWaylandDataDeviceManager *manager, QWaylandInputDevice *inputDevice)
: QObject(inputDevice)
, QtWayland::wl_data_device(manager->get_data_device(inputDevice->wl_seat()))
@@ -105,14 +109,47 @@ bool QWaylandDataDevice::startDrag(QMimeData *mimeData, Qt::DropActions supporte
drag->setResponse(response);
}
});
- connect(m_dragSource.data(), &QWaylandDataSource::dndDropped, this, [](bool accepted, Qt::DropAction action) {
- QPlatformDropQtResponse response(accepted, action);
- static_cast(QGuiApplicationPrivate::platformIntegration()->drag())->setDropResponse(response);
- });
- connect(m_dragSource.data(), &QWaylandDataSource::finished, this, []() {
+ connect(m_dragSource.data(), &QWaylandDataSource::dndDropped, this,
+ [this](bool accepted, Qt::DropAction action) {
+ QPlatformDropQtResponse response(accepted, action);
+ if (m_toplevelDrag) {
+ // If the widget was dropped but the drag not accepted it
+ // should be its own window in the future. To distinguish
+ // from canceling mid-drag the drag is accepted here as the
+ // we know if the widget is over a zone where it can be
+ // incorporated or not
+ response = { accepted, Qt::MoveAction };
+ }
+ static_cast(QGuiApplicationPrivate::platformIntegration()->drag())
+ ->setDropResponse(response);
+ });
+ connect(m_dragSource.data(), &QWaylandDataSource::finished, this, [this]() {
static_cast(QGuiApplicationPrivate::platformIntegration()->drag())->finishDrag();
+ if (m_toplevelDrag) {
+ m_toplevelDrag->destroy();
+ m_toplevelDrag = nullptr;
+ }
});
+ if (mimeData->hasFormat("application/x-qt-mainwindowdrag-window"_L1)
+ && m_display->xdgToplevelDragManager()) {
+ qintptr dockWindowPtr;
+ QPoint offset;
+ QDataStream windowStream(mimeData->data("application/x-qt-mainwindowdrag-window"_L1));
+ windowStream >> dockWindowPtr;
+ QWindow *dockWindow = reinterpret_cast(dockWindowPtr);
+ QDataStream offsetStream(mimeData->data("application/x-qt-mainwindowdrag-position"_L1));
+ offsetStream >> offset;
+ if (auto waylandWindow = static_cast(dockWindow->handle())) {
+ if (auto toplevel = waylandWindow->surfaceRole()) {
+ m_toplevelDrag = new QtWayland::qt_toplevel_drag_v1(
+ m_display->xdgToplevelDragManager()->get_qt_toplevel_drag(
+ m_dragSource->object()));
+ m_toplevelDrag->attach(toplevel, offset.x(), offset.y());
+ }
+ }
+ }
+
start_drag(m_dragSource->object(), origin->wlSurface(), icon->wlSurface(), m_display->currentInputDevice()->serial());
return true;
}
@@ -148,7 +185,6 @@ void QWaylandDataDevice::data_device_drop()
QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(m_dragWindow, dragData, m_dragPoint, supportedActions,
QGuiApplication::mouseButtons(),
QGuiApplication::keyboardModifiers());
-
if (drag) {
auto drag = static_cast(QGuiApplicationPrivate::platformIntegration()->drag());
drag->setDropResponse(response);
@@ -175,16 +211,14 @@ void QWaylandDataDevice::data_device_enter(uint32_t serial, wl_surface *surface,
QDrag *drag = static_cast(QGuiApplicationPrivate::platformIntegration()->drag())->currentDrag();
if (drag) {
dragData = drag->mimeData();
- supportedActions = drag->supportedActions();
} else if (m_dragOffer) {
dragData = m_dragOffer->mimeData();
supportedActions = m_dragOffer->supportedActions();
}
- const QPlatformDragQtResponse &response = QWindowSystemInterface::handleDrag(m_dragWindow, dragData, m_dragPoint, supportedActions,
- QGuiApplication::mouseButtons(),
- QGuiApplication::keyboardModifiers());
-
+ const QPlatformDragQtResponse &response = QWindowSystemInterface::handleDrag(
+ m_dragWindow, dragData, m_dragPoint, supportedActions, QGuiApplication::mouseButtons(),
+ QGuiApplication::keyboardModifiers());
if (drag) {
static_cast(QGuiApplicationPrivate::platformIntegration()->drag())->setResponse(response);
}
@@ -263,6 +297,10 @@ void QWaylandDataDevice::dragSourceCancelled()
{
static_cast(QGuiApplicationPrivate::platformIntegration()->drag())->finishDrag();
m_dragSource.reset();
+ if (m_toplevelDrag) {
+ m_toplevelDrag->destroy();
+ m_toplevelDrag = nullptr;
+ }
}
QPoint QWaylandDataDevice::calculateDragPosition(int x, int y, QWindow *wnd) const
diff --git a/src/plugins/platforms/wayland/qwaylanddatadevice_p.h b/src/plugins/platforms/wayland/qwaylanddatadevice_p.h
index 76c8965f906..b924aa7efe5 100644
--- a/src/plugins/platforms/wayland/qwaylanddatadevice_p.h
+++ b/src/plugins/platforms/wayland/qwaylanddatadevice_p.h
@@ -31,6 +31,10 @@ class QMimeData;
class QPlatformDragQtResponse;
class QWindow;
+namespace QtWayland {
+class qt_toplevel_drag_v1;
+}
+
namespace QtWaylandClient {
class QWaylandDisplay;
@@ -93,8 +97,8 @@ private:
QScopedPointer m_dragOffer;
QScopedPointer m_selectionOffer;
QScopedPointer m_selectionSource;
-
QScopedPointer m_dragSource;
+ QtWayland::qt_toplevel_drag_v1 *m_toplevelDrag = nullptr;
};
}
diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp
index c49cb428a4f..ae066becad8 100644
--- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp
+++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp
@@ -53,6 +53,7 @@
#include
#include
#include
+#include
#include
@@ -758,6 +759,9 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
mViewporter.reset(new QtWayland::wp_viewporter(registry, id, qMin(1u, version)));
} else if (interface == QLatin1String(QtWayland::wp_cursor_shape_manager_v1::interface()->name)) {
mCursorShapeManager.reset(new QtWayland::wp_cursor_shape_manager_v1(registry, id, std::min(1u, version)));
+ } else if (
+ interface == QLatin1String(QtWayland::qt_toplevel_drag_manager_v1::interface()->name)) {
+ mXdgToplevelDragManager.reset(new QtWayland::qt_toplevel_drag_manager_v1(registry, id, 1));
}
mGlobals.append(RegistryGlobal(id, interface, version, registry));
diff --git a/src/plugins/platforms/wayland/qwaylanddisplay_p.h b/src/plugins/platforms/wayland/qwaylanddisplay_p.h
index 877ff9692a5..7a64749ef9e 100644
--- a/src/plugins/platforms/wayland/qwaylanddisplay_p.h
+++ b/src/plugins/platforms/wayland/qwaylanddisplay_p.h
@@ -54,6 +54,7 @@ namespace QtWayland {
class wp_cursor_shape_manager_v1;
class wp_fractional_scale_manager_v1;
class wp_viewporter;
+ class qt_toplevel_drag_manager_v1;
}
namespace QtWaylandClient {
@@ -154,6 +155,7 @@ public:
QtWayland::wp_fractional_scale_manager_v1 *fractionalScaleManager() const { return mFractionalScaleManager.data(); }
QtWayland::wp_viewporter *viewporter() const { return mViewporter.data(); }
QtWayland::wp_cursor_shape_manager_v1 *cursorShapeManager() const { return mCursorShapeManager.data();}
+ QtWayland::qt_toplevel_drag_manager_v1 *xdgToplevelDragManager() const { return mXdgToplevelDragManager.data();}
struct RegistryGlobal {
uint32_t id;
@@ -280,6 +282,7 @@ private:
QScopedPointer mViewporter;
QScopedPointer mFractionalScaleManager;
QScopedPointer mCursorShapeManager;
+ QScopedPointer mXdgToplevelDragManager;
int mFd = -1;
int mWritableNotificationFd = -1;
QList mGlobals;