diff --git a/autotests/integration/scripting/screenedge_test.cpp b/autotests/integration/scripting/screenedge_test.cpp index 32a8be40a2..e828619320 100644 --- a/autotests/integration/scripting/screenedge_test.cpp +++ b/autotests/integration/scripting/screenedge_test.cpp @@ -126,11 +126,14 @@ void ScreenEdgeTest::testEdge() const int id = Scripting::self()->loadScript(scriptToLoad); QVERIFY(id != -1); QVERIFY(Scripting::self()->isScriptLoaded(scriptToLoad)); - // TODO: a way to run the script without having to call the global start - Scripting::self()->start(); - // give it some time to start - a callback would be nice - QTest::qWait(100); - + auto s = Scripting::self()->findScript(scriptToLoad); + QVERIFY(s); + QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged); + QVERIFY(runningChangedSpy.isValid()); + s->run(); + QVERIFY(runningChangedSpy.wait()); + QCOMPARE(runningChangedSpy.count(), 1); + QCOMPARE(runningChangedSpy.first().first().toBool(), true); // triggering the edge will result in show desktop being triggered QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged); QVERIFY(showDesktopSpy.isValid()); diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp index 3d1f772e9b..7ce6d59fd7 100644 --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -718,14 +718,19 @@ void KWin::Scripting::slotScriptsQueried() } bool KWin::Scripting::isScriptLoaded(const QString &pluginName) const +{ + return findScript(pluginName) != nullptr; +} + +KWin::AbstractScript *KWin::Scripting::findScript(const QString &pluginName) const { QMutexLocker locker(m_scriptsLock.data()); foreach (AbstractScript *script, scripts) { if (script->pluginName() == pluginName) { - return true; + return script; } } - return false; + return nullptr; } bool KWin::Scripting::unloadScript(const QString &pluginName) diff --git a/scripting/scripting.h b/scripting/scripting.h index 48a3b7132b..07f5e7346c 100644 --- a/scripting/scripting.h +++ b/scripting/scripting.h @@ -52,7 +52,7 @@ class Client; class ScriptUnloaderAgent; class WorkspaceWrapper; -class AbstractScript : public QObject +class KWIN_EXPORT AbstractScript : public QObject { Q_OBJECT public: @@ -149,6 +149,7 @@ private Q_SLOTS: Q_SIGNALS: Q_SCRIPTABLE void print(const QString &text); + void runningChanged(bool); protected: QFile &scriptFile() { @@ -158,7 +159,11 @@ protected: return m_running; } void setRunning(bool running) { + if (m_running == running) { + return; + } m_running = running; + emit runningChanged(m_running); } int scriptId() const { return m_scriptId; @@ -357,6 +362,8 @@ public: QQmlEngine *qmlEngine(); WorkspaceWrapper *workspaceWrapper() const; + AbstractScript *findScript(const QString &pluginName) const; + static Scripting *self(); static Scripting *create(QObject *parent);