From d91da41cef17e34841ad307041fc00f76c105ba6 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 4 Nov 2020 15:35:37 +0200 Subject: [PATCH] wayland: Fix binding of xwayland surfaces to windows Surface ids are not unique across clients. If the underlying surface of an XdgToplevelClient is replaced with an Xwayland's surface, you may see weird results such as a desktop window having the contents of an X11 window or even worse a crash. BUG: 428680 --- wayland_server.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/wayland_server.cpp b/wayland_server.cpp index 06c6e49380..016a460508 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -19,6 +19,7 @@ #include "workspace.h" #include "xdgshellclient.h" #include "service_utils.h" +#include "unmanaged.h" // Client #include @@ -348,12 +349,24 @@ bool WaylandServer::init(const QByteArray &socketName, InitializationFlags flags // setting surface is only relevat for Xwayland clients return; } - auto check = [surface] (const Toplevel *t) { - return t->surfaceId() == surface->id(); - }; - if (Toplevel *t = ws->findToplevel(check)) { - t->setSurface(surface); + + X11Client *client = ws->findClient([surface](const X11Client *client) { + return client->surfaceId() == surface->id(); + }); + if (client) { + client->setSurface(surface); + return; } + + Unmanaged *unmanaged = ws->findUnmanaged([surface](const Unmanaged *unmanaged) { + return unmanaged->surfaceId() == surface->id(); + }); + if (unmanaged) { + unmanaged->setSurface(surface); + return; + } + + // The surface will be bound later when a WL_SURFACE_ID message is received. } );