From 0eb37563e93d35dda9965e964c2304b7ce33675e Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 4 Mar 2021 19:38:15 +0000 Subject: [PATCH] Restore script DBus API The Script class has a DBus API we want to export. At some point this has got broken and the run method is not exported. It's a bit messy with script subclasses also having other invokables that we want to export to scripts, so an adaptor is used to keep things separated. The interface name has technically changed, but KWin was doing something weird and using the same interface names for the manager. Fortunately calling Plasma code doesn't specify an interface so this still works. --- src/CMakeLists.txt | 2 ++ src/scripting/org.kde.kwin.Script.xml | 10 ++++++++++ src/scripting/scripting.cpp | 8 +++++--- src/scripting/scripting.h | 3 --- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/scripting/org.kde.kwin.Script.xml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d13ceecdf..ed827187ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -139,6 +139,8 @@ set(kwin_SRCS xwl/xwayland_interface.cpp ) +qt5_add_dbus_adaptor(kwin_SRCS scripting/org.kde.kwin.Script.xml scripting/scripting.h KWin::AbstractScript) + if (HAVE_LINUX_VT_H) set(kwin_SRCS ${kwin_SRCS} virtual_terminal.cpp diff --git a/src/scripting/org.kde.kwin.Script.xml b/src/scripting/org.kde.kwin.Script.xml new file mode 100644 index 0000000000..d22c282149 --- /dev/null +++ b/src/scripting/org.kde.kwin.Script.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 26363737cd..840ac245c1 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -41,6 +41,8 @@ #include #include +#include "scriptadaptor.h" + static QRect scriptValueToRect(const QJSValue &value) { return QRect(value.property(QStringLiteral("x")).toInt(), @@ -71,6 +73,9 @@ KWin::AbstractScript::AbstractScript(int id, QString scriptName, QString pluginN if (m_pluginName.isNull()) { m_pluginName = scriptName; } + + new ScriptAdaptor(this); + QDBusConnection::sessionBus().registerObject(QLatin1Char('/') + QString::number(scriptId()), this, QDBusConnection::ExportAdaptors); } KWin::AbstractScript::~AbstractScript() @@ -104,13 +109,10 @@ KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject* pa } qRegisterMetaType>(); - - QDBusConnection::sessionBus().registerObject(QLatin1Char('/') + QString::number(scriptId()), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportScriptableInvokables); } KWin::Script::~Script() { - QDBusConnection::sessionBus().unregisterObject(QLatin1Char('/') + QString::number(scriptId())); } void KWin::Script::run() diff --git a/src/scripting/scripting.h b/src/scripting/scripting.h index 3dea60d409..0580e6816c 100644 --- a/src/scripting/scripting.h +++ b/src/scripting/scripting.h @@ -86,8 +86,6 @@ private: class Script : public AbstractScript, QDBusContext { Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting") - public: Script(int id, QString scriptName, QString pluginName, QObject *parent = nullptr); virtual ~Script(); @@ -237,7 +235,6 @@ private: class DeclarativeScript : public AbstractScript { Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting") public: explicit DeclarativeScript(int id, QString scriptName, QString pluginName, QObject *parent = nullptr); ~DeclarativeScript() override;