From 10e41fc948ee3c4dd65a1458ad961d0625a172eb Mon Sep 17 00:00:00 2001 From: Ser Freeman Date: Sat, 23 Dec 2023 15:59:18 +0500 Subject: [PATCH] Window: Extract title bar rect code to the separate function This will allow code reuse. --- src/window.cpp | 55 +++++++++++++++++++++++++------------------------- src/window.h | 1 + 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index 4c6faba682..c8635e1001 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1420,6 +1420,34 @@ void Window::handleInteractiveMoveResize(const QPointF &local, const QPointF &gl } } +QRectF Window::titleBarRect(const QRectF &rect, bool &transposed, int &requiredPixels) const +{ + QRectF titleRect = rect; + titleRect.moveTopLeft(QPointF(0, 0)); + switch (titlebarPosition()) { + default: + case Qt::TopEdge: + titleRect.setHeight(borderTop()); + break; + case Qt::LeftEdge: + titleRect.setWidth(borderLeft()); + transposed = true; + break; + case Qt::BottomEdge: + titleRect.setTop(titleRect.bottom() - borderBottom()); + break; + case Qt::RightEdge: + titleRect.setLeft(titleRect.right() - borderRight()); + transposed = true; + break; + } + // When doing a restricted move we must always keep 100px of the titlebar + // visible to allow the user to be able to move it again. + requiredPixels = std::min(100 * (transposed ? titleRect.width() : titleRect.height()), + rect.width() * rect.height()); + return titleRect; +} + void Window::handleInteractiveMoveResize(qreal x, qreal y, qreal x_root, qreal y_root) { if (isWaitingForInteractiveMoveResizeSync()) { @@ -1461,33 +1489,6 @@ void Window::handleInteractiveMoveResize(qreal x, qreal y, qreal x_root, qreal y // TODO move whole group when moving its leader or when the leader is not mapped? - auto titleBarRect = [this](const QRectF &rect, bool &transposed, int &requiredPixels) -> QRectF { - QRectF titleRect = rect; - titleRect.moveTopLeft(QPointF(0, 0)); - switch (titlebarPosition()) { - default: - case Qt::TopEdge: - titleRect.setHeight(borderTop()); - break; - case Qt::LeftEdge: - titleRect.setWidth(borderLeft()); - transposed = true; - break; - case Qt::BottomEdge: - titleRect.setTop(titleRect.bottom() - borderBottom()); - break; - case Qt::RightEdge: - titleRect.setLeft(titleRect.right() - borderRight()); - transposed = true; - break; - } - // When doing a restricted move we must always keep 100px of the titlebar - // visible to allow the user to be able to move it again. - requiredPixels = std::min(100 * (transposed ? titleRect.width() : titleRect.height()), - rect.width() * rect.height()); - return titleRect; - }; - if (isInteractiveResize()) { if (m_tile && m_tile->supportsResizeGravity(gravity)) { m_tile->resizeFromGravity(gravity, x_root, y_root); diff --git a/src/window.h b/src/window.h index f0bad44547..ebb5534637 100644 --- a/src/window.h +++ b/src/window.h @@ -1680,6 +1680,7 @@ protected: virtual void doInteractiveResizeSync(const QRectF &rect); void handleInteractiveMoveResize(qreal x, qreal y, qreal x_root, qreal y_root); void handleInteractiveMoveResize(const QPointF &local, const QPointF &global); + QRectF titleBarRect(const QRectF &rect, bool &transposed, int &requiredPixels) const; void dontInteractiveMoveResize(); virtual QSizeF resizeIncrements() const;