From 40c52035a8fc9aff5e682ff82f134fc84fde3122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 21 Feb 2015 09:30:22 +0100 Subject: [PATCH] [wayland] Better track if WaylandBackend is ready The WaylandBackend emits a signal when the backend is ready. If a user connects to it after it became ready, it will never get notified. Therefore the WaylandBackend tracks also whether it is ready and implements connectNotify to emit the signal again if a user connects and the backend is already ready. Users of the signal need to disconnect if they cannot handle it being invoked multiple times. So far the only user does handle this properly. --- wayland_backend.cpp | 11 +++++++++++ wayland_backend.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/wayland_backend.cpp b/wayland_backend.cpp index 93d352c22a..f2bd79d5fa 100644 --- a/wayland_backend.cpp +++ b/wayland_backend.cpp @@ -44,6 +44,7 @@ along with this program. If not, see . #include #include #include +#include #include // xcb #include @@ -552,6 +553,7 @@ void WaylandBackend::initConnection() Qt::QueuedConnection); connect(m_connectionThreadObject, &ConnectionThread::connectionDied, this, [this]() { + m_ready = false; emit systemCompositorDied(); m_cursorTracker.reset(); m_seat.reset(); @@ -652,9 +654,18 @@ void WaylandBackend::checkBackendReady() return; } disconnect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady); + m_ready = true; emit backendReady(); } +void WaylandBackend::connectNotify(const QMetaMethod &signal) +{ + if (m_ready && signal == QMetaMethod::fromSignal(&WaylandBackend::backendReady)) { + // backend is already ready, let's emit the signal + signal.invoke(this, Qt::QueuedConnection); + } +} + } } // KWin diff --git a/wayland_backend.h b/wayland_backend.h index 635d2b51aa..f1a6bbcecd 100644 --- a/wayland_backend.h +++ b/wayland_backend.h @@ -190,6 +190,10 @@ public: KWayland::Client::Surface *surface() const; QSize shellSurfaceSize() const; void installCursorImage(Qt::CursorShape shape); + +protected: + void connectNotify(const QMetaMethod &signal) override; + Q_SIGNALS: void shellSurfaceSizeChanged(const QSize &size); void systemCompositorDied(); @@ -217,6 +221,7 @@ private: KWayland::Client::FullscreenShell *m_fullscreenShell; KWayland::Client::SubCompositor *m_subCompositor; WaylandCursor *m_cursor; + bool m_ready = false; KWIN_SINGLETON(WaylandBackend) };