diff --git a/src/wayland/surface_interface.cpp b/src/wayland/surface_interface.cpp index 5820dd680b..19a89d0f97 100644 --- a/src/wayland/surface_interface.cpp +++ b/src/wayland/surface_interface.cpp @@ -182,13 +182,20 @@ void SurfaceInterface::Private::commit() const bool inputRegionChanged = pending.inputIsSet; const bool scaleFactorChanged = current.scale != pending.scale; const bool transformFactorChanged = current.transform != pending.transform; + bool sizeChanged = false; auto buffer = current.buffer; if (bufferChanged) { + QSize oldSize; if (current.buffer) { + oldSize = current.buffer->size(); current.buffer->unref(); + QObject::disconnect(current.buffer, &BufferInterface::sizeChanged, q, &SurfaceInterface::sizeChanged); } if (pending.buffer) { pending.buffer->ref(); + QObject::connect(pending.buffer, &BufferInterface::sizeChanged, q, &SurfaceInterface::sizeChanged); + const QSize newSize = pending.buffer->size(); + sizeChanged = newSize.isValid() && newSize != oldSize; } buffer = pending.buffer; } @@ -226,6 +233,9 @@ void SurfaceInterface::Private::commit() emit q->unmapped(); } } + if (sizeChanged) { + emit q->sizeChanged(); + } } void SurfaceInterface::Private::damage(const QRect &rect) @@ -436,6 +446,16 @@ QPointer< SubSurfaceInterface > SurfaceInterface::subSurface() const return d->subSurface; } +QSize SurfaceInterface::size() const +{ + Q_D(); + // TODO: apply transform and scale to the buffer size + if (d->current.buffer) { + return d->current.buffer->size(); + } + return QSize(); +} + SurfaceInterface::Private *SurfaceInterface::d_func() const { return reinterpret_cast(d.data()); diff --git a/src/wayland/surface_interface.h b/src/wayland/surface_interface.h index a9b855c3ae..1eaa4f3590 100644 --- a/src/wayland/surface_interface.h +++ b/src/wayland/surface_interface.h @@ -45,6 +45,7 @@ class KWAYLANDSERVER_EXPORT SurfaceInterface : public Resource Q_PROPERTY(QRegion input READ input NOTIFY inputChanged) Q_PROPERTY(qint32 scale READ scale NOTIFY scaleChanged) Q_PROPERTY(KWayland::Server::OutputInterface::Transform transform READ transform NOTIFY transformChanged) + Q_PROPERTY(QSize size READ size NOTIFY sizeChanged) public: virtual ~SurfaceInterface(); @@ -58,6 +59,11 @@ public: OutputInterface::Transform transform() const; BufferInterface *buffer(); QPoint offset() const; + /** + * The size of the Surface. + * @since 5.3 + **/ + QSize size() const; /** * @returns The SubSurface for this Surface in case there is one. @@ -85,6 +91,10 @@ Q_SIGNALS: * Emitted when the Surface removes its content **/ void unmapped(); + /** + * @since 5.3 + **/ + void sizeChanged(); private: friend class CompositorInterface;