From 2c29dfd596cf1a5334638b9dadcb216fd51e5694 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 18 Oct 2023 21:30:43 +0300 Subject: [PATCH] libkwineffects: Make SceneEffect fallback to root context QuickSceneEffect can also be instantiated by C++, for example that's the case with the overview effect. In that case, qmlContext() is not going to return a valid context because the effect has not been created by a QQmlEngine. In that case, use the root context as the parent context. --- src/libkwineffects/kwinquickeffect.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libkwineffects/kwinquickeffect.cpp b/src/libkwineffects/kwinquickeffect.cpp index b5ee71e795..447e951138 100644 --- a/src/libkwineffects/kwinquickeffect.cpp +++ b/src/libkwineffects/kwinquickeffect.cpp @@ -439,8 +439,15 @@ void QuickSceneEffect::addScreen(EffectScreen *screen) }); incubator->setInitialProperties(properties); - QQmlContext *creationContext = d->delegate->creationContext(); - QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this)); + QQmlContext *parentContext; + if (QQmlContext *context = d->delegate->creationContext()) { + parentContext = context; + } else if (QQmlContext *context = qmlContext(this)) { + parentContext = context; + } else { + parentContext = d->delegate->engine()->rootContext(); + } + QQmlContext *context = new QQmlContext(parentContext); d->contexts[screen].reset(context); d->incubators[screen].reset(incubator);