Commit d079f5da authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

[wayland] Keep the opposite corner still when resizing a window

Summary:
According to the xdg-shell spec, configure events carry the maximum
window geometry size. If a client wants to enforce aspect ratio, it
may attach a buffer with smaller size. We need to account for that
when determining frame geometry in the commit handler.

I'm targeting 5.18 branch.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26886
parent 72ca9268
......@@ -1369,6 +1369,7 @@ void TestXdgShellClient::testXdgWindowGeometryAttachBuffer()
Test::render(surface.data(), QSize(100, 50), Qt::blue);
QVERIFY(geometryChangedSpy.wait());
QCOMPARE(client->frameGeometry().topLeft(), oldPosition);
QEXPECT_FAIL("", "Ask on wayland-devel what effective window geometry should be here", Continue);
QCOMPARE(client->frameGeometry().size(), QSize(180, 80));
QCOMPARE(client->bufferGeometry().topLeft(), oldPosition - QPoint(10, 10));
QCOMPARE(client->bufferGeometry().size(), QSize(100, 50));
......
......@@ -1145,7 +1145,14 @@ void XdgShellClient::updatePendingGeometry()
}
//else serialId < m_lastAckedConfigureRequest and the state is now irrelevant and can be ignored
}
doSetGeometry(QRect(position, m_windowGeometry.size() + QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
QRect geometry = QRect(position, adjustedSize());
if (isMove()) {
geometry = adjustMoveGeometry(geometry);
}
if (isResize()) {
geometry = adjustResizeGeometry(geometry);
}
doSetGeometry(geometry);
updateMaximizeMode(maximizeMode);
}
......@@ -1994,4 +2001,46 @@ bool XdgShellClient::supportsWindowRules() const
return m_xdgShellSurface;
}
QRect XdgShellClient::adjustMoveGeometry(const QRect &rect) const
{
QRect geometry = rect;
geometry.moveTopLeft(moveResizeGeometry().topLeft());
return geometry;
}
QRect XdgShellClient::adjustResizeGeometry(const QRect &rect) const
{
QRect geometry = rect;
// We need to adjust frame geometry because configure events carry the maximum window geometry
// size. A client that has aspect ratio can attach a buffer with smaller size than the one in
// a configure event.
switch (moveResizePointerMode()) {
case PositionTopLeft:
geometry.moveRight(moveResizeGeometry().right());
geometry.moveBottom(moveResizeGeometry().bottom());
break;
case PositionTop:
case PositionTopRight:
geometry.moveLeft(moveResizeGeometry().left());
geometry.moveBottom(moveResizeGeometry().bottom());
break;
case PositionRight:
case PositionBottomRight:
case PositionBottom:
geometry.moveLeft(moveResizeGeometry().left());
geometry.moveTop(moveResizeGeometry().top());
break;
case PositionBottomLeft:
case PositionLeft:
geometry.moveRight(moveResizeGeometry().right());
geometry.moveTop(moveResizeGeometry().top());
break;
case PositionCenter:
Q_UNREACHABLE();
}
return geometry;
}
}
......@@ -190,6 +190,9 @@ private:
QRect determineBufferGeometry() const;
static void deleteClient(XdgShellClient *c);
QRect adjustMoveGeometry(const QRect &rect) const;
QRect adjustResizeGeometry(const QRect &rect) const;
KWayland::Server::XdgShellSurfaceInterface *m_xdgShellSurface;
KWayland::Server::XdgShellPopupInterface *m_xdgShellPopup;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment