Don't use QRect::bottom when applying virtual keyboard geometry

Bottom is unreliable because of "historical reasons" in Qt. So don't use
bottom, instead calculate the proper height and top manually.
This commit is contained in:
Arjen Hiemstra 2022-05-27 12:34:14 +02:00 committed by David Edmundson
parent 36f7bae36a
commit 083437d487
2 changed files with 6 additions and 5 deletions

View file

@ -906,7 +906,7 @@ void MoveResizeWindowTest::testResizeForVirtualKeyboard()
Test::render(surface.data(), toplevelConfigureRequestedSpy.last().first().toSize(), Qt::blue);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->frameGeometry(), QRect(100, 0, 500, 101));
QCOMPARE(window->frameGeometry(), QRect(100, 0, 500, 100));
window->setVirtualKeyboardGeometry(QRect());
QVERIFY(surfaceConfigureRequestedSpy.wait());
@ -950,7 +950,7 @@ void MoveResizeWindowTest::testResizeForVirtualKeyboardWithMaximize()
// render at the new size
Test::render(surface.data(), toplevelConfigureRequestedSpy.last().first().toSize(), Qt::blue);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->frameGeometry(), QRect(100, 0, 500, 101));
QCOMPARE(window->frameGeometry(), QRect(100, 0, 500, 100));
window->setMaximize(true, true);
QVERIFY(surfaceConfigureRequestedSpy.wait());
@ -1003,7 +1003,7 @@ void MoveResizeWindowTest::testResizeForVirtualKeyboardWithFullScreen()
// render at the new size
Test::render(surface.data(), toplevelConfigureRequestedSpy.last().first().toSize(), Qt::blue);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->frameGeometry(), QRect(100, 0, 500, 101));
QCOMPARE(window->frameGeometry(), QRect(100, 0, 500, 100));
window->setFullScreen(true, true);
QVERIFY(surfaceConfigureRequestedSpy.wait());

View file

@ -3264,8 +3264,9 @@ void Window::setVirtualKeyboardGeometry(const QRect &geo)
const QRect availableArea = workspace()->clientArea(MaximizeArea, this);
QRect newWindowGeometry = (maximizeMode() & MaximizeHorizontal) ? availableArea : m_keyboardGeometryRestore;
newWindowGeometry.moveBottom(geo.top());
newWindowGeometry.setTop(qMax(newWindowGeometry.top(), availableArea.top()));
newWindowGeometry.setHeight(std::min(newWindowGeometry.height(), geo.top() - availableArea.top()));
newWindowGeometry.moveTop(std::max(geo.top() - newWindowGeometry.height(), availableArea.top()));
newWindowGeometry = newWindowGeometry.intersected(availableArea);
moveResize(newWindowGeometry);
}