[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: [wayland] Add a SurfaceInterface to Toplevel
From:       Martin_Gräßlin <mgraesslin () kde ! org>
Date:       2015-03-17 9:33:04
Message-ID: E1YXns0-0006tV-1c () scm ! kde ! org
[Download RAW message or body]

Git commit 07c972b6d4a6d4e948d16305d4824c5f062cf6b4 by Martin Gräßlin.
Committed on 09/02/2015 at 15:08.
Pushed by graesslin into branch 'master'.

[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.

M  +7    -0    events.cpp
M  +29   -0    toplevel.h
M  +18   -0    wayland_server.cpp

http://commits.kde.org/kwin/07c972b6d4a6d4e948d16305d4824c5f062cf6b4

diff --git a/events.cpp b/events.cpp
index 2575b63..24dab56 100644
--- a/events.cpp
+++ b/events.cpp
@@ -66,6 +66,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "killwindow.h"
 #include "x11eventfilter.h"
 
+#if HAVE_WAYLAND
+#include <KWayland/Server/surface_interface.h>
+#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 10b8b59..1ec0d12 100644
--- a/toplevel.h
+++ b/toplevel.h
@@ -41,6 +41,16 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // c++
 #include <functional>
 
+#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 <class T, class U>
 inline T *Toplevel::findInList(const QList<T*> &list, std::function<bool (const U*)> func)
 {
diff --git a/wayland_server.cpp b/wayland_server.cpp
index 914315a..afdbbaa 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 <http://www.gnu.org/licenses/>.
 *********************************************************************/
 #include "wayland_server.h"
+#include "toplevel.h"
+#include "workspace.h"
 
 #include <KWayland/Server/compositor_interface.h>
 #include <KWayland/Server/display.h>
@@ -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();

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic