wasm: fix respecting minimum size of QWasmWindow

Minimum size of QWasmWindow was not properly enforced.
Make sure that minimumu size constraints are respected
when the QWasmWindow is created, resized manually or
changed by setGeometry().

Fixes: QTBUG-111162
Change-Id: I2984b0836b5b53f9163275153d734cb1d81ef3b6
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
bb10
Piotr Wierciński 2023-02-23 14:34:48 +01:00
parent 9e31631557
commit 073848f3c4
2 changed files with 11 additions and 6 deletions

View File

@ -187,14 +187,16 @@ void QWasmWindow::initialize()
{
QRect rect = windowGeometry();
constexpr int minSizeBoundForDialogsAndRegularWindows = 100;
const auto windowFlags = window()->flags();
const int systemMinSizeLowerBound = windowFlags.testAnyFlags(Qt::Window | Qt::Dialog)
? minSizeBoundForDialogsAndRegularWindows
: 0;
const bool shouldRestrictMinSize =
!windowFlags.testFlag(Qt::FramelessWindowHint) && !windowIsPopupType(windowFlags);
const bool isMinSizeUninitialized = window()->minimumSize() == QSize(0, 0);
const QSize minimumSize(std::max(windowMinimumSize().width(), systemMinSizeLowerBound),
std::max(windowMinimumSize().height(), systemMinSizeLowerBound));
if (shouldRestrictMinSize && isMinSizeUninitialized)
window()->setMinimumSize(QSize(minSizeForRegularWindows, minSizeForRegularWindows));
const QSize minimumSize = windowMinimumSize();
const QSize maximumSize = windowMaximumSize();
const QSize targetSize = !rect.isEmpty() ? rect.size() : minimumSize;
@ -256,6 +258,8 @@ void QWasmWindow::setGeometry(const QRect &rect)
QRect result(rect);
result.moveTop(std::max(std::min(rect.y(), screenGeometry.bottom()),
screenGeometry.y() + margins.top()));
result.setSize(
result.size().expandedTo(windowMinimumSize()).boundedTo(windowMaximumSize()));
return result;
})();
m_nonClientArea->onClientAreaWidthChange(clientAreaRect.width());

View File

@ -92,6 +92,7 @@ public:
private:
friend class QWasmScreen;
static constexpr auto minSizeForRegularWindows = 100;
void invalidate();
bool hasFrame() const;