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,17 +1383,28 @@ 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);
}
if (scale != mScale) { void QWaylandWindow::setScale(qreal newScale)
mScale = scale; {
QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window()); if (qFuzzyCompare(mScale, newScale))
if (mSurface) { return;
if (mViewport) mScale = newScale;
updateViewport();
else if (mSurface->version() >= 3) QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window());
mSurface->set_buffer_scale(std::ceil(mScale)); if (mSurface) {
} if (mViewport)
ensureSize(); updateViewport();
else if (mSurface->version() >= 3)
mSurface->set_buffer_scale(std::ceil(mScale));
}
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;