summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiDe Zhang <zhangjide@uniontech.com>2023-09-20 17:15:25 +0800
committerJiDe Zhang <zhangjide@uniontech.com>2023-10-07 18:06:23 +0800
commite695a39519a7629c1549275a148cfb9ab99a07a9 (patch)
tree5cc7e12c4ce3fb241d0fa6126406619a42b43b68
parent5ba560801508aef2c9885c8fd58b912fed783238 (diff)
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>
-rw-r--r--src/client/qwaylandwindow.cpp46
-rw-r--r--src/client/qwaylandwindow_p.h1
2 files changed, 24 insertions, 23 deletions
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index 5171a8bb0..9991ade4f 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/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<QWaylandScreen *>(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/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
index 445a05b7f..5e064a642 100644
--- a/src/client/qwaylandwindow_p.h
+++ b/src/client/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;