diff --git a/src/DockWidgetBase.cpp b/src/DockWidgetBase.cpp index 13967981..c8eef89f 100644 --- a/src/DockWidgetBase.cpp +++ b/src/DockWidgetBase.cpp @@ -273,7 +273,7 @@ void DockWidgetBase::setFloating(bool floats) auto lastGeo = lastPositions().lastFloatingGeometry(); if (lastGeo.isValid()) { if (auto fw = floatingWindow()) - fw->setSuggestedGeometry(lastGeo); + fw->setSuggestedGeometry(lastGeo, /*preserveCenter=*/true); } } else { saveLastFloatingGeometry(); diff --git a/src/private/DragController.cpp b/src/private/DragController.cpp index ed206a96..5b88f793 100644 --- a/src/private/DragController.cpp +++ b/src/private/DragController.cpp @@ -184,6 +184,16 @@ void StateDragging::onEntry(QEvent *) q->m_windowBeingDragged = q->m_draggable->makeWindow(); if (q->m_windowBeingDragged) { qCDebug(state) << "StateDragging entered. m_draggable=" << q->m_draggable << "; m_windowBeingDragged=" << q->m_windowBeingDragged->floatingWindow(); + + auto fw = q->m_windowBeingDragged->floatingWindow(); + if (!fw->geometry().contains(q->m_pressPos)) { + // The window shrunk when the drag started, this can happen if it has max-size constraints + // we make the floating window smaller. Has the downside that it might not be under the mouse + // cursor anymore, so make the change + if (fw->width() < q->m_offset.x()) { // make sure it shrunk + q->m_offset.setX(fw->width() / 2); + } + } } else { // Shouldn't happen qWarning() << Q_FUNC_INFO << "No window being dragged for " << q->m_draggable->asWidget(); diff --git a/src/private/FloatingWindow.cpp b/src/private/FloatingWindow.cpp index 04d7f902..73f60baa 100644 --- a/src/private/FloatingWindow.cpp +++ b/src/private/FloatingWindow.cpp @@ -221,7 +221,7 @@ const Frame::List FloatingWindow::frames() const return m_dropArea->findChildren(QString(), Qt::FindDirectChildrenOnly); } -void FloatingWindow::setSuggestedGeometry(QRect suggestedRect) +void FloatingWindow::setSuggestedGeometry(QRect suggestedRect, bool preserveCenter) { const Frame::List frames = this->frames(); if (frames.size() == 1) { @@ -236,7 +236,8 @@ void FloatingWindow::setSuggestedGeometry(QRect suggestedRect) // Resize to new size but preserve center const QPoint originalCenter = suggestedRect.center(); suggestedRect.setSize(size); - suggestedRect.moveCenter(originalCenter); + if (preserveCenter) + suggestedRect.moveCenter(originalCenter); } setGeometry(suggestedRect); diff --git a/src/private/FloatingWindow_p.h b/src/private/FloatingWindow_p.h index 0f4bdbfb..bc2c1f6f 100644 --- a/src/private/FloatingWindow_p.h +++ b/src/private/FloatingWindow_p.h @@ -69,8 +69,11 @@ public: * @brief Equivalent to setGeometry(), but the value might be adjusted. * * For example, if the suggestedRect is bigger than max size, we'll make it smaller. + * + * @param preserveCenter, if true, then the center is preserved + * */ - void setSuggestedGeometry(QRect suggestedRect); + void setSuggestedGeometry(QRect suggestedRect, bool preserveCenter = false); bool anyNonClosable() const; bool anyNonDockable() const;