From a3c665b65aa241c3ca56f3311e9380e8e434a6f2 Mon Sep 17 00:00:00 2001 From: Inho Lee Date: Tue, 9 May 2023 10:58:13 +0200 Subject: [PATCH] Apply only valid min/max sizes When setting min/max sizes, the minimum size can be larger than the maximum size. In that case, the size hint won't be applied to the geometry. Setting size hint will be pending until the min/max pair is valid and the actual geometry will not be changed with the invalid size hint. Fixes: QTBUG-113233 Pick-to: 6.5 6.5.1 6.2 Change-Id: Ia05944e8342e7f8d794aee7883e0637a4c711c9d Reviewed-by: David Edmundson --- .../shellintegration/xdg-shell/qwaylandxdgshell.cpp | 12 ++++++++---- src/plugins/platforms/wayland/qwaylandwindow.cpp | 12 +++++++++--- 2 files changed, 17 insertions(+), 7 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 bf6eb2d0313..a16fd8cc770 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -410,14 +410,18 @@ void QWaylandXdgSurface::setSizeHints() if (m_toplevel && m_window) { const int minWidth = qMax(0, m_window->windowMinimumSize().width()); const int minHeight = qMax(0, m_window->windowMinimumSize().height()); - m_toplevel->set_min_size(minWidth, minHeight); - - int maxWidth = qMax(minWidth, m_window->windowMaximumSize().width()); + int maxWidth = qMax(0, m_window->windowMaximumSize().width()); + int maxHeight = qMax(0, m_window->windowMaximumSize().height()); if (maxWidth == QWINDOWSIZE_MAX) maxWidth = 0; - int maxHeight = qMax(minHeight, m_window->windowMaximumSize().height()); if (maxHeight == QWINDOWSIZE_MAX) maxHeight = 0; + + // It will not change min/max sizes if invalid. + if (minWidth > maxHeight || minHeight > maxHeight) + return; + + m_toplevel->set_min_size(minWidth, minHeight); m_toplevel->set_max_size(maxWidth, maxHeight); } } diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 7634aedd6e9..4ca2d8e6ffc 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -394,9 +394,15 @@ void QWaylandWindow::setGeometry_helper(const QRect &rect) { QSize minimum = windowMinimumSize(); QSize maximum = windowMaximumSize(); - QPlatformWindow::setGeometry(QRect(rect.x(), rect.y(), - qBound(minimum.width(), rect.width(), maximum.width()), - qBound(minimum.height(), rect.height(), maximum.height()))); + int width = windowGeometry().width(); + int height = windowGeometry().height(); + if (minimum.width() <= maximum.width() + && minimum.height() <= maximum.height()) { + width = qBound(minimum.width(), rect.width(), maximum.width()); + height = qBound(minimum.height(), rect.height(), maximum.height()); + } + + QPlatformWindow::setGeometry(QRect(rect.x(), rect.y(), width, height)); if (mViewport) updateViewport();