QWaylandWindow: add QWaylandWindow::setScale

The logic for update window's scale is scattered in multiple places,
we should unify their behavior.

Change-Id: Ic8ba20fdbc44942aed9b4bd0b0b12dad7bee1719
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
JiDe Zhang 2023-09-20 17:15:25 +08:00
parent 646bca0c74
commit ad3bc01d35
2 changed files with 24 additions and 23 deletions

View File

@ -107,19 +107,8 @@ void QWaylandWindow::initWindow()
connect(mFractionalScale.data(), &QWaylandFractionalScale::preferredScaleChanged, this, [this](qreal preferredScale) { connect(mFractionalScale.data(), &QWaylandFractionalScale::preferredScaleChanged, this, [this](qreal preferredScale) {
preferredScale = std::max(1.0, preferredScale); preferredScale = std::max(1.0, preferredScale);
if (mScale == preferredScale) { Q_ASSERT(mViewport);
return; setScale(preferredScale);
}
mScale = preferredScale;
QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window());
ensureSize();
if (mViewport)
updateViewport();
if (isExposed()) {
// redraw at the new DPR
window()->requestUpdate();
sendExposeEvent(QRect(QPoint(), geometry().size()));
}
}); });
} }
@ -1394,9 +1383,15 @@ void QWaylandWindow::handleScreensChanged()
return; return;
int scale = mLastReportedScreen->isPlaceholder() ? 1 : static_cast<QWaylandScreen *>(mLastReportedScreen)->scale(); int scale = mLastReportedScreen->isPlaceholder() ? 1 : static_cast<QWaylandScreen *>(mLastReportedScreen)->scale();
setScale(scale);
}
void QWaylandWindow::setScale(qreal newScale)
{
if (qFuzzyCompare(mScale, newScale))
return;
mScale = newScale;
if (scale != mScale) {
mScale = scale;
QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window()); QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window());
if (mSurface) { if (mSurface) {
if (mViewport) if (mViewport)
@ -1405,6 +1400,11 @@ void QWaylandWindow::handleScreensChanged()
mSurface->set_buffer_scale(std::ceil(mScale)); mSurface->set_buffer_scale(std::ceil(mScale));
} }
ensureSize(); ensureSize();
if (isExposed()) {
// redraw at the new DPR
window()->requestUpdate();
sendExposeEvent(QRect(QPoint(), geometry().size()));
} }
} }

View File

@ -346,6 +346,7 @@ private:
void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
void handleScreensChanged(); void handleScreensChanged();
void setScale(qreal newScale);
void sendRecursiveExposeEvent(); void sendRecursiveExposeEvent();
QWaylandWindow *closestTransientParent() const; QWaylandWindow *closestTransientParent() const;