diff --git a/autotests/wayland/kwin_wayland_test.cpp b/autotests/wayland/kwin_wayland_test.cpp
index ef08c985ff..2c1a01d9ee 100644
--- a/autotests/wayland/kwin_wayland_test.cpp
+++ b/autotests/wayland/kwin_wayland_test.cpp
@@ -19,6 +19,7 @@ along with this program. If not, see .
*********************************************************************/
#include "kwin_wayland_test.h"
#include "../../abstract_backend.h"
+#include "../../effects.h"
#include "../../wayland_server.h"
#include "../../workspace.h"
#include "../../xcbutils.h"
@@ -52,6 +53,10 @@ WaylandTestApplication::~WaylandTestApplication()
{
destroyWorkspace();
waylandServer()->dispatch();
+ // need to unload all effects prior to destroying X connection as they might do X calls
+ if (effects) {
+ static_cast(effects)->unloadAllEffects();
+ }
if (x11Connection()) {
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
destroyAtoms();
diff --git a/effects.cpp b/effects.cpp
index 46409e3652..0f0ac4e3a3 100644
--- a/effects.cpp
+++ b/effects.cpp
@@ -315,6 +315,11 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene)
}
EffectsHandlerImpl::~EffectsHandlerImpl()
+{
+ unloadAllEffects();
+}
+
+void EffectsHandlerImpl::unloadAllEffects()
{
makeOpenGLContextCurrent();
if (keyboard_grab_effect != NULL)
diff --git a/effects.h b/effects.h
index c2e0221429..1d0652a872 100644
--- a/effects.h
+++ b/effects.h
@@ -62,7 +62,7 @@ class EffectLoader;
class Unmanaged;
class ScreenLockerWatcher;
-class EffectsHandlerImpl : public EffectsHandler
+class KWIN_EXPORT EffectsHandlerImpl : public EffectsHandler
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Effects")
@@ -206,6 +206,7 @@ public:
void reloadEffect(Effect *effect) override;
QStringList loadedEffects() const;
QStringList listOfEffects() const;
+ void unloadAllEffects();
QList elevatedWindows() const;
QStringList activeEffects() const;
diff --git a/main_wayland.cpp b/main_wayland.cpp
index f15601bad7..7c4f8570f4 100644
--- a/main_wayland.cpp
+++ b/main_wayland.cpp
@@ -22,6 +22,7 @@ along with this program. If not, see .
#include
// kwin
#include "abstract_backend.h"
+#include "effects.h"
#include "wayland_server.h"
#include "xcbutils.h"
@@ -76,6 +77,10 @@ ApplicationWayland::~ApplicationWayland()
{
destroyWorkspace();
waylandServer()->dispatch();
+ // need to unload all effects prior to destroying X connection as they might do X calls
+ if (effects) {
+ static_cast(effects)->unloadAllEffects();
+ }
if (x11Connection()) {
Xcb::setInputFocus(XCB_INPUT_FOCUS_POINTER_ROOT);
destroyAtoms();