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