From 9d6df1f92a7b9b66765d2ddd7f06e909a9624186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 31 Aug 2015 14:43:09 +0200 Subject: [PATCH] [server] Add a static OutputInterface::get(wl_resource*) Allows to retrieve the OutputInterface* for a given native wl_resource. To support this we need to track the resources bound for each Output. --- src/wayland/output_interface.cpp | 31 +++++++++++++++++++++++++++++++ src/wayland/output_interface.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/wayland/output_interface.cpp b/src/wayland/output_interface.cpp index ccf305d19a..e295eb6ab7 100644 --- a/src/wayland/output_interface.cpp +++ b/src/wayland/output_interface.cpp @@ -21,6 +21,8 @@ License along with this library. If not, see . #include "global_p.h" #include "display.h" +#include + #include namespace KWayland @@ -38,6 +40,7 @@ public: uint32_t version; }; Private(OutputInterface *q, Display *d); + ~Private(); void sendMode(wl_resource *resource, const Mode &mode); void sendDone(const ResourceData &data); void updateGeometry(); @@ -53,6 +56,8 @@ public: QList modes; QList resources; + static OutputInterface *get(wl_resource *native); + private: static void unbind(wl_resource *resource); void bind(wl_client *client, uint32_t version, uint32_t id) override; @@ -62,12 +67,33 @@ private: void sendScale(const ResourceData &data); OutputInterface *q; + static QVector s_privates; }; +QVector OutputInterface::Private::s_privates; + OutputInterface::Private::Private(OutputInterface *q, Display *d) : Global::Private(d, &wl_output_interface, s_version) , q(q) { + s_privates << this; +} + +OutputInterface::Private::~Private() +{ + s_privates.removeAll(this); +} + +OutputInterface *OutputInterface::Private::get(wl_resource *native) +{ + for (auto it = s_privates.constBegin(); it != s_privates.constEnd(); ++it) { + const auto &resources = (*it)->resources; + auto rit = std::find_if(resources.begin(), resources.end(), [native] (const ResourceData &data) { return data.resource == native; }); + if (rit != resources.end()) { + return (*it)->q; + } + } + return nullptr; } OutputInterface::OutputInterface(Display *display, QObject *parent) @@ -432,6 +458,11 @@ QList< OutputInterface::Mode > OutputInterface::modes() const return d->modes; } +OutputInterface *OutputInterface::get(wl_resource* native) +{ + return Private::get(native); +} + OutputInterface::Private *OutputInterface::d_func() const { return reinterpret_cast(d.data()); diff --git a/src/wayland/output_interface.h b/src/wayland/output_interface.h index 080ec7f786..56a8845e4c 100644 --- a/src/wayland/output_interface.h +++ b/src/wayland/output_interface.h @@ -100,6 +100,8 @@ public: void addMode(const QSize &size, ModeFlags flags = ModeFlags(), int refreshRate = 60000); void setCurrentMode(const QSize &size, int refreshRate = 60000); + static OutputInterface *get(wl_resource *native); + Q_SIGNALS: void physicalSizeChanged(const QSize&); void globalPositionChanged(const QPoint&);