diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-08-23 15:01:09 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-08-30 11:10:09 +0000 |
commit | bc7e69b176816536bbd0a0ca3c4fd83b1ba160cd (patch) | |
tree | 9c7d5ce1466b26961ad748e218cfae9be476ef70 | |
parent | 2af5dce3e7ea3e341720c4212e1d0a12ca68f41c (diff) |
Compositor: Update WaylandQuickItem size on new dpr or scaleFactor
updateSize() depends on both screen devicePixelRatio and output scaleFactor.
Make sure to call it when they change.
This still doesn't handle all cases, because there is no signal for when a
screen device pixel ratio changes, but we update when we get a new screen,
which should be good enough in most cases
Change-Id: I4550cf580d4821e4b0f4da0d2eb7bb8d9ab823cf
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem.cpp | 21 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem.h | 1 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandquickitem_p.h | 2 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp index 8480db6f4..7f0685fcf 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.cpp +++ b/src/compositor/compositor_api/qwaylandquickitem.cpp @@ -1169,12 +1169,14 @@ void QWaylandQuickItem::updateWindow() if (d->connectedWindow) { disconnect(d->connectedWindow, &QQuickWindow::beforeSynchronizing, this, &QWaylandQuickItem::beforeSync); + disconnect(d->connectedWindow, &QQuickWindow::screenChanged, this, &QWaylandQuickItem::updateSize); } d->connectedWindow = newWindow; if (d->connectedWindow) { connect(d->connectedWindow, &QQuickWindow::beforeSynchronizing, this, &QWaylandQuickItem::beforeSync, Qt::DirectConnection); + connect(d->connectedWindow, &QQuickWindow::screenChanged, this, &QWaylandQuickItem::updateSize); // new screen may have new dpr } if (compositor() && d->connectedWindow) { @@ -1182,6 +1184,25 @@ void QWaylandQuickItem::updateWindow() Q_ASSERT(output); d->view->setOutput(output); } + + updateSize(); // because scaleFactor depends on devicePixelRatio, which may be different for the new window +} + +void QWaylandQuickItem::updateOutput() +{ + Q_D(QWaylandQuickItem); + if (d->view->output() == d->connectedOutput) + return; + + if (d->connectedOutput) + disconnect(d->connectedOutput, &QWaylandOutput::scaleFactorChanged, this, &QWaylandQuickItem::updateSize); + + d->connectedOutput = d->view->output(); + + if (d->connectedOutput) + connect(d->connectedOutput, &QWaylandOutput::scaleFactorChanged, this, &QWaylandQuickItem::updateSize); + + updateSize(); } void QWaylandQuickItem::beforeSync() diff --git a/src/compositor/compositor_api/qwaylandquickitem.h b/src/compositor/compositor_api/qwaylandquickitem.h index aac88236c..653440aed 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.h +++ b/src/compositor/compositor_api/qwaylandquickitem.h @@ -160,6 +160,7 @@ private Q_SLOTS: void updateSize(); void updateBuffer(bool hasBuffer); void updateWindow(); + void updateOutput(); void beforeSync(); void handleSubsurfaceAdded(QWaylandSurface *childSurface); void handleSubsurfacePosition(const QPoint &pos); diff --git a/src/compositor/compositor_api/qwaylandquickitem_p.h b/src/compositor/compositor_api/qwaylandquickitem_p.h index ee8ea5442..51b41c9f6 100644 --- a/src/compositor/compositor_api/qwaylandquickitem_p.h +++ b/src/compositor/compositor_api/qwaylandquickitem_p.h @@ -128,6 +128,7 @@ public: QObject::connect(view.data(), &QWaylandView::surfaceChanged, q, &QWaylandQuickItem::handleSurfaceChanged); QObject::connect(view.data(), &QWaylandView::surfaceDestroyed, q, &QWaylandQuickItem::surfaceDestroyed); QObject::connect(view.data(), &QWaylandView::outputChanged, q, &QWaylandQuickItem::outputChanged); + QObject::connect(view.data(), &QWaylandView::outputChanged, q, &QWaylandQuickItem::updateOutput); QObject::connect(view.data(), &QWaylandView::bufferLockedChanged, q, &QWaylandQuickItem::bufferLockedChanged); QObject::connect(view.data(), &QWaylandView::allowDiscardFrontBufferChanged, q, &QWaylandQuickItem::allowDiscardFrontBuffer); @@ -174,6 +175,7 @@ public: QMatrix4x4 lastMatrix; QQuickWindow *connectedWindow = nullptr; + QWaylandOutput *connectedOutput = nullptr; QWaylandSurface::Origin origin = QWaylandSurface::OriginTopLeft; QPointer<QObject> subsurfaceHandler; QVector<QWaylandSeat *> touchingSeats; |