[kwin_wayland] Track all created Wayland::Surface
Add static accessors to get all Surfaces and the Surface for a wl_surface to Wayland::Surface.
This commit is contained in:
parent
17c1eaddef
commit
df548cc400
2 changed files with 26 additions and 0 deletions
|
@ -27,15 +27,19 @@ namespace KWin
|
|||
namespace Wayland
|
||||
{
|
||||
|
||||
QList<Surface*> Surface::s_surfaces = QList<Surface*>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,12 +62,16 @@ public:
|
|||
|
||||
static void frameCallback(void *data, wl_callback *callback, uint32_t time);
|
||||
|
||||
static const QList<Surface*> &all();
|
||||
static Surface *get(wl_surface *native);
|
||||
|
||||
Q_SIGNALS:
|
||||
void frameRendered();
|
||||
|
||||
private:
|
||||
void handleFrameCallback();
|
||||
static const wl_callback_listener s_listener;
|
||||
static QList<Surface*> s_surfaces;
|
||||
wl_surface *m_surface;
|
||||
bool m_frameCallbackInstalled;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue