From 07c972b6d4a6d4e948d16305d4824c5f062cf6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 9 Feb 2015 16:08:53 +0100 Subject: [PATCH] [wayland] Add a SurfaceInterface to Toplevel Adds the SurfaceInterface identified by the surface id we get from Xwayland. This allows in an easier way to map a Toplevel to a Wayland surface and will also be useful for Wayland clients. --- events.cpp | 7 +++++++ toplevel.h | 29 +++++++++++++++++++++++++++++ wayland_server.cpp | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/events.cpp b/events.cpp index 2575b63ce5..24dab56c11 100644 --- a/events.cpp +++ b/events.cpp @@ -66,6 +66,10 @@ along with this program. If not, see . #include "killwindow.h" #include "x11eventfilter.h" +#if HAVE_WAYLAND +#include +#endif + #ifndef XCB_GE_GENERIC #define XCB_GE_GENERIC 35 typedef struct xcb_ge_generic_event_t { @@ -1693,6 +1697,9 @@ void Toplevel::clientMessageEvent(xcb_client_message_event_t *e) { if (e->type == atoms->wl_surface_id) { m_surfaceId = e->data.data32[0]; +#if HAVE_WAYLAND + m_surface = KWayland::Server::SurfaceInterface::get(m_surfaceId); +#endif emit surfaceIdChanged(m_surfaceId); } } diff --git a/toplevel.h b/toplevel.h index 10b8b59af4..1ec0d129dc 100644 --- a/toplevel.h +++ b/toplevel.h @@ -41,6 +41,16 @@ along with this program. If not, see . // c++ #include +#if HAVE_WAYLAND +namespace KWayland +{ +namespace Server +{ +class SurfaceInterface; +} +} +#endif + namespace KWin { @@ -344,6 +354,10 @@ public: void setSkipCloseAnimation(bool set); quint32 surfaceId() const; +#if HAVE_WAYLAND + KWayland::Server::SurfaceInterface *surface() const; + void setSurface(KWayland::Server::SurfaceInterface *surface); +#endif virtual void sendPointerMoveEvent(const QPointF &globalPos); virtual void sendPointerEnterEvent(const QPointF &globalPos); @@ -482,6 +496,9 @@ private: int m_screen; bool m_skipCloseAnimation; quint32 m_surfaceId = 0; +#if HAVE_WAYLAND + KWayland::Server::SurfaceInterface *m_surface = nullptr; +#endif // when adding new data members, check also copyToDeleted() }; @@ -718,6 +735,18 @@ inline quint32 Toplevel::surfaceId() const return m_surfaceId; } +#if HAVE_WAYLAND +inline KWayland::Server::SurfaceInterface *Toplevel::surface() const +{ + return m_surface; +} + +inline void Toplevel::setSurface(KWayland::Server::SurfaceInterface *surface) +{ + m_surface = surface; +} +#endif + template inline T *Toplevel::findInList(const QList &list, std::function func) { diff --git a/wayland_server.cpp b/wayland_server.cpp index 914315af08..afdbbaa849 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "wayland_server.h" +#include "toplevel.h" +#include "workspace.h" #include #include @@ -47,6 +49,22 @@ void WaylandServer::init(const QByteArray &socketName) m_display->start(); m_compositor = m_display->createCompositor(m_display); m_compositor->create(); + connect(m_compositor, &CompositorInterface::surfaceCreated, this, + [this] (SurfaceInterface *surface) { + // check whether we have a Toplevel with the Surface's id + Workspace *ws = Workspace::self(); + if (!ws) { + // it's possible that a Surface gets created before Workspace is created + return; + } + auto check = [surface] (const Toplevel *t) { + return t->surfaceId() == surface->id(); + }; + if (Toplevel *t = ws->findToplevel(check)) { + t->setSurface(surface); + } + } + ); m_shell = m_display->createShell(m_display); m_shell->create(); m_display->createShm();