diff options
author | David Redondo <qt@david-redondo.de> | 2023-03-10 16:44:20 +0100 |
---|---|---|
committer | David Redondo <qt@david-redondo.de> | 2023-06-02 19:53:34 +0200 |
commit | 581c4bcb62a9d3cbb4c33df3f0f7a0a965225e74 (patch) | |
tree | 22da571a5a8c0d5fdbfd14a17654cf3a8b28d5ba /src/widgets/widgets/qdockwidget.cpp | |
parent | 1eb4d17cb48a70501ebf51fc8732e14fec2cc12f (diff) |
Use platform drags for drags of docks and toolbars on wayland
On Wayland we can't know where windows are in relation to
each other so the whole mechanism was broken, toolbars
were unmovable once undocked and could be blindly redocked.
Dockwidgets had native toolbars to move them around but could
not be redocked.
This introduces an alternative code path that uses a platform
drag with a special mimetype that enables the platform to
issue a combined drag and window move using the relevant protocol.
Should the protocol not be available this doesn't make things
actively worse as it will be similar broken as before.
Fixes: QTBUG-87332
Change-Id: I3b8bdc0b1bc22569a64cb8bf7ca7d37d223936a6
Reviewed-by: David Edmundson <davidedmundson@kde.org>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/widgets/widgets/qdockwidget.cpp')
-rw-r--r-- | src/widgets/widgets/qdockwidget.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 375bd3daae..c952c8d4fd 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -253,7 +253,9 @@ bool QDockWidgetLayout::wmSupportsNativeWindowDeco() return false; #else static const bool xcb = !QGuiApplication::platformName().compare("xcb"_L1, Qt::CaseInsensitive); - return !xcb; + static const bool wayland = + QGuiApplication::platformName().startsWith("wayland"_L1, Qt::CaseInsensitive); + return !(xcb || wayland); #endif } @@ -778,6 +780,8 @@ void QDockWidgetPrivate::startDrag(bool group) QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); Q_ASSERT(layout != nullptr); + bool wasFloating = q->isFloating(); + state->widgetItem = layout->unplug(q, group); if (state->widgetItem == nullptr) { /* Dock widget has a QMainWindow parent, but was never inserted with @@ -796,6 +800,20 @@ void QDockWidgetPrivate::startDrag(bool group) layout->restore(); state->dragging = true; + +#if QT_CONFIG(draganddrop) + if (QMainWindowLayout::needsPlatformDrag()) { + Qt::DropAction result = + layout->performPlatformWidgetDrag(state->widgetItem, state->pressPos); + if (result == Qt::IgnoreAction && !wasFloating) { + layout->revert(state->widgetItem); + delete state; + state = nullptr; + } else { + endDrag(); + } + } +#endif } /*! \internal @@ -1038,6 +1056,10 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) bool QDockWidgetPrivate::mouseReleaseEvent(QMouseEvent *event) { #if QT_CONFIG(mainwindow) + // if we are peforming a platform drag ignore the release here and end the drag when the actual + // drag ends. + if (QMainWindowLayout::needsPlatformDrag()) + return false; if (event->button() == Qt::LeftButton && state && !state->nca) { endDrag(); @@ -1185,7 +1207,9 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect flags |= Qt::FramelessWindowHint; } - if (unplug) + // If we are performing a platform drag the flag is not needed and we want to avoid recreating + // the platform window when it would be removed later + if (unplug && !QMainWindowLayout::needsPlatformDrag()) flags |= Qt::X11BypassWindowManagerHint; q->setWindowFlags(flags); |