diff --git a/autotests/client/test_wayland_output.cpp b/autotests/client/test_wayland_output.cpp --- a/autotests/client/test_wayland_output.cpp +++ b/autotests/client/test_wayland_output.cpp @@ -185,7 +185,10 @@ QSignalSpy outputChanged(&output, SIGNAL(changed())); QVERIFY(outputChanged.isValid()); - output.setup(registry.bindOutput(announced.first().first().value(), announced.first().last().value())); + auto o = registry.bindOutput(announced.first().first().value(), announced.first().last().value()); + QVERIFY(!KWayland::Client::Output::get(o)); + output.setup(o); + QCOMPARE(KWayland::Client::Output::get(o), &output); wl_display_flush(m_connection->display()); QVERIFY(outputChanged.wait()); diff --git a/src/client/output.h b/src/client/output.h --- a/src/client/output.h +++ b/src/client/output.h @@ -198,6 +198,12 @@ **/ EventQueue *eventQueue() const; + /** + * @returns The Output for the @p native wl_output. @c null if there is no Output for it. + * @since 5.26 + **/ + static Output *get(wl_output *native); + Q_SIGNALS: /** * Emitted whenever at least one of the data changed. diff --git a/src/client/output.cpp b/src/client/output.cpp --- a/src/client/output.cpp +++ b/src/client/output.cpp @@ -40,6 +40,7 @@ { public: Private(Output *q); + ~Private(); void setup(wl_output *o); WaylandPointer output; @@ -54,6 +55,8 @@ Modes modes; Modes::iterator currentMode = modes.end(); + static Output *get(wl_output *o); + private: static void geometryCallback(void *data, wl_output *output, int32_t x, int32_t y, int32_t physicalWidth, int32_t physicalHeight, int32_t subPixel, @@ -72,11 +75,35 @@ Output *q; static struct wl_output_listener s_outputListener; + + static QVector s_allOutputs; }; +QVector Output::Private::s_allOutputs; + Output::Private::Private(Output *q) : q(q) { + s_allOutputs << this; +} + +Output::Private::~Private() +{ + s_allOutputs.removeOne(this); +} + +Output *Output::Private::get(wl_output *o) +{ + auto it = std::find_if(s_allOutputs.constBegin(), s_allOutputs.constEnd(), + [o] (Private *p) { + const wl_output *reference = p->output; + return reference == o; + } + ); + if (it != s_allOutputs.constEnd()) { + return (*it)->q; + } + return nullptr; } void Output::Private::setup(wl_output *o) @@ -358,5 +385,10 @@ return d->output; } +Output *Output::get(wl_output *o) +{ + return Private::get(o); +} + } }