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.
This commit is contained in:
Vlad Zahorodnii 2023-10-18 21:30:43 +03:00
parent aa57e9130b
commit 2c29dfd596

View file

@ -439,8 +439,15 @@ void QuickSceneEffect::addScreen(EffectScreen *screen)
}); });
incubator->setInitialProperties(properties); incubator->setInitialProperties(properties);
QQmlContext *creationContext = d->delegate->creationContext(); QQmlContext *parentContext;
QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this)); 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->contexts[screen].reset(context);
d->incubators[screen].reset(incubator); d->incubators[screen].reset(incubator);