diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -719,8 +719,10 @@ 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(); + QQmlExpression exprClients(m_declarativeScriptSharedContext, nullptr, "workspace.clientList = function() { return workspace.clients }"); + QQmlExpression exprDesktops(m_declarativeScriptSharedContext, nullptr, "workspace.desktopList = function() { return workspace.desktopClients }"); + exprClients.evaluate(); + exprDesktops.evaluate(); } void KWin::Scripting::start() diff --git a/scripting/workspace_wrapper.h b/scripting/workspace_wrapper.h --- a/scripting/workspace_wrapper.h +++ b/scripting/workspace_wrapper.h @@ -363,6 +363,10 @@ * List of Clients currently managed by KWin. */ Q_INVOKABLE QList clientList() const; + /** + * List of desktops currently managed by KWin. + */ + Q_INVOKABLE QList desktopList() const; explicit QtScriptWorkspaceWrapper(QObject* parent = nullptr); }; @@ -372,11 +376,16 @@ Q_OBJECT Q_PROPERTY(QQmlListProperty clients READ clients) + Q_PROPERTY(QQmlListProperty desktopClients READ desktopClients) public: QQmlListProperty clients(); static int countClientList(QQmlListProperty *clients); static KWin::AbstractClient *atClientList(QQmlListProperty *clients, int index); + QQmlListProperty desktopClients(); + static int countDesktopList(QQmlListProperty *desktopClients); + static KWin::X11Client *atDesktopList(QQmlListProperty *desktopClients, int index); + explicit DeclarativeScriptWorkspaceWrapper(QObject* parent = nullptr); }; diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.cpp --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -363,6 +363,11 @@ return workspace()->allClientList(); } +QList QtScriptWorkspaceWrapper::desktopList() const +{ + return workspace()->desktopList(); +} + QQmlListProperty DeclarativeScriptWorkspaceWrapper::clients() { return QQmlListProperty(this, nullptr, &DeclarativeScriptWorkspaceWrapper::countClientList, &DeclarativeScriptWorkspaceWrapper::atClientList); @@ -380,6 +385,23 @@ return workspace()->allClientList().at(index); } +QQmlListProperty DeclarativeScriptWorkspaceWrapper::desktopClients() +{ + return QQmlListProperty(this, nullptr, &DeclarativeScriptWorkspaceWrapper::countDesktopList, &DeclarativeScriptWorkspaceWrapper::atDesktopList); +} + +int DeclarativeScriptWorkspaceWrapper::countDesktopList(QQmlListProperty *desktopClients) +{ + Q_UNUSED(desktopClients) + return workspace()->desktopList().size(); +} + +KWin::X11Client *DeclarativeScriptWorkspaceWrapper::atDesktopList(QQmlListProperty *desktopClients, int index) +{ + Q_UNUSED(desktopClients) + return workspace()->desktopList().at(index); +} + DeclarativeScriptWorkspaceWrapper::DeclarativeScriptWorkspaceWrapper(QObject* parent) : WorkspaceWrapper(parent) {}