From df548cc400af36b362dea1f8957fb483d7303a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 22 Aug 2014 11:10:18 +0200 Subject: [PATCH] [kwin_wayland] Track all created Wayland::Surface Add static accessors to get all Surfaces and the Surface for a wl_surface to Wayland::Surface. --- src/wayland/surface.cpp | 22 ++++++++++++++++++++++ src/wayland/surface.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/src/wayland/surface.cpp b/src/wayland/surface.cpp index 28c1178ca9..e190f8feb5 100644 --- a/src/wayland/surface.cpp +++ b/src/wayland/surface.cpp @@ -27,15 +27,19 @@ namespace KWin namespace Wayland { +QList Surface::s_surfaces = QList(); + Surface::Surface(QObject *parent) : QObject(parent) , m_surface(nullptr) , m_frameCallbackInstalled(false) { + s_surfaces << this; } Surface::~Surface() { + s_surfaces.removeAll(this); release(); } @@ -121,5 +125,23 @@ void Surface::attachBuffer(wl_buffer *buffer, const QPoint &offset) wl_surface_attach(m_surface, buffer, offset.x(), offset.y()); } +Surface *Surface::get(wl_surface *native) +{ + auto it = std::find_if(s_surfaces.constBegin(), s_surfaces.constEnd(), + [native](Surface *s) { + return s->m_surface == native; + } + ); + if (it != s_surfaces.constEnd()) { + return *(it); + } + return nullptr; +} + +const QList< Surface* > &Surface::all() +{ + return s_surfaces; +} + } } diff --git a/src/wayland/surface.h b/src/wayland/surface.h index ecd93ad812..ff2fab5eb1 100644 --- a/src/wayland/surface.h +++ b/src/wayland/surface.h @@ -62,12 +62,16 @@ public: static void frameCallback(void *data, wl_callback *callback, uint32_t time); + static const QList &all(); + static Surface *get(wl_surface *native); + Q_SIGNALS: void frameRendered(); private: void handleFrameCallback(); static const wl_callback_listener s_listener; + static QList s_surfaces; wl_surface *m_surface; bool m_frameCallbackInstalled; };