Turn Scripting into a proper singleton
There is only one instance hold by Workspace which means it should follow the common approach with ::self and ::create. REVIEW: 109850
This commit is contained in:
parent
bac6edb269
commit
6f113d84d3
5 changed files with 23 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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<KWin::AbstractScript*> 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<QAction*> 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
|
||||
|
|
|
@ -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<QAction*> scriptActions = ws->scripting()->actionsForUserActionMenu(m_client.data(), m_scriptsMenu);
|
||||
QList<QAction*> scriptActions = Scripting::self()->actionsForUserActionMenu(m_client.data(), m_scriptsMenu);
|
||||
if (!scriptActions.isEmpty()) {
|
||||
m_scriptsMenu->setFont(KGlobalSettings::menuFont());
|
||||
m_scriptsMenu->addActions(scriptActions);
|
||||
|
|
|
@ -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<void> 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,
|
||||
|
|
|
@ -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<KillWindow> m_windowKiller;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue