scripting: Register Options singleton

Context properties don't work with QML effects. At the moment, no effect
needs to access the options object, but it makes the QML API consistent.
The workspace is already a singleton type.
This commit is contained in:
Vlad Zahorodnii 2021-12-08 10:50:09 +02:00
parent 29a85e830c
commit b82897ce73

View file

@ -659,16 +659,18 @@ void KWin::Scripting::init()
Q_UNUSED(jsEngine)
return new DeclarativeScriptWorkspaceWrapper();
});
qmlRegisterSingletonInstance("org.kde.kwin", 3, 0, "Options", options);
qmlRegisterType<KWin::AbstractClient>();
qmlRegisterType<KWin::VirtualDesktop>();
qmlRegisterType<KWin::X11Client>();
qmlRegisterType<QAbstractItemModel>();
// TODO Plasma 6: Drop context properties.
m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("workspace"), m_workspaceWrapper);
m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("options"), options);
m_declarativeScriptSharedContext->setContextProperty(QStringLiteral("workspace"), new DeclarativeScriptWorkspaceWrapper(this));
// QQmlListProperty interfaces only work via properties, rebind them as functions here
QQmlExpression expr(m_declarativeScriptSharedContext, nullptr, "workspace.clientList = function() { return workspace.clients }");
expr.evaluate();