From b82897ce739c797c70c01a4602a13ea287e9ce18 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 8 Dec 2021 10:50:09 +0200 Subject: [PATCH] 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. --- src/scripting/scripting.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 5894d94b5d..39f3247b49 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -659,16 +659,18 @@ void KWin::Scripting::init() Q_UNUSED(jsEngine) return new DeclarativeScriptWorkspaceWrapper(); }); + qmlRegisterSingletonInstance("org.kde.kwin", 3, 0, "Options", options); qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); + // 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();