From ad3bc01d3547e09d39ad542870ff76b8c299cc41 Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Wed, 20 Sep 2023 17:15:25 +0800 Subject: [PATCH] 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 --- .../platforms/wayland/qwaylandwindow.cpp | 46 +++++++++---------- .../platforms/wayland/qwaylandwindow_p.h | 1 + 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 5171a8bb053..9991ade4ffe 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -107,19 +107,8 @@ void QWaylandWindow::initWindow() connect(mFractionalScale.data(), &QWaylandFractionalScale::preferredScaleChanged, this, [this](qreal preferredScale) { preferredScale = std::max(1.0, preferredScale); - if (mScale == preferredScale) { - return; - } - mScale = preferredScale; - QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window()); - ensureSize(); - if (mViewport) - updateViewport(); - if (isExposed()) { - // redraw at the new DPR - window()->requestUpdate(); - sendExposeEvent(QRect(QPoint(), geometry().size())); - } + Q_ASSERT(mViewport); + setScale(preferredScale); }); } @@ -1394,17 +1383,28 @@ void QWaylandWindow::handleScreensChanged() return; int scale = mLastReportedScreen->isPlaceholder() ? 1 : static_cast(mLastReportedScreen)->scale(); + setScale(scale); +} - if (scale != mScale) { - mScale = scale; - QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window()); - if (mSurface) { - if (mViewport) - updateViewport(); - else if (mSurface->version() >= 3) - mSurface->set_buffer_scale(std::ceil(mScale)); - } - ensureSize(); +void QWaylandWindow::setScale(qreal newScale) +{ + if (qFuzzyCompare(mScale, newScale)) + return; + mScale = newScale; + + QWindowSystemInterface::handleWindowDevicePixelRatioChanged(window()); + if (mSurface) { + if (mViewport) + 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())); } } diff --git a/src/plugins/platforms/wayland/qwaylandwindow_p.h b/src/plugins/platforms/wayland/qwaylandwindow_p.h index 445a05b7f43..5e064a642f3 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow_p.h +++ b/src/plugins/platforms/wayland/qwaylandwindow_p.h @@ -346,6 +346,7 @@ private: void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); void handleScreensChanged(); + void setScale(qreal newScale); void sendRecursiveExposeEvent(); QWaylandWindow *closestTransientParent() const;