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 <davidedmundson@kde.org>
This commit is contained in:
Jan Grulich 2021-03-17 15:45:54 +01:00
parent 1f2c1062c6
commit 5a8e861807

View File

@ -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));
}
/*!