From ef30575d374e8244420a56f3879962146b23b371 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 13 Dec 2023 12:43:27 +0000 Subject: [PATCH] client: Fix xdg shell setting only a minimum size hint An unbound maximum size is sent across the protocol as 0. We need to make this change before the check that the minimum size is less than the maximum size. This fixes having only a minimum size set. This bug is currently masked by the platform forcefully applying the minimum size. Pick-to: 6.6 Pick-to: 6.7 Change-Id: Ifca4fa01e4c2ac1c34aeb72db1584e4a868d50bc Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Vlad Zahorodnii --- .../xdg-shell/qwaylandxdgshell.cpp | 9 +-- tests/auto/wayland/xdgshell/tst_xdgshell.cpp | 59 ++++++++++++++++--- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index 57370f3595b..566a0ff47e9 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -424,15 +424,16 @@ void QWaylandXdgSurface::setSizeHints() const int minHeight = qMax(0, minSize.height()); int maxWidth = qMax(0, maxSize.width()); int maxHeight = qMax(0, maxSize.height()); - if (maxWidth == QWINDOWSIZE_MAX) - maxWidth = 0; - if (maxHeight == QWINDOWSIZE_MAX) - maxHeight = 0; // It will not change min/max sizes if invalid. if (minWidth > maxWidth || minHeight > maxHeight) return; + if (maxWidth == QWINDOWSIZE_MAX) + maxWidth = 0; + if (maxHeight == QWINDOWSIZE_MAX) + maxHeight = 0; + m_toplevel->set_min_size(minWidth, minHeight); m_toplevel->set_max_size(maxWidth, maxHeight); } diff --git a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp index edc1c0fea3a..a3e96d444d8 100644 --- a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp +++ b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp @@ -27,6 +27,7 @@ private slots: void switchPopups(); void hidePopupParent(); void pongs(); + void minMaxSize_data(); void minMaxSize(); void windowGeometry(); void foreignSurface(); @@ -609,12 +610,47 @@ void tst_xdgshell::pongs() QCOMPARE(pongSpy.first().at(0).toUInt(), serial); } +void tst_xdgshell::minMaxSize_data() +{ + QTest::addColumn("initialMinSize"); + QTest::addColumn("initialMaxSize"); + QTest::addColumn("nextMinSize"); + QTest::addColumn("nextMaxSize"); + QTest::addColumn("expectedInitialMinSize"); + QTest::addColumn("expectedInitialMaxSize"); + QTest::addColumn("expectedNextMinSize"); + QTest::addColumn("expectedNextMaxSize"); + + QTest::newRow("onlyMinSize") << QSize(50, 60) << QSize() << QSize(500, 600) << QSize() + << QSize(50, 60) << QSize(0, 0) << QSize(500, 600) << QSize(0, 0); + + QTest::newRow("onlyMaxSize") << QSize() << QSize(70, 80) << QSize() << QSize(700, 800) + << QSize(0,0 ) << QSize(70, 80) << QSize(0, 0) << QSize(700, 800); + + QTest::newRow("maxIsSentAsZero") << QSize() << QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX) << QSize() << QSize() + << QSize(0,0 ) << QSize(0, 0) << QSize(0, 0) << QSize(0, 0); + + + QTest::newRow("fullHints") << QSize(50, 60) << QSize(700, 800) << QSize(500, 600) << QSize(710, 810) + << QSize(50, 60) << QSize(700, 800) << QSize(500, 600) << QSize(710, 810); + + // setting a minimum above the maximum is not allowed, we should no-op + QTest::newRow("invalidResize") << QSize(50, 60) << QSize(100, 100) << QSize(500, 600) << QSize(100, 100) + << QSize(50, 60) << QSize(100, 100) << QSize(50, 60) << QSize(100, 100);} + void tst_xdgshell::minMaxSize() { + QFETCH(QSize, initialMinSize); + QFETCH(QSize, initialMaxSize); + + QFETCH(QSize, expectedInitialMinSize); + QFETCH(QSize, expectedInitialMaxSize); + QRasterWindow window; - window.setMinimumSize(QSize(100, 100)); - window.setMaximumSize(QSize(1000, 1000)); - window.resize(400, 320); + if (initialMinSize.isValid()) + window.setMinimumSize(initialMinSize); + if (initialMaxSize.isValid()) + window.setMaximumSize(initialMaxSize); window.show(); QCOMPOSITOR_TRY_VERIFY(xdgToplevel()); @@ -622,16 +658,21 @@ void tst_xdgshell::minMaxSize() // we don't roundtrip with our configuration the initial commit should be correct - QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.minSize, QSize(100, 100)); - QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.maxSize, QSize(1000, 1000)); + QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.minSize, expectedInitialMinSize); + QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.maxSize, expectedInitialMaxSize); - window.setMaximumSize(QSize(500, 400)); + QFETCH(QSize, nextMinSize); + QFETCH(QSize, expectedNextMinSize); + window.setMinimumSize(nextMinSize); window.update(); - QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.maxSize, QSize(500, 400)); + QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.minSize, expectedNextMinSize); - window.setMinimumSize(QSize(50, 40)); + QFETCH(QSize, nextMaxSize); + QFETCH(QSize, expectedNextMaxSize); + + window.setMaximumSize(nextMaxSize); window.update(); - QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.minSize, QSize(50, 40)); + QCOMPOSITOR_TRY_COMPARE(xdgToplevel()->m_committed.maxSize, expectedNextMaxSize); } void tst_xdgshell::windowGeometry()