Fix floating window position when dragging with constraints
When the detach starts we might make the window smaller so it respects the max-size constraint. The quirk was that in that case the window was no longer under the mouse cursor, so looked weird while dragging, although it worked
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -221,7 +221,7 @@ const Frame::List FloatingWindow::frames() const
|
||||
return m_dropArea->findChildren<Frame *>(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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user