Commit d91da41c authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

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
parent 59262615
......@@ -19,6 +19,7 @@
#include "workspace.h"
#include "xdgshellclient.h"
#include "service_utils.h"
#include "unmanaged.h"
// Client
#include <KWayland/Client/connection_thread.h>
......@@ -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.
}
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment