diff --git a/events.cpp b/events.cpp
index 24dab56c11..8872e48b60 100644
--- a/events.cpp
+++ b/events.cpp
@@ -67,6 +67,7 @@ along with this program. If not, see .
#include "x11eventfilter.h"
#if HAVE_WAYLAND
+#include "wayland_server.h"
#include
#endif
@@ -1698,7 +1699,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);
+ if (auto w = waylandServer()) {
+ m_surface = KWayland::Server::SurfaceInterface::get(m_surfaceId, w->xWaylandConnection());
+ }
#endif
emit surfaceIdChanged(m_surfaceId);
}
diff --git a/wayland_server.h b/wayland_server.h
index 2149cd6ec8..ee98dab619 100644
--- a/wayland_server.h
+++ b/wayland_server.h
@@ -79,6 +79,10 @@ public:
**/
int createQtConnection();
+ KWayland::Server::ClientConnection *xWaylandConnection() const {
+ return m_xwaylandConnection;
+ }
+
private:
KWayland::Server::Display *m_display = nullptr;
KWayland::Server::CompositorInterface *m_compositor = nullptr;