From 5a8e8618075b014f9cd7fd062e19573d69b36ec1 Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Wed, 17 Mar 2021 15:45:54 +0100 Subject: [PATCH] Client: get correct window content geometry We have to apply geometry where we don't include shadows, because we need them to be ignored in some scenarios. Also, with geometry being already shrunk by the size of shadow margins, we have to avoid doing it again, otherwise we can accidentally make our window smaller every time we update its size or state. Change-Id: I0e26ee1be8d918913125ee7f7c97de56ccc797cf Reviewed-by: David Edmundson --- src/plugins/platforms/wayland/qwaylandwindow.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 4d59a2b7802..27a9e562825 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -374,7 +374,7 @@ void QWaylandWindow::setGeometry(const QRect &rect) sendExposeEvent(exposeGeometry); if (mShellSurface && isExposed()) - mShellSurface->setWindowGeometry(QRect(QPoint(), surfaceSize())); + mShellSurface->setWindowGeometry(windowContentGeometry()); if (isOpaque() && mMask.isEmpty()) setOpaqueArea(rect); @@ -383,6 +383,16 @@ void QWaylandWindow::setGeometry(const QRect &rect) void QWaylandWindow::resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset) { QMargins margins = frameMargins(); + + // Exclude shadows from margins once they are excluded from window geometry + // 1) First resizeFromApplyConfigure() call will have sizeWithMargins equal to surfaceSize() + // which has full margins (shadows included). + // 2) Following resizeFromApplyConfigure() calls should have sizeWithMargins equal to + // windowContentGeometry() which excludes shadows, therefore in this case we have to + // exclude them too in order not to accidentally apply smaller size to the window. + if (mWindowDecoration && (sizeWithMargins != surfaceSize())) + margins = mWindowDecoration->margins(QWaylandAbstractDecoration::ShadowsExcluded); + int widthWithoutMargins = qMax(sizeWithMargins.width() - (margins.left() + margins.right()), 1); int heightWithoutMargins = qMax(sizeWithMargins.height() - (margins.top() + margins.bottom()), 1); QRect geometry(windowGeometry().topLeft(), QSize(widthWithoutMargins, heightWithoutMargins)); @@ -708,7 +718,7 @@ QRect QWaylandWindow::windowContentGeometry() const if (mWindowDecoration) shadowMargins = mWindowDecoration->margins(QWaylandAbstractDecoration::ShadowsOnly); - return QRect(QPoint(shadowMargins.left(), shadowMargins.right()), surfaceSize().shrunkBy(shadowMargins)); + return QRect(QPoint(shadowMargins.left(), shadowMargins.top()), surfaceSize().shrunkBy(shadowMargins)); } /*!