diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp index 1d71944f75..3a0843712c 100644 --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -574,6 +574,15 @@ void KWin::DeclarativeScript::run() setRunning(true); } +KWin::Scripting *KWin::Scripting::s_self = NULL; + +KWin::Scripting *KWin::Scripting::create(QObject *parent) +{ + Q_ASSERT(!s_self); + s_self = new Scripting(parent); + return s_self; +} + KWin::Scripting::Scripting(QObject *parent) : QObject(parent) , m_scriptsLock(new QMutex(QMutex::Recursive)) @@ -735,6 +744,7 @@ KWin::Scripting::~Scripting() { QDBusConnection::sessionBus().unregisterObject("/Scripting"); QDBusConnection::sessionBus().unregisterService("org.kde.kwin.Scripting"); + s_self = NULL; } QList< QAction * > KWin::Scripting::actionsForUserActionMenu(KWin::Client *c, QMenu *parent) diff --git a/scripting/scripting.h b/scripting/scripting.h index db85e23663..469274966b 100644 --- a/scripting/scripting.h +++ b/scripting/scripting.h @@ -287,6 +287,7 @@ class Scripting : public QObject Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting") private: + explicit Scripting(QObject *parent); QStringList scriptList; QList scripts; /** @@ -298,7 +299,6 @@ private: void runScripts(); public: - explicit Scripting(QObject *parent = NULL); ~Scripting(); Q_SCRIPTABLE Q_INVOKABLE int loadScript(const QString &filePath, const QString &pluginName = QString()); Q_SCRIPTABLE Q_INVOKABLE int loadDeclarativeScript(const QString &filePath, const QString &pluginName = QString()); @@ -314,6 +314,9 @@ public: **/ QList actionsForUserActionMenu(Client *c, QMenu *parent); + static Scripting *self(); + static Scripting *create(QObject *parent); + public Q_SLOTS: void scriptDestroyed(QObject *object); Q_SCRIPTABLE void start(); @@ -323,7 +326,14 @@ private Q_SLOTS: private: LoadScriptList queryScriptsToLoad(); + static Scripting *s_self; }; +inline +Scripting *Scripting::self() +{ + return s_self; +} + } #endif diff --git a/useractions.cpp b/useractions.cpp index 033ed6d51f..9ddd9ea185 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -453,7 +453,7 @@ void UserActionsMenu::menuAboutToShow() m_scriptsMenu = NULL; // ask scripts whether they want to add entries for the given Client m_scriptsMenu = new QMenu(m_menu); - QList scriptActions = ws->scripting()->actionsForUserActionMenu(m_client.data(), m_scriptsMenu); + QList scriptActions = Scripting::self()->actionsForUserActionMenu(m_client.data(), m_scriptsMenu); if (!scriptActions.isEmpty()) { m_scriptsMenu->setFont(KGlobalSettings::menuFont()); m_scriptsMenu->addActions(scriptActions); diff --git a/workspace.cpp b/workspace.cpp index 9d9e1e86be..8f1bbe4b33 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -136,7 +136,6 @@ Workspace::Workspace(bool restore) , set_active_client_recursion(0) , block_stacking_updates(0) , forced_global_mouse_grab(false) - , m_scripting(NULL) { // If KWin was already running it saved its configuration after loosing the selection -> Reread QFuture reparseConfigFuture = QtConcurrent::run(options, &Options::reparseConfiguration); @@ -492,7 +491,7 @@ void Workspace::init() #ifdef KWIN_BUILD_SCRIPTING - m_scripting = new Scripting(this); + Scripting::create(this); #endif // SELI TODO: This won't work with unreasonable focus policies, diff --git a/workspace.h b/workspace.h index b751521d6d..12ae8b6f2d 100644 --- a/workspace.h +++ b/workspace.h @@ -69,7 +69,6 @@ class Outline; class RootInfo; class PluginMgr; class Rules; -class Scripting; class UserActionsMenu; class WindowRules; class Compositor; @@ -243,12 +242,6 @@ public: return client_keys; } -#ifdef KWIN_BUILD_SCRIPTING - Scripting *scripting() { - return m_scripting; - } -#endif - /** * Returns the list of clients sorted in stacking order, with topmost client * at the last position @@ -652,8 +645,6 @@ private: bool forced_global_mouse_grab; friend class StackingUpdatesBlocker; - Scripting *m_scripting; - QScopedPointer m_windowKiller; private: