Export workspace as global property on ScriptEngine in QML bindings

If workspace is exported as a context property there seem to be
issues with the signals which are not bound to a property of
WorkspaceWrapper.

This problems seems to be fixable by exporting the workspace
property as a global property on the script engine.

As a side-effect this also resolves the issue with the clientList,
so we can drop the hack again.

REVIEW: 104682
This commit is contained in:
Martin Gräßlin 2012-04-19 22:12:06 +02:00
parent 175668f2b3
commit 7073b0af40
3 changed files with 7 additions and 22 deletions

View file

@ -142,6 +142,13 @@ void KWin::AbstractScript::installScriptFunctions(QScriptEngine* engine)
engine->globalObject().setProperty("readConfig", configFunc);
// add global Shortcut
registerGlobalShortcutFunction(this, engine, kwinScriptGlobalShortcut);
// global properties
engine->globalObject().setProperty("KWin", engine->newQMetaObject(&WorkspaceWrapper::staticMetaObject));
QScriptValue workspace = engine->newQObject(AbstractScript::workspace(), QScriptEngine::QtOwnership,
QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater);
engine->globalObject().setProperty("workspace", workspace, QScriptValue::Undeletable);
// install meta functions
KWin::MetaScripting::registration(engine);
}
KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject* parent)
@ -162,16 +169,11 @@ void KWin::Script::run()
return;
}
if (scriptFile().open(QIODevice::ReadOnly)) {
QScriptValue workspace = m_engine->newQObject(AbstractScript::workspace(), QScriptEngine::QtOwnership,
QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater);
QScriptValue optionsValue = m_engine->newQObject(options, QScriptEngine::QtOwnership,
QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater);
m_engine->globalObject().setProperty("workspace", workspace, QScriptValue::Undeletable);
m_engine->globalObject().setProperty("options", optionsValue, QScriptValue::Undeletable);
m_engine->globalObject().setProperty("QTimer", constructTimerClass(m_engine));
m_engine->globalObject().setProperty("KWin", m_engine->newQMetaObject(&WorkspaceWrapper::staticMetaObject));
QObject::connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), this, SLOT(sigException(QScriptValue)));
KWin::MetaScripting::registration(m_engine);
KWin::MetaScripting::supplyConfig(m_engine);
installScriptFunctions(m_engine);
@ -236,10 +238,8 @@ void KWin::DeclarativeScript::run()
kdeclarative.setupBindings();
installScriptFunctions(kdeclarative.scriptEngine());
qmlRegisterType<ThumbnailItem>("org.kde.kwin", 0, 1, "ThumbnailItem");
qmlRegisterType<WorkspaceWrapper>("org.kde.kwin", 0, 1, "KWin");
qmlRegisterType<KWin::Client>();
m_view->rootContext()->setContextProperty("workspace", workspace());
m_view->rootContext()->setContextProperty("options", options);
m_view->setSource(QUrl::fromLocalFile(scriptFile().fileName()));

View file

@ -191,15 +191,6 @@ QString WorkspaceWrapper::supportInformation() const
return Workspace::self()->supportInformation();
}
QList< QObject* > WorkspaceWrapper::getClientList() const
{
QList<QObject*> list;
foreach (Client* client, Workspace::self()->clientList()) {
list << client;
}
return list;
}
void WorkspaceWrapper::setupClientConnections(KWin::Client *client)
{
connect(client, SIGNAL(clientMinimized(KWin::Client*,bool)), SIGNAL(clientMinimized(KWin::Client*)));

View file

@ -148,12 +148,6 @@ void setter( rettype val );
/**
* List of Clients currently managed by KWin.
* Use this method in QML scripts.
**/
Q_INVOKABLE QList< QObject* > getClientList() const;
/**
* List of Clients currently managed by KWin.
* Use this method in JavaScript scripts.
**/
Q_INVOKABLE QList< KWin::Client* > clientList() const;
/**