summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2023-03-10 16:47:19 +0100
committerDavid Edmundson <davidedmundson@kde.org>2023-06-05 09:32:22 +0100
commit40a27c26cee7ad4e5e32eb01568777cd4e9da25c (patch)
treefa5e5769f37cfd23551fa8380d8bc89a44f1dc43
parent345a612894a561846edba3b28b5f743653a23d12 (diff)
client: Implement qt-toplevel-drag-v1
This protocol for tabs toolbars and dock widgets to be dragged in and out of a main window using an extended version of the drag and drop protocol. Application code in QtBase use a special internal mimedata to specify a window that should be associated with a drag. This is 1:1 match with the pending upstream proposal xdg-toplevel-drag, and can be switched when that lands. Change-Id: Idf0afb71cd98d45938b4641ce861484fffac911c Reviewed-by: David Edmundson <davidedmundson@kde.org>
-rw-r--r--src/3rdparty/protocol/qt-toplevel-drag-v1.xml83
-rw-r--r--src/client/CMakeLists.txt2
-rw-r--r--src/client/qwaylanddatadevice.cpp60
-rw-r--r--src/client/qwaylanddatadevice_p.h6
-rw-r--r--src/client/qwaylanddisplay.cpp4
-rw-r--r--src/client/qwaylanddisplay_p.h3
6 files changed, 146 insertions, 12 deletions
diff --git a/src/3rdparty/protocol/qt-toplevel-drag-v1.xml b/src/3rdparty/protocol/qt-toplevel-drag-v1.xml
new file mode 100644
index 000000000..72a22cbbd
--- /dev/null
+++ b/src/3rdparty/protocol/qt-toplevel-drag-v1.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="qt_toplevel_drag_v1">
+
+ <copyright>
+ Copyright 2022 David Redondo &lt;kde@david-redondo.de&gt;
+
+ 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.
+ </copyright>
+
+ <interface name="qt_toplevel_drag_manager_v1" version="1">
+ <description summary="Move a window during a drag">
+ 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.
+ </description>
+
+ <request name="get_qt_toplevel_drag">
+ <description summary="get an qt_toplevel_drag for a wl_data_source">
+ 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.
+ </description>
+ <arg name="id" type="new_id" interface="qt_toplevel_drag_v1"/>
+ <arg name="data_source" type="object" interface="wl_data_source"/>
+ </request>
+
+ <request name="release" type="destructor" />
+
+ <enum name="error">
+ <entry name="invalid_source" value="0" summary="data_source already used for toplevel drag"/>
+ </enum>
+ </interface>
+
+ <interface name="qt_toplevel_drag_v1" version="1">
+ <description summary="Object representing a toplevel move during a drag">
+ </description>
+
+ <request name="attach">
+ <description summary="Move a toplevel with the drag operation">
+ 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.
+ </description>
+ <arg name="toplevel" type="object" interface="xdg_toplevel" />
+ <arg name="x_offset" type="int" summary="dragged surface x offset"/>
+ <arg name="y_offset" type="int" summary="dragged surface y offset"/>
+ </request>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy an qt_toplevel_drag object" />
+ </request>
+
+ <enum name="error">
+ <entry name="drag_ended" value="0" summary="corresponding drag has ended" />
+ </enum>
+ </interface>
+</protocol>
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
index d42259fc0..4fab5b319 100644
--- a/src/client/CMakeLists.txt
+++ b/src/client/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/client/qwaylanddatadevice.cpp b/src/client/qwaylanddatadevice.cpp
index a7014f7a1..e9d82100f 100644
--- a/src/client/qwaylanddatadevice.cpp
+++ b/src/client/qwaylanddatadevice.cpp
@@ -13,6 +13,8 @@
#include "qwaylandabstractdecoration_p.h"
#include "qwaylandsurface_p.h"
+#include <QtWaylandClient/private/qwayland-qt-toplevel-drag-v1.h>
+
#include <QtCore/QMimeData>
#include <QtGui/QGuiApplication>
#include <QtGui/private/qguiapplication_p.h>
@@ -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<QWaylandDrag *>(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<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())
+ ->setDropResponse(response);
+ });
+ connect(m_dragSource.data(), &QWaylandDataSource::finished, this, [this]() {
static_cast<QWaylandDrag *>(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<QWindow *>(dockWindowPtr);
+ QDataStream offsetStream(mimeData->data("application/x-qt-mainwindowdrag-position"_L1));
+ offsetStream >> offset;
+ if (auto waylandWindow = static_cast<QWaylandWindow *>(dockWindow->handle())) {
+ if (auto toplevel = waylandWindow->surfaceRole<xdg_toplevel>()) {
+ 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<QWaylandDrag *>(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<QWaylandDrag *>(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<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->setResponse(response);
}
@@ -263,6 +297,10 @@ void QWaylandDataDevice::dragSourceCancelled()
{
static_cast<QWaylandDrag *>(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/client/qwaylanddatadevice_p.h b/src/client/qwaylanddatadevice_p.h
index 76c8965f9..b924aa7ef 100644
--- a/src/client/qwaylanddatadevice_p.h
+++ b/src/client/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<QWaylandDataOffer> m_dragOffer;
QScopedPointer<QWaylandDataOffer> m_selectionOffer;
QScopedPointer<QWaylandDataSource> m_selectionSource;
-
QScopedPointer<QWaylandDataSource> m_dragSource;
+ QtWayland::qt_toplevel_drag_v1 *m_toplevelDrag = nullptr;
};
}
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
index c49cb428a..ae066beca 100644
--- a/src/client/qwaylanddisplay.cpp
+++ b/src/client/qwaylanddisplay.cpp
@@ -53,6 +53,7 @@
#include <QtWaylandClient/private/qwayland-fractional-scale-v1.h>
#include <QtWaylandClient/private/qwayland-viewporter.h>
#include <QtWaylandClient/private/qwayland-cursor-shape-v1.h>
+#include <QtWaylandClient/private/qwayland-qt-toplevel-drag-v1.h>
#include <QtCore/private/qcore_unix_p.h>
@@ -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/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h
index 877ff9692..7a64749ef 100644
--- a/src/client/qwaylanddisplay_p.h
+++ b/src/client/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<QtWayland::wp_viewporter> mViewporter;
QScopedPointer<QtWayland::wp_fractional_scale_manager_v1> mFractionalScaleManager;
QScopedPointer<QtWayland::wp_cursor_shape_manager_v1> mCursorShapeManager;
+ QScopedPointer<QtWayland::qt_toplevel_drag_manager_v1> mXdgToplevelDragManager;
int mFd = -1;
int mWritableNotificationFd = -1;
QList<RegistryGlobal> mGlobals;