diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5d44b10c4..74e98795cc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -233,4 +233,9 @@ install( FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
install( FILES kwin.notifyrc DESTINATION ${DATA_INSTALL_DIR}/kwin )
install( FILES org.kde.KWin.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} )
+if( KWIN_BUILD_SCRIPTING )
+ # Install the KWin/WindowSwitcher service type
+ install( FILES scripting/kwinscript.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} )
+endif( KWIN_BUILD_SCRIPTING )
+
kde4_install_icons( ${ICON_INSTALL_DIR} )
diff --git a/scripting/kwinscript.desktop b/scripting/kwinscript.desktop
new file mode 100644
index 0000000000..224f4bfd1d
--- /dev/null
+++ b/scripting/kwinscript.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=KWin/Script
+
+Comment=KWin Script
+
+[PropertyDef::X-Plasma-API]
+Type=QString
+
+[PropertyDef::X-Plasma-MainScript]
+Type=QString
diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp
index d95f6075c3..180991b13e 100644
--- a/scripting/scripting.cpp
+++ b/scripting/scripting.cpp
@@ -25,7 +25,10 @@ along with this program. If not, see .
#include "workspace_wrapper.h"
// KDE
#include
+#include
#include
+#include
+#include
// Qt
#include
#include
@@ -53,7 +56,6 @@ KWin::Script::Script(int scriptId, QString scriptName, QDir dir, QObject *parent
, m_scriptId(scriptId)
, m_engine(new QScriptEngine(this))
, m_scriptDir(dir)
- , m_configFile(QFileInfo(m_scriptFile).completeBaseName() + QString(".kwscfg"))
, m_workspace(new WorkspaceWrapper(m_engine))
, m_running(false)
{
@@ -85,20 +87,7 @@ void KWin::Script::run()
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);
-
- if (m_scriptDir.exists(m_configFile)) {
- QSettings scriptSettings(m_scriptDir.filePath(m_configFile), QSettings::IniFormat);
- QHash scriptConfig;
- QStringList keys = scriptSettings.allKeys();
-
- for (int i = 0; i < keys.size(); i++) {
- scriptConfig.insert(keys.at(i), scriptSettings.value(keys.at(i)));
- }
-
- KWin::MetaScripting::supplyConfig(m_engine, QVariant(scriptConfig));
- } else {
- KWin::MetaScripting::supplyConfig(m_engine);
- }
+ KWin::MetaScripting::supplyConfig(m_engine);
// add our print
QScriptValue printFunc = m_engine->newFunction(kwinScriptPrint);
printFunc.setData(m_engine->newQObject(this));
@@ -146,20 +135,29 @@ KWin::Scripting::Scripting(QObject *parent)
void KWin::Scripting::start()
{
- QStringList scriptFilters;
- QString sDirectory = KStandardDirs::locateLocal("data", "kwin/scripts/");
+ KSharedConfig::Ptr _config = KGlobal::config();
+ KConfigGroup conf(_config, "Plugins");
- if (sDirectory.isEmpty()) {
- // Abort scripting setup. No location found to locate scripts
- return;
- }
+ KService::List offers = KServiceTypeTrader::self()->query("KWin/Script");
- scriptFilters << "*.kwinscript" << "*.kws" << "*.kwinqs";
- scriptsDir.setPath(sDirectory);
- scriptList = scriptsDir.entryList(scriptFilters, QDir::Files | QDir::Readable | QDir::Executable);
+ foreach (const KService::Ptr & service, offers) {
+ KPluginInfo plugininfo(service);
+ plugininfo.load(conf);
+ if (service->property("X-Plasma-API").toString() != "javascript") {
+ continue;
+ }
- for (int i = 0; i < scriptList.size(); i++) {
- loadScript(scriptsDir.filePath(scriptList.at(i)));
+ if (!plugininfo.isPluginEnabled()) {
+ continue;
+ }
+ const QString pluginName = service->property("X-KDE-PluginInfo-Name").toString();
+ const QString scriptName = service->property("X-Plasma-MainScript").toString();
+ const QString file = KStandardDirs::locate("data", "kwin/scripts/" + pluginName + "/contents/" + scriptName);
+ if (file.isNull()) {
+ kDebug(1212) << "Could not find script file for " << pluginName;
+ continue;
+ }
+ loadScript(file);
}
runScripts();
diff --git a/scripting/scripting.h b/scripting/scripting.h
index 3811c4d710..f716ae6059 100644
--- a/scripting/scripting.h
+++ b/scripting/scripting.h
@@ -65,7 +65,6 @@ private:
QScriptEngine *m_engine;
QDir m_scriptDir;
QFile m_scriptFile;
- QString m_configFile;
WorkspaceWrapper *m_workspace;
bool m_running;
};