Commit 1998d5ac authored by Martin Flöser's avatar Martin Flöser

[wayland] Improve tear-down to not crash if X11 applications are still around

We need to destroy the compositor after Xwayland terminated and after
the internal Wayland connection is destroyed. This means when destroying
the Workspace we may no longer destroy the Compositor at the same time.
Also we need to ensure that other tear down functionality doesn't call
into the no longer existing internal client connection.

With this change kwin doesn't crash when exiting with Wayland and/or
X11 windows still open.
parent c09f4039
......@@ -50,8 +50,8 @@ WaylandTestApplication::WaylandTestApplication(int &argc, char **argv)
WaylandTestApplication::~WaylandTestApplication()
{
destroyCompositor();
destroyWorkspace();
waylandServer()->dispatch();
if (x11Connection()) {
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
destroyAtoms();
......@@ -61,6 +61,8 @@ WaylandTestApplication::~WaylandTestApplication()
m_xwaylandProcess->terminate();
m_xwaylandProcess->waitForFinished();
}
waylandServer()->destroyInternalConnection();
destroyCompositor();
}
void WaylandTestApplication::performStartup()
......
......@@ -418,10 +418,6 @@ void Application::destroyWorkspace()
void Application::destroyCompositor()
{
if (Workspace::self()) {
// compositor is destroyed together with Workspace
return;
}
delete Compositor::self();
}
......
......@@ -74,8 +74,8 @@ ApplicationWayland::ApplicationWayland(int &argc, char **argv)
ApplicationWayland::~ApplicationWayland()
{
destroyCompositor();
destroyWorkspace();
waylandServer()->dispatch();
if (x11Connection()) {
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
destroyAtoms();
......@@ -85,6 +85,8 @@ ApplicationWayland::~ApplicationWayland()
m_xwaylandProcess->terminate();
m_xwaylandProcess->waitForFinished();
}
waylandServer()->destroyInternalConnection();
destroyCompositor();
}
void ApplicationWayland::performStartup()
......
......@@ -121,6 +121,7 @@ ApplicationX11::ApplicationX11(int &argc, char **argv)
ApplicationX11::~ApplicationX11()
{
destroyCompositor();
destroyWorkspace();
if (!owner.isNull() && owner->ownerWindow() != XCB_WINDOW_NONE) // If there was no --replace (no new WM)
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
......@@ -134,6 +135,7 @@ void ApplicationX11::setReplace(bool replace)
void ApplicationX11::lostSelection()
{
sendPostedEvents();
destroyCompositor();
destroyWorkspace();
// Remove windowmanager privileges
Xcb::selectInput(rootWindow(), XCB_EVENT_MASK_PROPERTY_CHANGE);
......
......@@ -57,7 +57,6 @@ Window::~Window()
}
delete m_shellSurface;
delete m_surface;
waylandServer()->internalClientConection()->flush();
}
WId Window::winId() const
......@@ -106,7 +105,9 @@ void Window::unmap()
}
m_surface->attachBuffer(KWayland::Client::Buffer::Ptr());
m_surface->commit(KWayland::Client::Surface::CommitFlag::None);
waylandServer()->internalClientConection()->flush();
if (waylandServer()->internalClientConection()) {
waylandServer()->internalClientConection()->flush();
}
}
void Window::createEglSurface(EGLDisplay dpy, EGLConfig config)
......
......@@ -70,13 +70,16 @@ WaylandServer::WaylandServer(QObject *parent)
qRegisterMetaType<KWayland::Server::OutputInterface::DpmsMode>();
}
WaylandServer::~WaylandServer()
WaylandServer::~WaylandServer() = default;
void WaylandServer::destroyInternalConnection()
{
if (m_internalConnection.client) {
dispatch();
m_internalConnection.client->deleteLater();
m_internalConnection.clientThread->quit();
m_internalConnection.clientThread->wait();
m_internalConnection.client = nullptr;
}
}
......
......@@ -116,6 +116,7 @@ public:
int createInputMethodConnection();
void createInternalConnection();
void destroyInternalConnection();
void initWorkspace();
KWayland::Server::ClientConnection *xWaylandConnection() const {
......
......@@ -425,8 +425,6 @@ void Workspace::init()
Workspace::~Workspace()
{
delete m_compositor;
m_compositor = NULL;
blockStackingUpdates(true);
// TODO: grabXServer();
......
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