diff --git a/autotests/wayland/kwin_wayland_test.cpp b/autotests/wayland/kwin_wayland_test.cpp index eec0f56830..ba37dfa6a9 100644 --- a/autotests/wayland/kwin_wayland_test.cpp +++ b/autotests/wayland/kwin_wayland_test.cpp @@ -62,6 +62,7 @@ WaylandTestApplication::~WaylandTestApplication() if (x11Connection()) { Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT); destroyAtoms(); + emit x11ConnectionAboutToBeDestroyed(); xcb_disconnect(x11Connection()); setX11Connection(nullptr); } diff --git a/composite.cpp b/composite.cpp index 77d66d4ae5..c921c87e45 100644 --- a/composite.cpp +++ b/composite.cpp @@ -128,6 +128,12 @@ Compositor::Compositor(QObject* workspace) } }, Qt::QueuedConnection ); + connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed, this, + [this] { + delete cm_selection; + cm_selection = nullptr; + } + ); } else { // delay the call to setup by one event cycle // The ctor of this class is invoked from the Workspace ctor, that means before diff --git a/main.h b/main.h index 4a2a7e994f..a345cd36ca 100644 --- a/main.h +++ b/main.h @@ -152,6 +152,7 @@ public: Q_SIGNALS: void x11ConnectionChanged(); + void x11ConnectionAboutToBeDestroyed(); void workspaceCreated(); void screensCreated(); void virtualTerminalCreated(); diff --git a/main_wayland.cpp b/main_wayland.cpp index 93831d1921..21aeebb6a1 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -86,6 +86,7 @@ ApplicationWayland::~ApplicationWayland() if (x11Connection()) { Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT); destroyAtoms(); + emit x11ConnectionAboutToBeDestroyed(); xcb_disconnect(x11Connection()); setX11Connection(nullptr); }