From e11df5b4f5eef10220b77bce7125249a62c9e686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 22 Aug 2014 13:48:50 +0200 Subject: [PATCH] [kwin_wayland] Keep the size in Surface Technically the Surface itself does not have a size, it's the ShellSurface or the size of the FullScreenShell's Output. But it simplifies a lot if we keep track of the size in the Surface as that way we can hide the fact which kind of Shell is used. The user of the Surface must connect either the FullscreenShell's Output or the ShellSurface to set the size on the Surface. --- autotests/wayland_client/test_wayland_surface.cpp | 9 +++++++++ wayland_client/surface.cpp | 9 +++++++++ wayland_client/surface.h | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/autotests/wayland_client/test_wayland_surface.cpp b/autotests/wayland_client/test_wayland_surface.cpp index a2936feb3c..0c59895641 100644 --- a/autotests/wayland_client/test_wayland_surface.cpp +++ b/autotests/wayland_client/test_wayland_surface.cpp @@ -118,6 +118,15 @@ void TestWaylandSurface::testStaticAccessor() QCOMPARE(KWin::Wayland::Surface::all().first(), s1); QCOMPARE(KWin::Wayland::Surface::get(*s1), s1); + QVERIFY(!s1->size().isValid()); + QSignalSpy sizeChangedSpy(s1, SIGNAL(sizeChanged(QSize))); + QVERIFY(sizeChangedSpy.isValid()); + const QSize testSize(200, 300); + s1->setSize(testSize); + QCOMPARE(s1->size(), testSize); + QCOMPARE(sizeChangedSpy.count(), 1); + QCOMPARE(sizeChangedSpy.first().first().toSize(), testSize); + // add another surface KWin::Wayland::Surface *s2 = compositor.createSurface(); QCOMPARE(KWin::Wayland::Surface::all().count(), 2); diff --git a/wayland_client/surface.cpp b/wayland_client/surface.cpp index e190f8feb5..f897d24f14 100644 --- a/wayland_client/surface.cpp +++ b/wayland_client/surface.cpp @@ -125,6 +125,15 @@ void Surface::attachBuffer(wl_buffer *buffer, const QPoint &offset) wl_surface_attach(m_surface, buffer, offset.x(), offset.y()); } +void Surface::setSize(const QSize &size) +{ + if (m_size == size) { + return; + } + m_size = size; + emit sizeChanged(m_size); +} + Surface *Surface::get(wl_surface *native) { auto it = std::find_if(s_surfaces.constBegin(), s_surfaces.constEnd(), diff --git a/wayland_client/surface.h b/wayland_client/surface.h index ff2fab5eb1..fffdb331f5 100644 --- a/wayland_client/surface.h +++ b/wayland_client/surface.h @@ -22,6 +22,7 @@ along with this program. If not, see . #include #include +#include #include @@ -52,6 +53,10 @@ public: void damage(const QRect &rect); void damage(const QRegion ®ion); void attachBuffer(wl_buffer *buffer, const QPoint &offset = QPoint()); + void setSize(const QSize &size); + const QSize &size() const { + return m_size; + } operator wl_surface*() { return m_surface; @@ -67,6 +72,7 @@ public: Q_SIGNALS: void frameRendered(); + void sizeChanged(const QSize&); private: void handleFrameCallback(); @@ -74,6 +80,7 @@ private: static QList s_surfaces; wl_surface *m_surface; bool m_frameCallbackInstalled; + QSize m_size; }; }