diff --git a/kwin/CMakeLists.txt b/kwin/CMakeLists.txt
index fd4b2f5b..3bb84778 100644
--- a/kwin/CMakeLists.txt
+++ b/kwin/CMakeLists.txt
@@ -6,7 +6,6 @@ OPTION(KWIN_BUILD_OXYGEN "Enable building of default decoration Oxygen" ON)
OPTION(KWIN_BUILD_KCMS "Enable building of KWin configuration modules." ON)
OPTION(KWIN_BUILD_TABBOX "Enable building of KWin Tabbox functionality" ON)
OPTION(KWIN_BUILD_SCREENEDGES "Enable building of KWin with screen edge support" ON)
-OPTION(KWIN_BUILD_SCRIPTING "Enable building of KWin with scripting support" ON)
OPTION(KWIN_BUILD_KAPPMENU "Enable building of KWin with application menu support" ON)
OPTION(KWIN_BUILD_XRENDER_COMPOSITING "Enable building of KWin with XRender Compositing support" ON)
OPTION(KWIN_BUILD_OPENGL_1_COMPOSITING "Enable support for OpenGL 1.x, automatically disabled when building for OpenGL ES 2.0" ON)
@@ -23,7 +22,6 @@ if(KWIN_PLASMA_ACTIVE)
set(KWIN_BUILD_DECORATIONS OFF)
set(KWIN_BUILD_KCMS OFF)
set(KWIN_BUILD_SCREENEDGES OFF)
- set(KWIN_BUILD_SCRIPTING ON)
set(KWIN_BUILD_XRENDER_COMPOSITING OFF)
set(KWIN_MOBILE_EFFECTS ON)
set(KWIN_BUILD_WITH_OPENGLES ON)
@@ -86,12 +84,8 @@ endif()
add_subdirectory( data )
add_subdirectory( effects )
-add_subdirectory( scripts )
add_subdirectory( tabbox )
-if(KWIN_BUILD_SCRIPTING)
- add_subdirectory(scripting)
-endif()
########### next target ###############
@@ -143,19 +137,6 @@ set(kwin_KDEINIT_SRCS
xcbutils.cpp
)
-if(KWIN_BUILD_SCRIPTING)
- set(
- kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS}
- scripting/scripting.cpp
- scripting/workspace_wrapper.cpp
- scripting/meta.cpp
- scripting/scriptedeffect.cpp
- scripting/scriptingutils.cpp
- scripting/timer.cpp
- scripting/scripting_model.cpp
- )
-endif()
-
if(KWIN_BUILD_TABBOX)
set(
kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS}
@@ -262,10 +243,6 @@ else()
add_definitions(-DKWIN_NO_XF86VM)
endif()
-if(KWIN_BUILD_SCRIPTING)
- set(kwin_QT_LIBS ${kwin_QT_LIBS} ${QT_QTSCRIPT_LIBRARY})
-endif()
-
if(OPENGL_EGL_FOUND)
set(kwin_OPENGL_LIBS ${kwin_OPENGL_LIBS} ${OPENGLES_EGL_LIBRARY})
endif()
@@ -324,11 +301,6 @@ install( FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} RENAME ${KWIN_NAME}.k
install( FILES kwin.notifyrc DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME} RENAME ${KWIN_NAME}.notifyrc)
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()
-
kde4_install_icons( ${ICON_INSTALL_DIR} )
add_subdirectory(tests)
diff --git a/kwin/scripting/CMakeLists.txt b/kwin/scripting/CMakeLists.txt
deleted file mode 100644
index 8630b022..00000000
--- a/kwin/scripting/CMakeLists.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-set(kcm_kwin4_genericscripted_SRCS genericscriptedconfig.cpp)
-kde4_add_plugin( kcm_kwin4_genericscripted ${kcm_kwin4_genericscripted_SRCS} )
-target_link_libraries( kcm_kwin4_genericscripted ${KDE4_KIO_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} ${QT_QTUITOOLS_LIBRARY} )
-install( TARGETS kcm_kwin4_genericscripted DESTINATION ${PLUGIN_INSTALL_DIR} )
diff --git a/kwin/scripting/Messages.sh b/kwin/scripting/Messages.sh
deleted file mode 100644
index c52b3998..00000000
--- a/kwin/scripting/Messages.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp
-$XGETTEXT `find . -name \*.h -o -name \*.cpp` -o $podir/kwin_scripting.pot
-rm -f rc.cpp
diff --git a/kwin/scripting/documentation-effect-global.xml b/kwin/scripting/documentation-effect-global.xml
deleted file mode 100644
index 07b774e2..00000000
--- a/kwin/scripting/documentation-effect-global.xml
+++ /dev/null
@@ -1,179 +0,0 @@
-
-
-
-
-
-
- Global
- Methods and properties added to the global JavaScript object.
-
-
- KWin::EffectsHandler
-
-
- effects
-
- Global property to the core wrapper of KWin Effects
-
-
- KWin::ScriptedEffect
-
-
- effect
-
- Global property to the actual Effect
-
-
- object
-
-
- Effect
-
- Provides access to enums defined in KWin::AnimationEffect and KWin::ScriptedEffect
-
-
- object
-
-
- KWin
-
- Provides access to enums defined in KWin::WorkspaceWrapper
-
-
- object
-
-
- QEasingCurve
-
- Provides access to enums defined in QEasingCurve
-
-
-
-
- Q_SCRIPTABLE QList<quint64>
- QList<quint64> KWin::ScriptedEffect::animate
- (settings)
- animate
-
-
-Schedules one or many animations for one window. The animations are defined through the settings object providing
-a more declarative way to specify the animations than the animate call on the effect object. The settings object
-supports the following attributes:
-<syntaxhighlight lang="javascript">
-{
- window: EffectWindow, /* the window to animate, required */
- duration: int, /* duration in msec, required */
- curve: QEasingCurve.Type, /* global easing curve, optional */
- type: Effect.Attribute, /* for first animation, optional */
- from: FPx2, /* for first animation, optional */
- to: FPx2, /* for first animation, optional */
- delay: int, /* for first animation, optional */
- animations: [ /* additional animations, optional */
- {
- curve: QEasingCurve.Type, /* overrides global */
- type: Effect.Attribute,
- from: FPx2,
- to: FPx2,
- delay: int
- }
- ]
-}
-</syntaxhighlight>
-At least one animation or attribute setter (see below) needs to be specified either with the top-level properties or in the animations list.
-
-
-
- Q_SCRIPTABLE QList<quint64>
- QList<quint64> KWin::ScriptedEffect::set
- (settings)
- set
-
-
-Like animate, just that the manipulation does not implicitly end with the animation. You have to explicitly cancel it.
-Until then, the manipulated attribute will remain at animation target value.
-
-
-
- Q_SCRIPTABLE bool
- bool KWin::ScriptedEffect::cancel
- (QList<quint64>)
- cancel
-
-
-Cancel one or more present animations caused and returned by KWin::ScriptedEffect::animate or KWin::ScriptedEffect::set.
-For convenience you can pass a single quint64 as well.
-
-
-
- Q_SCRIPTABLE void
- void KWin::ScriptedEffect::print
- (QVariant ... values)
- print
-
- Prints all provided values to kDebug and as a D-Bus signal
-
-
- Q_SCRIPTABLE int
- int KWin::ScriptedEffect::animationTime
- (int duration)
- animationTime
-
- Adjusts the passed in duration to the global animation time facator.
-
-
- Q_SCRIPTABLE int
- int KWin::ScriptedEffect::displayWidth
- ()
- displayWidth
-
- Width of the complete display (all screens).
-
-
- Q_SCRIPTABLE int
- int KWin::ScriptedEffect::displayHeight
- ()
- displayHeight
-
- Height of the complete display (all screens).
-
-
- Q_SCRIPTABLE bool
- bool KWin::ScriptedEffect::registerScreenEdge
- (ElectricBorder border, QScriptValue callback)
- registerScreenEdge
-
- Registers the callback for the screen edge. When the mouse gets pushed against the given edge the callback will be invoked.
-
-
- Q_SCRIPTABLE bool
- bool KWin::ScriptedEffect::registerShortcut
- (QString title, QString text, QString keySequence, QScriptValue callback)
- registerShortcut
-
- Registers keySequence as a global shortcut. When the shortcut is invoked the callback will be called. Title and text are used to name the shortcut and make it available to the global shortcut configuration module.
-
-
-
-
- KWin::FPx2
- This class is used to describe the animation end points, that is from which FPx2 values to which FPx2 values an animation goes. This class contains two properties to describe two animation components individually (e.g. width and height). But it's also possible to just have one value (e.g. opacity). In this case the definition of an FPx2 can be replaced by a single value.
-
-
- qreal
-
-
- value1
-
-
-
-
- qreal
-
-
- value2
-
-
-
-
-
-
diff --git a/kwin/scripting/documentation-global.xml b/kwin/scripting/documentation-global.xml
deleted file mode 100644
index 6ab70cd3..00000000
--- a/kwin/scripting/documentation-global.xml
+++ /dev/null
@@ -1,134 +0,0 @@
-
-
-
-
-
-
- Global
- Methods and properties added to the global JavaScript object.
-
-
- KWin::Options
-
-
- options
-
- Global property to all configuration values of KWin core.
-
-
- KWin::Workspace
-
-
- workspace
-
- Global property to the core wrapper of KWin.
-
-
- object
-
-
- KWin
-
- Provides access to enums defined in KWin::WorkspaceWrapper
-
-
-
-
- Q_SCRIPTABLE void
- void KWin::Scripting::print
- (QVariant ... values)
- print
-
- Prints all provided values to kDebug and as a D-Bus signal
-
-
- Q_SCRIPTABLE QVariant
- QVariant KWin::Scripting::readConfig
- (QString key, QVariant defaultValue = QVariant())
- readConfig
-
- Reads the config value for key in the Script's configuration with the optional default value. If not providing a default value and no value stored in the configuration an undefined value is returned.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::registerScreenEdge
- (ElectricBorder border, QScriptValue callback)
- registerScreenEdge
-
- Registers the callback for the screen edge. When the mouse gets pushed against the given edge the callback will be invoked.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::registerShortcut
- (QString title, QString text, QString keySequence, QScriptValue callback)
- registerShortcut
-
- Registers keySequence as a global shortcut. When the shortcut is invoked the callback will be called. Title and text are used to name the shortcut and make it available to the global shortcut configuration module.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::assert
- (bool value, QString message = QString())
- assert
-
- Aborts the execution of the script if value does not evaluate to true. If message is provided an error is thrown with the given message, if not provided an error with default message is thrown.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::assertTrue
- (bool value, QString message = QString())
- assertTrue
-
- Aborts the execution of the script if value does not evaluate to true. If message is provided an error is thrown with the given message, if not provided an error with default message is thrown.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::assertFalse
- (bool value, QString message = QString())
- assertFalse
-
- Aborts the execution of the script if value does not evaluate to false. If message is provided an error is thrown with the given message, if not provided an error with default message is thrown.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::assertEquals
- (QVariant expected, QVariant actual, QString message = QString())
- assertEquals
-
- Aborts the execution of the script if the actual value is not equal to the expected value. If message is provided an error is thrown with the given message, if not provided an error with default message is thrown.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::assertNull
- (QVariant value, QString message = QString())
- assertNull
-
- Aborts the execution of the script if value is not null. If message is provided an error is thrown with the given message, if not provided an error with default message is thrown.
-
-
- Q_SCRIPTABLE bool
- bool KWin::Scripting::assertNotNull
- (QVariant value, QString message = QString())
- assertNotNull
-
- Aborts the execution of the script if value is null. If message is provided an error is thrown with the given message, if not provided an error with default message is thrown.
-
-
- Q_SCRIPTABLE void
- void KWin::Scripting::callDBus
- (QString service, QString path, QString interface, QString method, QVariant arg..., QScriptValue callback = QScriptValue())
- callDBus
-
- Call a D-Bus method at (service, path, interface and method). A variable number of arguments can be added to the method call. The D-Bus call is always performed in an async way invoking the callback provided as the last (optional) argument. The reply values of the D-Bus method call are passed to the callback.
-
-
- Q_SCRIPTABLE void
- void KWin::Scripting::registerUserActionsMenu
- (QScriptValue callback)
- registerUserActionsMenu
-
- Registers the passed in callback to be invoked whenever the User actions menu (Alt+F3 or right click on window decoration) is about to be shown. The callback is invoked with a reference to the Client for which the menu is shown. The callback can return either a single menu entry to be added to the menu or an own sub menu with multiple entries. The object for a menu entry should be {title: "My Menu entry", checkable: true, checked: false, triggered: function (action) { // callback with triggered QAction}}, for a menu it should be {title: "My menu", items: [{...}, {...}, ...] /*list with entries as described*/}
-
-
-
-
diff --git a/kwin/scripting/genericscriptedconfig.cpp b/kwin/scripting/genericscriptedconfig.cpp
deleted file mode 100644
index 6d2cd188..00000000
--- a/kwin/scripting/genericscriptedconfig.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * KWin - the KDE window manager
- * This file is part of the KDE project.
- *
- * Copyright (C) 2013 Martin Gräßlin
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-#include "genericscriptedconfig.h"
-#include "config-kwin.h"
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace KWin {
-
-GenericScriptedConfigFactory::GenericScriptedConfigFactory()
- : KPluginFactory("kcm_kwin4_genericscripted")
-{
-}
-
-QObject *GenericScriptedConfigFactory::create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
-{
- Q_UNUSED(iface)
- Q_UNUSED(parent)
- if (keyword.startsWith("kwin4_effect_")) {
- return new ScriptedEffectConfig(componentData(), keyword, parentWidget, args);
- } else {
- return new ScriptingConfig(componentData(), keyword, parentWidget, args);
- }
-}
-
-GenericScriptedConfig::GenericScriptedConfig(const KComponentData &data, const QString &keyword, QWidget *parent, const QVariantList &args)
- : KCModule(data, parent, args)
- , m_packageName(keyword)
-{
-}
-
-GenericScriptedConfig::~GenericScriptedConfig()
-{
-}
-
-void GenericScriptedConfig::createUi()
-{
- QVBoxLayout* layout = new QVBoxLayout(this);
-
- const QString kconfigXTFile = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + '/' + typeName() + '/' + m_packageName + "/contents/config/main.xml");
- const QString uiPath = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + '/' + typeName() + '/' + m_packageName + "/contents/ui/config.ui");
- if (kconfigXTFile.isEmpty() || uiPath.isEmpty()) {
- layout->addWidget(new QLabel(i18nc("Error message", "Plugin does not provide configuration file in expected location")));
- return;
- }
- QFile xmlFile(kconfigXTFile);
- KConfigGroup cg = configGroup();
- Plasma::ConfigLoader *configLoader = new Plasma::ConfigLoader(&cg, &xmlFile, this);
- // load the ui file
- QUiLoader *loader = new QUiLoader(this);
- QFile uiFile(uiPath);
- uiFile.open(QFile::ReadOnly);
- QWidget *customConfigForm = loader->load(&uiFile, this);
- uiFile.close();
- layout->addWidget(customConfigForm);
- addConfig(configLoader, customConfigForm);
-}
-
-void GenericScriptedConfig::save()
-{
- KCModule::save();
- reload();
-}
-
-void GenericScriptedConfig::reload()
-{
-}
-
-ScriptedEffectConfig::ScriptedEffectConfig(const KComponentData &data, const QString &keyword, QWidget *parent, const QVariantList &args)
- : GenericScriptedConfig(data, keyword, parent, args)
-{
- createUi();
-}
-
-ScriptedEffectConfig::~ScriptedEffectConfig()
-{
-}
-
-QString ScriptedEffectConfig::typeName() const
-{
- return QString("effects");
-}
-
-KConfigGroup ScriptedEffectConfig::configGroup()
-{
- return KSharedConfig::openConfig(KWIN_CONFIG)->group("Effect-" + packageName());
-}
-
-void ScriptedEffectConfig::reload()
-{
- QDBusMessage message = QDBusMessage::createMethodCall("org.kde.kwin", "/KWin", "org.kde.KWin", "reconfigureEffect");
- message << QString(packageName());
- QDBusConnection::sessionBus().send(message);
-}
-
-ScriptingConfig::ScriptingConfig(const KComponentData &data, const QString &keyword, QWidget *parent, const QVariantList &args)
- : GenericScriptedConfig(data, keyword, parent, args)
-{
- createUi();
-}
-
-ScriptingConfig::~ScriptingConfig()
-{
-}
-
-KConfigGroup ScriptingConfig::configGroup()
-{
- return KSharedConfig::openConfig(KWIN_CONFIG)->group("Script-" + packageName());
-}
-
-QString ScriptingConfig::typeName() const
-{
- return QString("scripts");
-}
-
-void ScriptingConfig::reload()
-{
- // TODO: what to call
-}
-
-K_EXPORT_PLUGIN(GenericScriptedConfigFactory())
-
-} // namespace
diff --git a/kwin/scripting/genericscriptedconfig.h b/kwin/scripting/genericscriptedconfig.h
deleted file mode 100644
index d1affdfa..00000000
--- a/kwin/scripting/genericscriptedconfig.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * KWin - the KDE window manager
- * This file is part of the KDE project.
- *
- * Copyright (C) 2013 Martin Gräßlin
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
-*/
-
-#ifndef KWIN_GENERICSCRIPTEDCONFIG_H
-#define KWIN_GENERICSCRIPTEDCONFIG_H
-
-#include
-#include
-
-namespace KWin
-{
-
-class GenericScriptedConfigFactory : public KPluginFactory
-{
- Q_OBJECT
-public:
- GenericScriptedConfigFactory();
-
-protected:
- virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword);
-};
-
-class GenericScriptedConfig : public KCModule
-{
- Q_OBJECT
-
-public:
- GenericScriptedConfig(const KComponentData &data, const QString &keyword, QWidget *parent, const QVariantList &args);
- virtual ~GenericScriptedConfig();
-
-public slots:
- virtual void save();
-
-protected:
- const QString &packageName() const;
- void createUi();
- virtual QString typeName() const = 0;
- virtual KConfigGroup configGroup() = 0;
- virtual void reload();
-
-private:
- QString m_packageName;
-};
-
-class ScriptedEffectConfig : public GenericScriptedConfig
-{
- Q_OBJECT
-public:
- ScriptedEffectConfig(const KComponentData &data, const QString &keyword, QWidget *parent, const QVariantList &args);
- virtual ~ScriptedEffectConfig();
-protected:
- virtual QString typeName() const;
- virtual KConfigGroup configGroup();
- virtual void reload();
-};
-
-class ScriptingConfig : public GenericScriptedConfig
-{
- Q_OBJECT
-public:
- ScriptingConfig(const KComponentData &data, const QString &keyword, QWidget *parent, const QVariantList &args);
- virtual ~ScriptingConfig();
-
-protected:
- virtual QString typeName() const;
- virtual KConfigGroup configGroup();
- virtual void reload();
-};
-
-inline
-const QString &GenericScriptedConfig::packageName() const
-{
- return m_packageName;
-}
-
-}
-
-#endif // KWIN_GENERICSCRIPTEDCONFIG_H
diff --git a/kwin/scripting/kwinscript.desktop b/kwin/scripting/kwinscript.desktop
deleted file mode 100644
index b6170c64..00000000
--- a/kwin/scripting/kwinscript.desktop
+++ /dev/null
@@ -1,60 +0,0 @@
-[Desktop Entry]
-Type=ServiceType
-X-KDE-ServiceType=KWin/Script
-
-Comment=KWin Script
-Comment[bs]=KWin skripta
-Comment[ca]=Script del KWin
-Comment[ca@valencia]=Script del KWin
-Comment[cs]=Skript KWinu
-Comment[da]=KWin-script
-Comment[de]=KWin-Skript
-Comment[el]=Σενάριο KWin
-Comment[en_GB]=KWin Script
-Comment[es]=Guion de KWin
-Comment[et]=KWini skript
-Comment[eu]=KWin scripta
-Comment[fi]=KWin-skripti
-Comment[fr]=Script KWin
-Comment[ga]=Script KWin
-Comment[gl]=Script do KWin
-Comment[he]=תסריט של KWin
-Comment[hu]=KWin parancsfájl
-Comment[ia]=Script de kwin
-Comment[it]=Script kwin
-Comment[kk]=KWin скрипті
-Comment[km]=ស្គ្រីប KWin
-Comment[ko]=KWin 스크립트
-Comment[lt]=KWin scenarijus
-Comment[mr]=के-विन स्क्रिप्ट
-Comment[nb]=KWin-skript
-Comment[nds]=KWin-Skript
-Comment[nl]=KWin-script
-Comment[pa]=KWin ਸਕ੍ਰਿਪਟ
-Comment[pl]=Skrypt KWin
-Comment[pt]=Programa do KWin
-Comment[pt_BR]=Script do KWin
-Comment[ro]=Script KWin
-Comment[ru]=Сценарий KWin
-Comment[sk]=KWin skript
-Comment[sl]=Skript KWin
-Comment[sr]=К‑винова скрипта
-Comment[sr@ijekavian]=К‑винова скрипта
-Comment[sr@ijekavianlatin]=KWinova skripta
-Comment[sr@latin]=KWinova skripta
-Comment[sv]=Kwin-skript
-Comment[tr]=KWin Betiği
-Comment[uk]=Скрипт KWin
-Comment[vi]=Tập lệnh KWin
-Comment[x-test]=xxKWin Scriptxx
-Comment[zh_CN]=KWin 脚本
-Comment[zh_TW]=KWin 文稿
-
-[PropertyDef::X-Plasma-API]
-Type=QString
-
-[PropertyDef::X-Plasma-MainScript]
-Type=QString
-
-[PropertyDef::X-KWin-Exclude-Listing]
-Type=bool
diff --git a/kwin/scripting/meta.cpp b/kwin/scripting/meta.cpp
deleted file mode 100644
index b6c3ba37..00000000
--- a/kwin/scripting/meta.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2010 Rohan Prabhu
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#include "meta.h"
-#include "client.h"
-
-#include
-
-using namespace KWin::MetaScripting;
-
-// Meta for QPoint object
-QScriptValue Point::toScriptValue(QScriptEngine* eng, const QPoint& point)
-{
- QScriptValue temp = eng->newObject();
- temp.setProperty("x", point.x());
- temp.setProperty("y", point.y());
- return temp;
-}
-
-void Point::fromScriptValue(const QScriptValue& obj, QPoint& point)
-{
- QScriptValue x = obj.property("x", QScriptValue::ResolveLocal);
- QScriptValue y = obj.property("y", QScriptValue::ResolveLocal);
-
- if (!x.isUndefined() && !y.isUndefined()) {
- point.setX(x.toInt32());
- point.setY(y.toInt32());
- }
-}
-// End of meta for QPoint object
-
-// Meta for QSize object
-QScriptValue Size::toScriptValue(QScriptEngine* eng, const QSize& size)
-{
- QScriptValue temp = eng->newObject();
- temp.setProperty("w", size.width());
- temp.setProperty("h", size.height());
- return temp;
-}
-
-void Size::fromScriptValue(const QScriptValue& obj, QSize& size)
-{
- QScriptValue w = obj.property("w", QScriptValue::ResolveLocal);
- QScriptValue h = obj.property("h", QScriptValue::ResolveLocal);
-
- if (!w.isUndefined() && !h.isUndefined()) {
- size.setWidth(w.toInt32());
- size.setHeight(h.toInt32());
- }
-}
-// End of meta for QSize object
-
-// Meta for QRect object. Just a temporary measure, hope to
-// add a much better wrapping of the QRect object soon
-QScriptValue Rect::toScriptValue(QScriptEngine* eng, const QRect& rect)
-{
- QScriptValue temp = eng->newObject();
- temp.setProperty("x", rect.x());
- temp.setProperty("y", rect.y());
- temp.setProperty("width", rect.width());
- temp.setProperty("height", rect.height());
-
- return temp;
-}
-
-void Rect::fromScriptValue(const QScriptValue& obj, QRect &rect)
-{
- QScriptValue w = obj.property("width", QScriptValue::ResolveLocal);
- QScriptValue h = obj.property("height", QScriptValue::ResolveLocal);
- QScriptValue x = obj.property("x", QScriptValue::ResolveLocal);
- QScriptValue y = obj.property("y", QScriptValue::ResolveLocal);
-
- if (!w.isUndefined() && !h.isUndefined() && !x.isUndefined() && !y.isUndefined()) {
- rect.setX(x.toInt32());
- rect.setY(y.toInt32());
- rect.setWidth(w.toInt32());
- rect.setHeight(h.toInt32());
- }
-}
-// End of meta for QRect object
-
-QScriptValue Client::toScriptValue(QScriptEngine *eng, const KClientRef &client)
-{
- return eng->newQObject(client, QScriptEngine::QtOwnership,
- QScriptEngine::ExcludeChildObjects |
- QScriptEngine::ExcludeDeleteLater |
- QScriptEngine::PreferExistingWrapperObject |
- QScriptEngine::AutoCreateDynamicProperties);
-}
-
-void Client::fromScriptValue(const QScriptValue &value, KWin::Client* &client)
-{
- client = qobject_cast(value.toQObject());
-}
-
-QScriptValue Toplevel::toScriptValue(QScriptEngine *eng, const KToplevelRef &client)
-{
- return eng->newQObject(client, QScriptEngine::QtOwnership,
- QScriptEngine::ExcludeChildObjects |
- QScriptEngine::ExcludeDeleteLater |
- QScriptEngine::PreferExistingWrapperObject |
- QScriptEngine::AutoCreateDynamicProperties);
-}
-
-void Toplevel::fromScriptValue(const QScriptValue &value, KToplevelRef &client)
-{
- client = qobject_cast(value.toQObject());
-}
-
-// Other helper functions
-void KWin::MetaScripting::registration(QScriptEngine* eng)
-{
- qScriptRegisterMetaType(eng, Point::toScriptValue, Point::fromScriptValue);
- qScriptRegisterMetaType(eng, Size::toScriptValue, Size::fromScriptValue);
- qScriptRegisterMetaType(eng, Rect::toScriptValue, Rect::fromScriptValue);
- qScriptRegisterMetaType(eng, Client::toScriptValue, Client::fromScriptValue);
- qScriptRegisterMetaType(eng, Toplevel::toScriptValue, Toplevel::fromScriptValue);
-
- qScriptRegisterSequenceMetaType(eng);
- qScriptRegisterSequenceMetaType< QList >(eng);
-}
-
-QScriptValue KWin::MetaScripting::configExists(QScriptContext* ctx, QScriptEngine* eng)
-{
- QHash scriptConfig = (((ctx->thisObject()).data()).toVariant()).toHash();
- QVariant val = scriptConfig.value((ctx->argument(0)).toString(), QVariant());
-
- return eng->toScriptValue(val.isValid());
-}
-
-QScriptValue KWin::MetaScripting::getConfigValue(QScriptContext* ctx, QScriptEngine* eng)
-{
- int num = ctx->argumentCount();
- QHash scriptConfig = (((ctx->thisObject()).data()).toVariant()).toHash();
-
- /*
- * Handle config.get() separately. Compute and return immediately.
- **/
- if (num == 0) {
- QHash::const_iterator i;
- QScriptValue ret = eng->newArray();
-
- for (i = scriptConfig.constBegin(); i != scriptConfig.constEnd(); ++i) {
- ret.setProperty(i.key(), eng->newVariant(i.value()));
- }
-
- return ret;
- }
-
- if ((num == 1) && !((ctx->argument(0)).isArray())) {
- QVariant val = scriptConfig.value((ctx->argument(0)).toString(), QVariant());
-
- if (val.isValid()) {
- return eng->newVariant(val);
- } else {
- return QScriptValue();
- }
- } else {
- QScriptValue ret = eng->newArray();
- int j = 0;
-
- if ((ctx->argument(0)).isArray()) {
- bool simple = (num == 1) ? 0 : (ctx->argument(1)).toBool();
- QScriptValue array = (ctx->argument(0));
- int len = (array.property("length").isValid()) ? array.property("length").toNumber() : 0;
-
- for (int i = 0; i < len; i++) {
- QVariant val = scriptConfig.value(array.property(i).toString(), QVariant());
-
- if (val.isValid()) {
- if (simple) {
- ret.setProperty(j, eng->newVariant(val));
- } else {
- ret.setProperty(array.property(i).toString(), eng->newVariant(val));
- }
-
- j++;
- }
- }
- } else {
- for (int i = 0; i < num; i++) {
- QVariant val = scriptConfig.value((ctx->argument(i)).toString(), QVariant());
-
- if (val.isValid()) {
- ret.setProperty((ctx->argument(i)).toString(), eng->newVariant(val));
- j = 1;
- }
- }
- }
-
-
- if (j == 0) {
- return QScriptValue();
- } else {
- return ret;
- }
- }
-}
-
-void KWin::MetaScripting::supplyConfig(QScriptEngine* eng, const QVariant& scriptConfig)
-{
- QScriptValue configObject = eng->newObject();
- configObject.setData(eng->newVariant(scriptConfig));
- configObject.setProperty("get", eng->newFunction(getConfigValue, 0), QScriptValue::Undeletable);
- configObject.setProperty("exists", eng->newFunction(configExists, 0), QScriptValue::Undeletable);
- configObject.setProperty("loaded", ((scriptConfig.toHash().empty()) ? eng->newVariant((bool)0) : eng->newVariant((bool)1)), QScriptValue::Undeletable);
- (eng->globalObject()).setProperty("config", configObject);
-}
-
-void KWin::MetaScripting::supplyConfig(QScriptEngine* eng)
-{
- KWin::MetaScripting::supplyConfig(eng, QVariant(QHash()));
-}
-
-void KWin::MetaScripting::valueMerge(QScriptValue& first, QScriptValue second)
-{
- QScriptValueIterator value_it(second);
-
- while (value_it.hasNext()) {
- value_it.next();
- first.setProperty(value_it.name(), value_it.value());
- }
-}
diff --git a/kwin/scripting/meta.h b/kwin/scripting/meta.h
deleted file mode 100644
index 306adec7..00000000
--- a/kwin/scripting/meta.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2010 Rohan Prabhu
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#ifndef KWIN_SCRIPTING_META_H
-#define KWIN_SCRIPTING_META_H
-
-#include
-
-// forward declarations
-class QPoint;
-class QRect;
-class QScriptContext;
-class QSize;
-
-namespace KWin {
-class Client;
-class Toplevel;
-}
-
-typedef KWin::Client* KClientRef;
-typedef KWin::Toplevel* KToplevelRef;
-
-namespace KWin
-{
-namespace MetaScripting
-{
-
-
-/**
- * The toScriptValue and fromScriptValue functions used in qScriptRegisterMetaType.
- * Conversion functions for QPoint
- */
-namespace Point
-{
-QScriptValue toScriptValue(QScriptEngine*, const QPoint&);
-void fromScriptValue(const QScriptValue&, QPoint&);
-}
-
-/**
- * The toScriptValue and fromScriptValue functions used in qScriptRegisterMetaType.
- * Conversion functions for QSize
- */
-namespace Size
-{
-QScriptValue toScriptValue(QScriptEngine*, const QSize&);
-void fromScriptValue(const QScriptValue&, QSize&);
-}
-
-/**
- * The toScriptValue and fromScriptValue functions used in qScriptRegisterMetaType.
- * Conversion functions for QRect
- * TODO: QRect conversions have to be linked from plasma as they provide a lot more
- * features. As for QSize and QPoint, I don't really plan any such thing.
- */
-namespace Rect
-{
-QScriptValue toScriptValue(QScriptEngine*, const QRect&);
-void fromScriptValue(const QScriptValue&, QRect&);
-}
-
-namespace Client
-{
-QScriptValue toScriptValue(QScriptEngine *eng, const KClientRef &client);
-void fromScriptValue(const QScriptValue &value, KClientRef& client);
-}
-
-namespace Toplevel
-{
-QScriptValue toScriptValue(QScriptEngine *eng, const KToplevelRef &client);
-void fromScriptValue(const QScriptValue &value, KToplevelRef& client);
-}
-
-/**
- * Merges the second QScriptValue in the first one.
- */
-void valueMerge(QScriptValue&, QScriptValue);
-
-/**
- * Registers all the meta conversion to the provided QScriptEngine
- */
-void registration(QScriptEngine* eng);
-
-/**
- * Functions for the JS function objects, config.exists and config.get.
- * Read scripting/IMPLIST for details on how they work
- */
-QScriptValue configExists(QScriptContext*, QScriptEngine*);
-QScriptValue getConfigValue(QScriptContext*, QScriptEngine*);
-
-/**
- * Provide a config object to the given QScriptEngine depending
- * on the keys provided in the QVariant. The provided QVariant
- * MUST returns (true) on isHash()
- */
-void supplyConfig(QScriptEngine*, const QVariant&);
-
-/**
- * For engines whose scripts have no associated configuration.
- */
-void supplyConfig(QScriptEngine*);
-
-}
-}
-
-/**
- * Code linked from plasma for QTimer.
- */
-QScriptValue constructTimerClass(QScriptEngine *eng);
-
-#endif
diff --git a/kwin/scripting/scriptedeffect.cpp b/kwin/scripting/scriptedeffect.cpp
deleted file mode 100644
index 31d13239..00000000
--- a/kwin/scripting/scriptedeffect.cpp
+++ /dev/null
@@ -1,642 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
- Copyright (C) 2012 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#include "scriptedeffect.h"
-#include "meta.h"
-#include "scriptingutils.h"
-#include "workspace_wrapper.h"
-#ifdef KWIN_BUILD_SCREENEDGES
-#include "../screenedge.h"
-#endif
-// KDE
-#include
-#include
-#include
-#include
-// Qt
-#include
-#include
-#include
-
-typedef KWin::EffectWindow* KEffectWindowRef;
-
-Q_DECLARE_METATYPE(KWin::AnimationData*)
-Q_SCRIPT_DECLARE_QMETAOBJECT(KWin::AnimationData, QObject*)
-
-namespace KWin
-{
-
-QScriptValue kwinEffectScriptPrint(QScriptContext *context, QScriptEngine *engine)
-{
- ScriptedEffect *script = qobject_cast(context->callee().data().toQObject());
- QString result;
- for (int i = 0; i < context->argumentCount(); ++i) {
- if (i > 0) {
- result.append(" ");
- }
- result.append(context->argument(i).toString());
- }
- kDebug(1212) << script->scriptFile() << ":" << result;
-
- return engine->undefinedValue();
-}
-
-QScriptValue kwinEffectScriptAnimationTime(QScriptContext *context, QScriptEngine *engine)
-{
- if (context->argumentCount() != 1) {
- return engine->undefinedValue();
- }
- if (!context->argument(0).isNumber()) {
- return engine->undefinedValue();
- }
- return Effect::animationTime(context->argument(0).toInteger());
-}
-
-QScriptValue kwinEffectDisplayWidth(QScriptContext *context, QScriptEngine *engine)
-{
- Q_UNUSED(context)
- Q_UNUSED(engine)
- return Effect::displayWidth();
-}
-
-QScriptValue kwinEffectDisplayHeight(QScriptContext *context, QScriptEngine *engine)
-{
- Q_UNUSED(context)
- Q_UNUSED(engine)
- return Effect::displayHeight();
-}
-
-QScriptValue kwinScriptGlobalShortcut(QScriptContext *context, QScriptEngine *engine)
-{
- return globalShortcut(context, engine);
-}
-
-QScriptValue kwinScriptScreenEdge(QScriptContext *context, QScriptEngine *engine)
-{
- return registerScreenEdge(context, engine);
-}
-
-struct AnimationSettings {
- enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3 };
- AnimationEffect::Attribute type;
- QEasingCurve::Type curve;
- FPx2 from;
- FPx2 to;
- int delay;
- uint duration;
- uint set;
-};
-
-AnimationSettings animationSettingsFromObject(QScriptValue &object)
-{
- AnimationSettings settings;
- settings.set = 0;
-
- settings.to = qscriptvalue_cast(object.property("to"));
- settings.from = qscriptvalue_cast(object.property("from"));
-
- QScriptValue duration = object.property("duration");
- if (duration.isValid() && duration.isNumber()) {
- settings.duration = duration.toUInt32();
- settings.set |= AnimationSettings::Duration;
- } else {
- settings.duration = 0;
- }
-
- QScriptValue delay = object.property("delay");
- if (delay.isValid() && delay.isNumber()) {
- settings.delay = delay.toInt32();
- settings.set |= AnimationSettings::Delay;
- } else {
- settings.delay = 0;
- }
-
- QScriptValue curve = object.property("curve");
- if (curve.isValid() && curve.isNumber()) {
- settings.curve = static_cast(curve.toInt32());
- settings.set |= AnimationSettings::Curve;
- } else {
- settings.curve = QEasingCurve::Linear;
- }
-
- QScriptValue type = object.property("type");
- if (type.isValid() && type.isNumber()) {
- settings.type = static_cast(type.toInt32());
- settings.set |= AnimationSettings::Type;
- } else {
- settings.type = static_cast(-1);
- }
-
- return settings;
-}
-
-QList animationSettings(QScriptContext *context, ScriptedEffect *effect, EffectWindow **window)
-{
- QList settings;
- if (!effect) {
- context->throwError(QScriptContext::ReferenceError, "Internal Scripted KWin Effect error");
- return settings;
- }
- if (context->argumentCount() != 1) {
- context->throwError(QScriptContext::SyntaxError, "Exactly one argument expected");
- return settings;
- }
- if (!context->argument(0).isObject()) {
- context->throwError(QScriptContext::TypeError, "Argument needs to be an object");
- return settings;
- }
- QScriptValue object = context->argument(0);
- QScriptValue windowProperty = object.property("window");
- if (!windowProperty.isValid() || !windowProperty.isObject()) {
- context->throwError(QScriptContext::TypeError, "Window property missing in animation options");
- return settings;
- }
- *window = qobject_cast(windowProperty.toQObject());
-
- settings << animationSettingsFromObject(object); // global
-
- QScriptValue animations = object.property("animations"); // array
- if (animations.isValid()) {
- if (!animations.isArray()) {
- context->throwError(QScriptContext::TypeError, "Animations provided but not an array");
- settings.clear();
- return settings;
- }
- const int length = static_cast(animations.property("length").toInteger());
- for (int i=0; ithrowError(QScriptContext::TypeError, "Type property missing in animation options");
- continue;
- }
- if (!(set & AnimationSettings::Duration)) {
- context->throwError(QScriptContext::TypeError, "Duration property missing in animation options");
- continue;
- }
- // Complete local animations from global settings
- if (!(s.set & AnimationSettings::Duration)) {
- s.duration = settings.at(0).duration;
- }
- if (!(s.set & AnimationSettings::Curve)) {
- s.curve = settings.at(0).curve;
- }
- if (!(s.set & AnimationSettings::Delay)) {
- s.delay = settings.at(0).delay;
- }
- settings << s;
- }
- }
- }
-
- if (settings.count() == 1) {
- const uint set = settings.at(0).set;
- if (!(set & AnimationSettings::Type)) {
- context->throwError(QScriptContext::TypeError, "Type property missing in animation options");
- settings.clear();
- }
- if (!(set & AnimationSettings::Duration)) {
- context->throwError(QScriptContext::TypeError, "Duration property missing in animation options");
- settings.clear();
- }
- } else if (!(settings.at(0).set & AnimationSettings::Type)) { // invalid global
- settings.removeAt(0); // -> get rid of it, only used to complete the others
- }
-
- return settings;
-}
-
-QScriptValue kwinEffectAnimate(QScriptContext *context, QScriptEngine *engine)
-{
- ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject());
- EffectWindow *window;
- QList settings = animationSettings(context, effect, &window);
- if (settings.empty()) {
- context->throwError(QScriptContext::TypeError, "No animations provided");
- return engine->undefinedValue();
- }
- if (!window) {
- context->throwError(QScriptContext::TypeError, "Window property does not contain an EffectWindow");
- return engine->undefinedValue();
- }
-
- QList animIds;
- foreach (const AnimationSettings &setting, settings) {
- animIds << QVariant(effect->animate(window,
- setting.type,
- setting.duration,
- setting.to,
- setting.from,
- NULL,
- setting.curve,
- setting.delay));
- }
- return engine->newVariant(animIds);
-}
-
-QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine)
-{
- ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject());
-
- EffectWindow *window;
- QList settings = animationSettings(context, effect, &window);
- if (settings.empty()) {
- context->throwError(QScriptContext::TypeError, "No animations provided");
- return engine->undefinedValue();
- }
- if (!window) {
- context->throwError(QScriptContext::TypeError, "Window property does not contain an EffectWindow");
- return engine->undefinedValue();
- }
-
- QList animIds;
- foreach (const AnimationSettings &setting, settings) {
- animIds << QVariant(effect->set(window,
- setting.type,
- setting.duration,
- setting.to,
- setting.from,
- NULL,
- setting.curve,
- setting.delay));
- }
-
- return engine->newVariant(animIds);
-}
-
-QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine)
-{
- ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject());
- if (context->argumentCount() != 1) {
- context->throwError(QScriptContext::SyntaxError, "Exactly one argument expected");
- return engine->undefinedValue();
- }
- QVariant v = context->argument(0).toVariant();
- QList animIds;
- bool ok = false;
- if (v.isValid()) {
- quint64 animId = v.toULongLong(&ok);
- if (ok)
- animIds << animId;
- }
- if (!ok) { // may still be a variantlist of variants being quint64
- QList list = v.toList();
- if (!list.isEmpty()) {
- foreach (const QVariant &vv, list) {
- quint64 animId = vv.toULongLong(&ok);
- if (ok)
- animIds << animId;
- }
- ok = !animIds.isEmpty();
- }
- }
- if (!ok) {
- context->throwError(QScriptContext::TypeError, "Argument needs to be one or several quint64");
- return engine->undefinedValue();
- }
-
- foreach (const quint64 &animId, animIds) {
- ok |= engine->newVariant(effect->cancel(animId)).toBool();
- }
-
- return engine->newVariant(ok);
-}
-
-QScriptValue effectWindowToScriptValue(QScriptEngine *eng, const KEffectWindowRef &window)
-{
- return eng->newQObject(window, QScriptEngine::QtOwnership,
- QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject);
-}
-
-void effectWindowFromScriptValue(const QScriptValue &value, EffectWindow* &window)
-{
- window = qobject_cast(value.toQObject());
-}
-
-QScriptValue fpx2ToScriptValue(QScriptEngine *eng, const KWin::FPx2 &fpx2)
-{
- QScriptValue val = eng->newObject();
- val.setProperty("value1", fpx2[0]);
- val.setProperty("value2", fpx2[1]);
- return val;
-}
-
-void fpx2FromScriptValue(const QScriptValue &value, KWin::FPx2 &fpx2)
-{
- if (value.isNull()) {
- fpx2 = FPx2();
- return;
- }
- if (value.isNumber()) {
- fpx2 = FPx2(value.toNumber());
- return;
- }
- if (value.isObject()) {
- QScriptValue value1 = value.property("value1");
- QScriptValue value2 = value.property("value2");
- if (!value1.isValid() || !value2.isValid() || !value1.isNumber() || !value2.isNumber()) {
- kDebug(1212) << "Cannot cast scripted FPx2 to C++";
- fpx2 = FPx2();
- return;
- }
- fpx2 = FPx2(value1.toNumber(), value2.toNumber());
- }
-}
-
-ScriptedEffect *ScriptedEffect::create(const QString& effectName, const QString& pathToScript)
-{
- ScriptedEffect *effect = new ScriptedEffect();
- if (!effect->init(effectName, pathToScript)) {
- delete effect;
- return NULL;
- }
- return effect;
-}
-
-ScriptedEffect::ScriptedEffect()
- : AnimationEffect()
- , m_engine(new QScriptEngine(this))
- , m_scriptFile(QString())
- , m_config(NULL)
-{
- connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue)));
-}
-
-ScriptedEffect::~ScriptedEffect()
-{
-}
-
-bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript)
-{
- QFile scriptFile(pathToScript);
- if (!scriptFile.open(QIODevice::ReadOnly)) {
- kDebug(1212) << "Could not open script file: " << pathToScript;
- return false;
- }
- m_effectName = effectName;
- m_scriptFile = pathToScript;
-
- // does the effect contain an KConfigXT file?
- const QString kconfigXTFile = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + "/effects/" + m_effectName + "/contents/config/main.xml");
- if (!kconfigXTFile.isNull()) {
- KConfigGroup cg = effects->effectConfig(m_effectName);
- QFile xmlFile(kconfigXTFile);
- m_config = new Plasma::ConfigLoader(&cg, &xmlFile, this);
- m_config->readConfig();
- }
-
- QScriptValue effectsObject = m_engine->newQObject(effects, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater);
- m_engine->globalObject().setProperty("effects", effectsObject, QScriptValue::Undeletable);
- m_engine->globalObject().setProperty("Effect", m_engine->newQMetaObject(&ScriptedEffect::staticMetaObject));
- m_engine->globalObject().setProperty("KWin", m_engine->newQMetaObject(&WorkspaceWrapper::staticMetaObject));
- m_engine->globalObject().setProperty("QEasingCurve", m_engine->newQMetaObject(&QEasingCurve::staticMetaObject));
- m_engine->globalObject().setProperty("effect", m_engine->newQObject(this, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater), QScriptValue::Undeletable);
- m_engine->globalObject().setProperty("AnimationData", m_engine->scriptValueFromQMetaObject());
- MetaScripting::registration(m_engine);
- qScriptRegisterMetaType(m_engine, effectWindowToScriptValue, effectWindowFromScriptValue);
- qScriptRegisterMetaType(m_engine, fpx2ToScriptValue, fpx2FromScriptValue);
- qScriptRegisterSequenceMetaType >(m_engine);
- // add our print
- QScriptValue printFunc = m_engine->newFunction(kwinEffectScriptPrint);
- printFunc.setData(m_engine->newQObject(this));
- m_engine->globalObject().setProperty("print", printFunc);
- // add our animationTime
- QScriptValue animationTimeFunc = m_engine->newFunction(kwinEffectScriptAnimationTime);
- animationTimeFunc.setData(m_engine->newQObject(this));
- m_engine->globalObject().setProperty("animationTime", animationTimeFunc);
- // add displayWidth and displayHeight
- QScriptValue displayWidthFunc = m_engine->newFunction(kwinEffectDisplayWidth);
- m_engine->globalObject().setProperty("displayWidth", displayWidthFunc);
- QScriptValue displayHeightFunc = m_engine->newFunction(kwinEffectDisplayHeight);
- m_engine->globalObject().setProperty("displayHeight", displayHeightFunc);
- // add global Shortcut
- registerGlobalShortcutFunction(this, m_engine, kwinScriptGlobalShortcut);
- registerScreenEdgeFunction(this, m_engine, kwinScriptScreenEdge);
- // add the animate method
- QScriptValue animateFunc = m_engine->newFunction(kwinEffectAnimate);
- animateFunc.setData(m_engine->newQObject(this));
- m_engine->globalObject().setProperty("animate", animateFunc);
-
- // and the set variant
- QScriptValue setFunc = m_engine->newFunction(kwinEffectSet);
- setFunc.setData(m_engine->newQObject(this));
- m_engine->globalObject().setProperty("set", setFunc);
-
- // cancel...
- QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel);
- cancelFunc.setData(m_engine->newQObject(this));
- m_engine->globalObject().setProperty("cancel", cancelFunc);
-
- QScriptValue ret = m_engine->evaluate(scriptFile.readAll());
-
- if (ret.isError()) {
- signalHandlerException(ret);
- return false;
- }
- scriptFile.close();
- return true;
-}
-
-void ScriptedEffect::signalHandlerException(const QScriptValue &value)
-{
- if (value.isError()) {
- kDebug(1212) << "KWin Effect script encountered an error at [Line " << m_engine->uncaughtExceptionLineNumber() << "]";
- kDebug(1212) << "Message: " << value.toString();
-
- QScriptValueIterator iter(value);
- while (iter.hasNext()) {
- iter.next();
- kDebug(1212) << " " << iter.name() << ": " << iter.value().toString();
- }
- }
-}
-
-uint metaFromData(KWin::AnimationData* data)
-{
- uint meta = 0;
- if (data) {
- if (data->axis() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::Axis, data->axis() -1, meta);
- }
- if (data->sourceAnchor() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::SourceAnchor, data->sourceAnchor(), meta);
- }
- if (data->targetAnchor() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::TargetAnchor, data->targetAnchor(), meta);
- }
- if (data->relativeSourceX() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::RelativeSourceX, data->relativeSourceX(), meta);
- }
- if (data->relativeSourceY() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::RelativeSourceY, data->relativeSourceY(), meta);
- }
- if (data->relativeTargetX() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::RelativeTargetX, data->relativeTargetX(), meta);
- }
- if (data->relativeTargetY() != 0) {
- AnimationEffect::setMetaData(AnimationEffect::RelativeTargetY, data->relativeTargetY(), meta);
- }
- }
- return meta;
-}
-
-quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, KWin::AnimationData* data, QEasingCurve::Type curve, int delay)
-{
- return AnimationEffect::animate(w, a, metaFromData(data), ms, to, QEasingCurve(curve), delay, from);
-}
-
-quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, KWin::AnimationData* data, QEasingCurve::Type curve, int delay)
-{
- return AnimationEffect::set(w, a, metaFromData(data), ms, to, QEasingCurve(curve), delay, from);
-}
-
-bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole)
-{
- void *e = w->data(static_cast(grabRole)).value();
- if (e) {
- return e != this;
- } else {
- return false;
- }
-}
-
-void ScriptedEffect::reconfigure(ReconfigureFlags flags)
-{
- AnimationEffect::reconfigure(flags);
- if (m_config) {
- m_config->readConfig();
- }
- emit configChanged();
-}
-
-void ScriptedEffect::registerShortcut(QAction *a, QScriptValue callback)
-{
- m_shortcutCallbacks.insert(a, callback);
- connect(a, SIGNAL(triggered(bool)), SLOT(globalShortcutTriggered()));
-}
-
-void ScriptedEffect::globalShortcutTriggered()
-{
- callGlobalShortcutCallback(this, sender());
-}
-
-bool ScriptedEffect::borderActivated(ElectricBorder edge)
-{
- screenEdgeActivated(this, edge);
- return true;
-}
-
-QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue)
-{
- if (!m_config) {
- return defaultValue;
- }
- return m_config->property(key);
-}
-
-AnimationData::AnimationData (QObject* parent)
- : QObject (parent)
- , m_sourceAnchor((AnimationEffect::Anchor)0)
- , m_targetAnchor((AnimationEffect::Anchor)0)
- , m_relativeSourceX(0)
- , m_relativeSourceY(0)
- , m_relativeTargetX(0)
- , m_relativeTargetY(0)
- , m_axis((AnimationData::Axis)0)
-{
-}
-
-AnimationData::Axis AnimationData::axis() const
-{
- return m_axis;
-}
-
-int AnimationData::relativeSourceX() const
-{
- return m_relativeSourceX;
-}
-
-int AnimationData::relativeSourceY() const
-{
- return m_relativeSourceY;
-}
-
-int AnimationData::relativeTargetX() const
-{
- return m_relativeTargetX;
-}
-
-int AnimationData::relativeTargetY() const
-{
- return m_relativeTargetY;
-}
-
-void AnimationData::setRelativeSourceX(int relativeSourceX)
-{
- m_relativeSourceX = relativeSourceX;
-}
-
-void AnimationData::setRelativeSourceY(int relativeSourceY)
-{
- m_relativeSourceY = relativeSourceY;
-}
-
-void AnimationData::setRelativeTargetX(int relativeTargetX)
-{
- m_relativeTargetX = relativeTargetX;
-}
-
-void AnimationData::setRelativeTargetY(int relativeTargetY)
-{
- m_relativeTargetY = relativeTargetY;
-}
-
-void AnimationData::setAxis(AnimationData::Axis axis)
-{
- m_axis = axis;
-}
-
-void AnimationData::setSourceAnchor(AnimationEffect::Anchor sourceAnchor)
-{
- m_sourceAnchor = sourceAnchor;
-}
-
-void AnimationData::setTargetAnchor(AnimationEffect::Anchor targetAnchor)
-{
- m_targetAnchor = targetAnchor;
-}
-
-AnimationEffect::Anchor AnimationData::sourceAnchor() const
-{
- return m_sourceAnchor;
-}
-
-AnimationEffect::Anchor AnimationData::targetAnchor() const
-{
- return m_targetAnchor;
-}
-
-} // namespace
diff --git a/kwin/scripting/scriptedeffect.h b/kwin/scripting/scriptedeffect.h
deleted file mode 100644
index 8db3b6b4..00000000
--- a/kwin/scripting/scriptedeffect.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
- Copyright (C) 2012 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#ifndef KWIN_SCRIPTEDEFFECT_H
-#define KWIN_SCRIPTEDEFFECT_H
-
-#include
-
-class QScriptEngine;
-class QScriptValue;
-
-namespace Plasma {
-class ConfigLoader;
-}
-
-namespace KWin
-{
-class ScriptedEffect;
-class AnimationData : public QObject
-{
- Q_OBJECT
- Q_ENUMS(Axis)
- Q_PROPERTY(KWin::AnimationEffect::Anchor sourceAnchor READ sourceAnchor WRITE setSourceAnchor)
- Q_PROPERTY(KWin::AnimationEffect::Anchor targetAnchor READ targetAnchor WRITE setTargetAnchor)
- Q_PROPERTY(int relativeSourceX READ relativeSourceX WRITE setRelativeSourceX)
- Q_PROPERTY(int relativeSourceY READ relativeSourceY WRITE setRelativeSourceY)
- Q_PROPERTY(int relativeTargetX READ relativeTargetX WRITE setRelativeTargetX)
- Q_PROPERTY(int relativeTargetY READ relativeTargetY WRITE setRelativeTargetY)
- Q_PROPERTY(Axis axis READ axis WRITE setAxis)
-public:
- enum Axis {
- XAxis = 1,
- YAxis,
- ZAxis
- };
- explicit AnimationData(QObject* parent = 0);
-
- // getter
- AnimationEffect::Anchor sourceAnchor() const;
- AnimationEffect::Anchor targetAnchor() const;
- int relativeSourceX() const;
- int relativeSourceY() const;
- int relativeTargetX() const;
- int relativeTargetY() const;
- Axis axis() const;
-
- // setter
- void setSourceAnchor(AnimationEffect::Anchor sourceAnchor);
- void setTargetAnchor(AnimationEffect::Anchor targetAnchor);
- void setRelativeSourceX(int relativeSourceX);
- void setRelativeSourceY(int relativeSourceY);
- void setRelativeTargetX(int relativeTargetX);
- void setRelativeTargetY(int relativeTargetY);
- void setAxis(Axis axis);
-
-private:
- AnimationEffect::Anchor m_sourceAnchor;
- AnimationEffect::Anchor m_targetAnchor;
- int m_relativeSourceX;
- int m_relativeSourceY;
- int m_relativeTargetX;
- int m_relativeTargetY;
- Axis m_axis;
-};
-
-class ScriptedEffect : public KWin::AnimationEffect
-{
- Q_OBJECT
- Q_ENUMS(DataRole)
- Q_ENUMS(KWin::AnimationData::Axis)
- Q_ENUMS(Anchor)
- Q_ENUMS(MetaType)
-public:
- // copied from kwineffects.h
- enum DataRole {
- // Grab roles are used to force all other animations to ignore the window.
- // The value of the data is set to the Effect's `this` value.
- WindowAddedGrabRole = 1,
- WindowClosedGrabRole,
- WindowMinimizedGrabRole,
- WindowUnminimizedGrabRole,
- WindowForceBlurRole, ///< For fullscreen effects to enforce blurring of windows,
- WindowBlurBehindRole, ///< For single windows to blur behind
- LanczosCacheRole
- };
- const QString &scriptFile() const {
- return m_scriptFile;
- }
- virtual void reconfigure(ReconfigureFlags flags);
- QString activeConfig() const;
- void setActiveConfig(const QString &name);
- static ScriptedEffect *create(const QString &effectName, const QString &pathToScript);
- virtual ~ScriptedEffect();
- /**
- * Whether another effect has grabbed the @p w with the given @p grabRole.
- * @param w The window to check
- * @param grabRole The grab role to check
- * @returns @c true if another window has grabbed the effect, @c false otherwise
- **/
- Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole);
- /**
- * Reads the value from the configuration data for the given key.
- * @param key The key to search for
- * @param defaultValue The value to return if the key is not found
- * @returns The config value if present
- **/
- Q_SCRIPTABLE QVariant readConfig(const QString &key, const QVariant defaultValue = QVariant());
- void registerShortcut(QAction *a, QScriptValue callback);
- const QHash &shortcutCallbacks() const {
- return m_shortcutCallbacks;
- }
- QHash > &screenEdgeCallbacks() {
- return m_screenEdgeCallbacks;
- }
-
-public Q_SLOTS:
- quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), KWin::AnimationData *data = NULL, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
- quint64 set(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), KWin::AnimationData *data = NULL, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0);
- bool cancel(quint64 animationId) { return AnimationEffect::cancel(animationId); }
- virtual bool borderActivated(ElectricBorder border);
-
-Q_SIGNALS:
- /**
- * Signal emitted whenever the effect's config changed.
- **/
- void configChanged();
-
-private Q_SLOTS:
- void signalHandlerException(const QScriptValue &value);
- void globalShortcutTriggered();
-private:
- ScriptedEffect();
- bool init(const QString &effectName, const QString &pathToScript);
- QScriptEngine *m_engine;
- QString m_effectName;
- QString m_scriptFile;
- QHash m_shortcutCallbacks;
- QHash > m_screenEdgeCallbacks;
- Plasma::ConfigLoader *m_config;
-};
-
-}
-
-#endif // KWIN_SCRIPTEDEFFECT_H
diff --git a/kwin/scripting/scripting.cpp b/kwin/scripting/scripting.cpp
deleted file mode 100644
index c67704de..00000000
--- a/kwin/scripting/scripting.cpp
+++ /dev/null
@@ -1,770 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2010 Rohan Prabhu
-Copyright (C) 2011 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#include "scripting.h"
-// own
-#include "meta.h"
-#include "scriptingutils.h"
-#include "workspace_wrapper.h"
-#include "scripting_model.h"
-#include "../client.h"
-#include "../thumbnailitem.h"
-#include "../options.h"
-#include "../workspace.h"
-// KDE
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-// Qt
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-QScriptValue kwinScriptPrint(QScriptContext *context, QScriptEngine *engine)
-{
- KWin::AbstractScript *script = qobject_cast(context->callee().data().toQObject());
- if (!script) {
- return engine->undefinedValue();
- }
- QString result;
- QTextStream stream(&result);
- for (int i = 0; i < context->argumentCount(); ++i) {
- if (i > 0) {
- stream << " ";
- }
- QScriptValue argument = context->argument(i);
- if (KWin::Client *client = qscriptvalue_cast(argument)) {
- client->print(stream);
- } else {
- stream << argument.toString();
- }
- }
- script->printMessage(result);
-
- return engine->undefinedValue();
-}
-
-QScriptValue kwinScriptReadConfig(QScriptContext *context, QScriptEngine *engine)
-{
- KWin::AbstractScript *script = qobject_cast(context->callee().data().toQObject());
- if (!script) {
- return engine->undefinedValue();
- }
- if (context->argumentCount() < 1 || context->argumentCount() > 2) {
- kDebug(1212) << "Incorrect number of arguments";
- return engine->undefinedValue();
- }
- const QString key = context->argument(0).toString();
- QVariant defaultValue;
- if (context->argumentCount() == 2) {
- defaultValue = context->argument(1).toVariant();
- }
- return engine->newVariant(script->config().readEntry(key, defaultValue));
-}
-
-QScriptValue kwinScriptGlobalShortcut(QScriptContext *context, QScriptEngine *engine)
-{
- return KWin::globalShortcut(context, engine);
-}
-
-QScriptValue kwinAssertTrue(QScriptContext *context, QScriptEngine *engine)
-{
- return KWin::scriptingAssert(context, engine, 1, 2, true);
-}
-
-QScriptValue kwinAssertFalse(QScriptContext *context, QScriptEngine *engine)
-{
- return KWin::scriptingAssert(context, engine, 1, 2, false);
-}
-
-QScriptValue kwinAssertEquals(QScriptContext *context, QScriptEngine *engine)
-{
- return KWin::scriptingAssert(context, engine, 2, 3);
-}
-
-QScriptValue kwinAssertNull(QScriptContext *context, QScriptEngine *engine)
-{
- if (!KWin::validateParameters(context, 1, 2)) {
- return engine->undefinedValue();
- }
- if (!context->argument(0).isNull()) {
- if (context->argumentCount() == 2) {
- context->throwError(QScriptContext::UnknownError, context->argument(1).toString());
- } else {
- context->throwError(QScriptContext::UnknownError,
- i18nc("Assertion failed in KWin script with given value",
- "Assertion failed: %1 is not null", context->argument(0).toString()));
- }
- return engine->undefinedValue();
- }
- return true;
-}
-
-QScriptValue kwinAssertNotNull(QScriptContext *context, QScriptEngine *engine)
-{
- if (!KWin::validateParameters(context, 1, 2)) {
- return engine->undefinedValue();
- }
- if (context->argument(0).isNull()) {
- if (context->argumentCount() == 2) {
- context->throwError(QScriptContext::UnknownError, context->argument(1).toString());
- } else {
- context->throwError(QScriptContext::UnknownError,
- i18nc("Assertion failed in KWin script",
- "Assertion failed: argument is null"));
- }
- return engine->undefinedValue();
- }
- return true;
-}
-
-QScriptValue kwinRegisterScreenEdge(QScriptContext *context, QScriptEngine *engine)
-{
- return KWin::registerScreenEdge(context, engine);
-}
-
-QScriptValue kwinRegisterUserActionsMenu(QScriptContext *context, QScriptEngine *engine)
-{
- return KWin::registerUserActionsMenu(context, engine);
-}
-
-QScriptValue kwinCallDBus(QScriptContext *context, QScriptEngine *engine)
-{
- KWin::AbstractScript *script = qobject_cast(context->callee().data().toQObject());
- if (!script) {
- context->throwError(QScriptContext::UnknownError, "Internal Error: script not registered");
- return engine->undefinedValue();
- }
- if (context->argumentCount() < 4) {
- context->throwError(QScriptContext::SyntaxError,
- i18nc("Error in KWin Script",
- "Invalid number of arguments. At least service, path, interface and method need to be provided"));
- return engine->undefinedValue();
- }
- if (!KWin::validateArgumentType(context)) {
- context->throwError(QScriptContext::SyntaxError,
- i18nc("Error in KWin Script",
- "Invalid type. Service, path, interface and method need to be string values"));
- return engine->undefinedValue();
- }
- const QString service = context->argument(0).toString();
- const QString path = context->argument(1).toString();
- const QString interface = context->argument(2).toString();
- const QString method = context->argument(3).toString();
- int argumentsCount = context->argumentCount();
- if (context->argument(argumentsCount-1).isFunction()) {
- --argumentsCount;
- }
- QDBusMessage msg = QDBusMessage::createMethodCall(service, path, interface, method);
- QVariantList arguments;
- for (int i=4; iargument(i).isArray()) {
- QStringList stringArray = engine->fromScriptValue(context->argument(i));
- arguments << qVariantFromValue(stringArray);
- } else {
- arguments << context->argument(i).toVariant();
- }
- }
- if (!arguments.isEmpty()) {
- msg.setArguments(arguments);
- }
- if (argumentsCount == context->argumentCount()) {
- // no callback, just fire and forget
- QDBusConnection::sessionBus().asyncCall(msg);
- } else {
- // with a callback
- QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall(msg), script);
- watcher->setProperty("callback", script->registerCallback(context->argument(context->argumentCount()-1)));
- QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), script, SLOT(slotPendingDBusCall(QDBusPendingCallWatcher*)));
- }
- return engine->undefinedValue();
-}
-
-KWin::AbstractScript::AbstractScript(int id, QString scriptName, QString pluginName, QObject *parent)
- : QObject(parent)
- , m_scriptId(id)
- , m_pluginName(pluginName)
- , m_running(false)
- , m_workspace(new WorkspaceWrapper(this))
-{
- m_scriptFile.setFileName(scriptName);
- if (m_pluginName.isNull()) {
- m_pluginName = scriptName;
- }
-}
-
-KWin::AbstractScript::~AbstractScript()
-{
-}
-
-KConfigGroup KWin::AbstractScript::config() const
-{
- return KGlobal::config()->group("Script-" + m_pluginName);
-}
-
-void KWin::AbstractScript::stop()
-{
- deleteLater();
-}
-
-void KWin::AbstractScript::printMessage(const QString &message)
-{
- kDebug(1212) << scriptFile().fileName() << ":" << message;
- emit print(message);
-}
-
-void KWin::AbstractScript::registerShortcut(QAction *a, QScriptValue callback)
-{
- m_shortcutCallbacks.insert(a, callback);
- connect(a, SIGNAL(triggered(bool)), SLOT(globalShortcutTriggered()));
-}
-
-void KWin::AbstractScript::globalShortcutTriggered()
-{
- callGlobalShortcutCallback(this, sender());
-}
-
-bool KWin::AbstractScript::borderActivated(KWin::ElectricBorder edge)
-{
- screenEdgeActivated(this, edge);
- return true;
-}
-
-void KWin::AbstractScript::installScriptFunctions(QScriptEngine* engine)
-{
- // add our print
- QScriptValue printFunc = engine->newFunction(kwinScriptPrint);
- printFunc.setData(engine->newQObject(this));
- engine->globalObject().setProperty("print", printFunc);
- // add read config
- QScriptValue configFunc = engine->newFunction(kwinScriptReadConfig);
- configFunc.setData(engine->newQObject(this));
- engine->globalObject().setProperty("readConfig", configFunc);
- QScriptValue dbusCallFunc = engine->newFunction(kwinCallDBus);
- dbusCallFunc.setData(engine->newQObject(this));
- engine->globalObject().setProperty("callDBus", dbusCallFunc);
- // add global Shortcut
- registerGlobalShortcutFunction(this, engine, kwinScriptGlobalShortcut);
- // add screen edge
- registerScreenEdgeFunction(this, engine, kwinRegisterScreenEdge);
- // add user actions menu register function
- regesterUserActionsMenuFunction(this, engine, kwinRegisterUserActionsMenu);
- // add assertions
- QScriptValue assertTrueFunc = engine->newFunction(kwinAssertTrue);
- engine->globalObject().setProperty("assertTrue", assertTrueFunc);
- engine->globalObject().setProperty("assert", assertTrueFunc);
- QScriptValue assertFalseFunc = engine->newFunction(kwinAssertFalse);
- engine->globalObject().setProperty("assertFalse", assertFalseFunc);
- QScriptValue assertEqualsFunc = engine->newFunction(kwinAssertEquals);
- engine->globalObject().setProperty("assertEquals", assertEqualsFunc);
- QScriptValue assertNullFunc = engine->newFunction(kwinAssertNull);
- engine->globalObject().setProperty("assertNull", assertNullFunc);
- engine->globalObject().setProperty("assertEquals", assertEqualsFunc);
- QScriptValue assertNotNullFunc = engine->newFunction(kwinAssertNotNull);
- engine->globalObject().setProperty("assertNotNull", assertNotNullFunc);
- // 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);
-}
-
-int KWin::AbstractScript::registerCallback(QScriptValue value)
-{
- int id = m_callbacks.size();
- m_callbacks.insert(id, value);
- return id;
-}
-
-void KWin::AbstractScript::slotPendingDBusCall(QDBusPendingCallWatcher* watcher)
-{
- if (watcher->isError()) {
- kDebug(1212) << "Received D-Bus message is error";
- watcher->deleteLater();
- return;
- }
- const int id = watcher->property("callback").toInt();
- QDBusMessage reply = watcher->reply();
- QScriptValue callback (m_callbacks.value(id));
- QScriptValueList arguments;
- foreach (const QVariant &argument, reply.arguments()) {
- arguments << callback.engine()->newVariant(argument);
- }
- callback.call(QScriptValue(), arguments);
- m_callbacks.remove(id);
- watcher->deleteLater();
-}
-
-void KWin::AbstractScript::registerUseractionsMenuCallback(QScriptValue callback)
-{
- m_userActionsMenuCallbacks.append(callback);
-}
-
-QList< QAction * > KWin::AbstractScript::actionsForUserActionMenu(KWin::Client *c, QMenu *parent)
-{
- QList returnActions;
- for (QList::const_iterator it = m_userActionsMenuCallbacks.constBegin(); it != m_userActionsMenuCallbacks.constEnd(); ++it) {
- QScriptValue callback(*it);
- QScriptValueList arguments;
- arguments << callback.engine()->newQObject(c);
- QScriptValue actions = callback.call(QScriptValue(), arguments);
- if (!actions.isValid() || actions.isUndefined() || actions.isNull()) {
- // script does not want to handle this Client
- continue;
- }
- if (actions.isObject()) {
- QAction *a = scriptValueToAction(actions, parent);
- if (a) {
- returnActions << a;
- }
- }
- }
-
- return returnActions;
-}
-
-QAction *KWin::AbstractScript::scriptValueToAction(QScriptValue &value, QMenu *parent)
-{
- QScriptValue titleValue = value.property("text");
- QScriptValue checkableValue = value.property("checkable");
- QScriptValue checkedValue = value.property("checked");
- QScriptValue itemsValue = value.property("items");
- QScriptValue triggeredValue = value.property("triggered");
-
- if (!titleValue.isValid()) {
- // title not specified - does not make any sense to include
- return NULL;
- }
- const QString title = titleValue.toString();
- const bool checkable = checkableValue.isValid() && checkableValue.toBool();
- const bool checked = checkable && checkedValue.isValid() && checkedValue.toBool();
- // either a menu or a menu item
- if (itemsValue.isValid()) {
- if (!itemsValue.isArray()) {
- // not an array, so cannot be a menu
- return NULL;
- }
- QScriptValue lengthValue = itemsValue.property("length");
- if (!lengthValue.isValid() || !lengthValue.isNumber() || lengthValue.toInteger() == 0) {
- // length property missing
- return NULL;
- }
- return createMenu(title, itemsValue, parent);
- } else if (triggeredValue.isValid()) {
- // normal item
- return createAction(title, checkable, checked, triggeredValue, parent);
- }
- return NULL;
-}
-
-QAction *KWin::AbstractScript::createAction(const QString &title, bool checkable, bool checked, QScriptValue &callback, QMenu *parent)
-{
- QAction *action = new QAction(title, parent);
- action->setCheckable(checkable);
- action->setChecked(checked);
- // TODO: rename m_shortcutCallbacks
- m_shortcutCallbacks.insert(action, callback);
- connect(action, SIGNAL(triggered(bool)), SLOT(globalShortcutTriggered()));
- connect(action, SIGNAL(destroyed(QObject*)), SLOT(actionDestroyed(QObject*)));
- return action;
-}
-
-QAction *KWin::AbstractScript::createMenu(const QString &title, QScriptValue &items, QMenu *parent)
-{
- QMenu *menu = new QMenu(title, parent);
- const int length = static_cast(items.property("length").toInteger());
- for (int i=0; iaddAction(a);
- }
- }
- }
- return menu->menuAction();
-}
-
-void KWin::AbstractScript::actionDestroyed(QObject *object)
-{
- // TODO: Qt 5 - change to lambda function
- m_shortcutCallbacks.remove(static_cast(object));
-}
-
-KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject* parent)
- : AbstractScript(id, scriptName, pluginName, parent)
- , m_engine(new QScriptEngine(this))
- , m_starting(false)
- , m_agent(new ScriptUnloaderAgent(this))
-{
- QDBusConnection::sessionBus().registerObject('/' + QString::number(scriptId()), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportScriptableInvokables);
-}
-
-KWin::Script::~Script()
-{
- QDBusConnection::sessionBus().unregisterObject('/' + QString::number(scriptId()));
-}
-
-void KWin::Script::run()
-{
- if (running() || m_starting) {
- return;
- }
- m_starting = true;
- QFutureWatcher *watcher = new QFutureWatcher(this);
- connect(watcher, SIGNAL(finished()), SLOT(slotScriptLoadedFromFile()));
- watcher->setFuture(QtConcurrent::run(this, &KWin::Script::loadScriptFromFile));
-}
-
-QByteArray KWin::Script::loadScriptFromFile()
-{
- if (!scriptFile().open(QIODevice::ReadOnly)) {
- return QByteArray();
- }
- QByteArray result(scriptFile().readAll());
- scriptFile().close();
- return result;
-}
-
-void KWin::Script::slotScriptLoadedFromFile()
-{
- QFutureWatcher *watcher = dynamic_cast< QFutureWatcher< QByteArray>* >(sender());
- if (!watcher) {
- // not invoked from a QFutureWatcher
- return;
- }
- if (watcher->result().isNull()) {
- // do not load empty script
- deleteLater();
- watcher->deleteLater();
- return;
- }
- QScriptValue optionsValue = m_engine->newQObject(options, QScriptEngine::QtOwnership,
- QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater);
- m_engine->globalObject().setProperty("options", optionsValue, QScriptValue::Undeletable);
- m_engine->globalObject().setProperty("QTimer", constructTimerClass(m_engine));
- QObject::connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), this, SLOT(sigException(QScriptValue)));
- KWin::MetaScripting::supplyConfig(m_engine);
- installScriptFunctions(m_engine);
-
- QScriptValue ret = m_engine->evaluate(watcher->result());
-
- if (ret.isError()) {
- sigException(ret);
- deleteLater();
- }
-
- watcher->deleteLater();
- setRunning(true);
- m_starting = false;
-}
-
-void KWin::Script::sigException(const QScriptValue& exception)
-{
- QScriptValue ret = exception;
- if (ret.isError()) {
- kDebug(1212) << "defaultscript encountered an error at [Line " << m_engine->uncaughtExceptionLineNumber() << "]";
- kDebug(1212) << "Message: " << ret.toString();
- kDebug(1212) << "-----------------";
-
- QScriptValueIterator iter(ret);
- while (iter.hasNext()) {
- iter.next();
- qDebug() << " " << iter.name() << ": " << iter.value().toString();
- }
- }
- emit printError(exception.toString());
- stop();
-}
-
-KWin::ScriptUnloaderAgent::ScriptUnloaderAgent(KWin::Script *script)
- : QScriptEngineAgent(script->engine())
- , m_script(script)
-{
- script->engine()->setAgent(this);
-}
-
-void KWin::ScriptUnloaderAgent::scriptUnload(qint64 id)
-{
- Q_UNUSED(id)
- m_script->stop();
-}
-
-KWin::DeclarativeScript::DeclarativeScript(int id, QString scriptName, QString pluginName, QObject* parent)
- : AbstractScript(id, scriptName, pluginName, parent)
- , m_engine(new QDeclarativeEngine(this))
- , m_component(new QDeclarativeComponent(m_engine, this))
- , m_scene(new QGraphicsScene(this))
-{
-}
-
-KWin::DeclarativeScript::~DeclarativeScript()
-{
-}
-
-void KWin::DeclarativeScript::run()
-{
- if (running()) {
- return;
- }
- // add read config
- KDeclarative kdeclarative;
- kdeclarative.setDeclarativeEngine(m_engine);
- kdeclarative.initialize();
- kdeclarative.setupBindings();
- installScriptFunctions(kdeclarative.scriptEngine());
- qmlRegisterType("org.kde.kwin", 0, 1, "DesktopThumbnailItem");
- qmlRegisterType("org.kde.kwin", 0, 1, "ThumbnailItem");
- qmlRegisterType();
- qmlRegisterType("org.kde.kwin", 0, 1, "ClientModel");
- qmlRegisterType("org.kde.kwin", 0, 1, "ClientModelByScreen");
- qmlRegisterType("org.kde.kwin", 0, 1, "ClientModelByScreenAndDesktop");
- qmlRegisterType("org.kde.kwin", 0, 1, "ClientFilterModel");
- qmlRegisterType();
-
- m_engine->rootContext()->setContextProperty("options", options);
-
- m_component->loadUrl(QUrl::fromLocalFile(scriptFile().fileName()));
- if (m_component->isLoading()) {
- connect(m_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), SLOT(createComponent()));
- } else {
- createComponent();
- }
-}
-
-void KWin::DeclarativeScript::createComponent()
-{
- if (m_component->isError()) {
- kDebug(1212) << "Component failed to load: " << m_component->errors();
- } else {
- m_scene->addItem(qobject_cast(m_component->create()));
- }
- 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))
-{
- QDBusConnection::sessionBus().registerObject("/Scripting", this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportScriptableInvokables);
- QDBusConnection::sessionBus().registerService("org.kde.kwin.Scripting");
- connect(Workspace::self(), SIGNAL(configChanged()), SLOT(start()));
- connect(Workspace::self(), SIGNAL(workspaceInitialized()), SLOT(start()));
-}
-
-void KWin::Scripting::start()
-{
-#if 0
- // TODO make this threaded again once KConfigGroup is sufficiently thread safe, bug #305361 and friends
- // perform querying for the services in a thread
- QFutureWatcher *watcher = new QFutureWatcher(this);
- connect(watcher, SIGNAL(finished()), this, SLOT(slotScriptsQueried()));
- watcher->setFuture(QtConcurrent::run(this, &KWin::Scripting::queryScriptsToLoad, pluginStates, offers));
-#else
- LoadScriptList scriptsToLoad = queryScriptsToLoad();
- for (LoadScriptList::const_iterator it = scriptsToLoad.constBegin();
- it != scriptsToLoad.constEnd();
- ++it) {
- if (it->first) {
- loadScript(it->second.first, it->second.second);
- } else {
- loadDeclarativeScript(it->second.first, it->second.second);
- }
- }
-
- runScripts();
-#endif
-}
-
-LoadScriptList KWin::Scripting::queryScriptsToLoad()
-{
- KSharedConfig::Ptr _config = KGlobal::config();
- static bool s_started = false;
- if (s_started) {
- _config->reparseConfiguration();
- } else {
- s_started = true;
- }
- QMap pluginStates = KConfigGroup(_config, "Plugins").entryMap();
- KService::List offers = KServiceTypeTrader::self()->query("KWin/Script");
-
- LoadScriptList scriptsToLoad;
-
- foreach (const KService::Ptr & service, offers) {
- KPluginInfo plugininfo(service);
- const QString value = pluginStates.value(plugininfo.pluginName() + QString::fromLatin1("Enabled"), QString());
- plugininfo.setPluginEnabled(value.isNull() ? plugininfo.isPluginEnabledByDefault() : QVariant(value).toBool());
- const bool javaScript = service->property("X-Plasma-API").toString() == "javascript";
- const bool declarativeScript = service->property("X-Plasma-API").toString() == "declarativescript";
- if (!javaScript && !declarativeScript) {
- continue;
- }
-
- if (!plugininfo.isPluginEnabled()) {
- if (isScriptLoaded(plugininfo.pluginName())) {
- // unload the script
- unloadScript(plugininfo.pluginName());
- }
- 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", QLatin1String(KWIN_NAME) + "/scripts/" + pluginName + "/contents/" + scriptName);
- if (file.isNull()) {
- kDebug(1212) << "Could not find script file for " << pluginName;
- continue;
- }
- scriptsToLoad << qMakePair(javaScript, qMakePair(file, pluginName));
- }
- return scriptsToLoad;
-}
-
-void KWin::Scripting::slotScriptsQueried()
-{
- QFutureWatcher *watcher = dynamic_cast< QFutureWatcher* >(sender());
- if (!watcher) {
- // slot invoked not from a FutureWatcher
- return;
- }
-
- LoadScriptList scriptsToLoad = watcher->result();
- for (LoadScriptList::const_iterator it = scriptsToLoad.constBegin();
- it != scriptsToLoad.constEnd();
- ++it) {
- if (it->first) {
- loadScript(it->second.first, it->second.second);
- } else {
- loadDeclarativeScript(it->second.first, it->second.second);
- }
- }
-
- runScripts();
- watcher->deleteLater();
-}
-
-bool KWin::Scripting::isScriptLoaded(const QString &pluginName) const
-{
- QMutexLocker locker(m_scriptsLock.data());
- foreach (AbstractScript *script, scripts) {
- if (script->pluginName() == pluginName) {
- return true;
- }
- }
- return false;
-}
-
-bool KWin::Scripting::unloadScript(const QString &pluginName)
-{
- QMutexLocker locker(m_scriptsLock.data());
- foreach (AbstractScript *script, scripts) {
- if (script->pluginName() == pluginName) {
- script->deleteLater();
- return true;
- }
- }
- return false;
-}
-
-void KWin::Scripting::runScripts()
-{
- QMutexLocker locker(m_scriptsLock.data());
- for (int i = 0; i < scripts.size(); i++) {
- scripts.at(i)->run();
- }
-}
-
-void KWin::Scripting::scriptDestroyed(QObject *object)
-{
- QMutexLocker locker(m_scriptsLock.data());
- scripts.removeAll(static_cast(object));
-}
-
-int KWin::Scripting::loadScript(const QString &filePath, const QString& pluginName)
-{
- QMutexLocker locker(m_scriptsLock.data());
- if (isScriptLoaded(pluginName)) {
- return -1;
- }
- const int id = scripts.size();
- KWin::Script *script = new KWin::Script(id, filePath, pluginName, this);
- connect(script, SIGNAL(destroyed(QObject*)), SLOT(scriptDestroyed(QObject*)));
- scripts.append(script);
- return id;
-}
-
-int KWin::Scripting::loadDeclarativeScript(const QString& filePath, const QString& pluginName)
-{
- QMutexLocker locker(m_scriptsLock.data());
- if (isScriptLoaded(pluginName)) {
- return -1;
- }
- const int id = scripts.size();
- KWin::DeclarativeScript *script = new KWin::DeclarativeScript(id, filePath, pluginName, this);
- connect(script, SIGNAL(destroyed(QObject*)), SLOT(scriptDestroyed(QObject*)));
- scripts.append(script);
- return id;
-}
-
-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)
-{
- QList actions;
- foreach (AbstractScript *script, scripts) {
- actions << script->actionsForUserActionMenu(c, parent);
- }
- return actions;
-}
-
-#include "scripting.moc"
diff --git a/kwin/scripting/scripting.h b/kwin/scripting/scripting.h
deleted file mode 100644
index e8a56b2d..00000000
--- a/kwin/scripting/scripting.h
+++ /dev/null
@@ -1,346 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2010 Rohan Prabhu
-Copyright (C) 2011 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#ifndef KWIN_SCRIPTING_H
-#define KWIN_SCRIPTING_H
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-class QDeclarativeComponent;
-class QDeclarativeEngine;
-class QAction;
-class QDBusPendingCallWatcher;
-class QGraphicsScene;
-class QMenu;
-class QMutex;
-class QScriptEngine;
-class QScriptValue;
-class KConfigGroup;
-
-/// @c true == javascript, @c false == qml
-typedef QList< QPair > > LoadScriptList;
-
-namespace KWin
-{
-class Client;
-class ScriptUnloaderAgent;
-class WorkspaceWrapper;
-
-class AbstractScript : public QObject
-{
- Q_OBJECT
-public:
- AbstractScript(int id, QString scriptName, QString pluginName, QObject *parent = NULL);
- ~AbstractScript();
- QString fileName() const {
- return m_scriptFile.fileName();
- }
- const QString &pluginName() {
- return m_pluginName;
- }
-
- void printMessage(const QString &message);
- void registerShortcut(QAction *a, QScriptValue callback);
- /**
- * @brief Registers the given @p callback to be invoked whenever the UserActionsMenu is about
- * to be showed. In the callback the script can create a further sub menu or menu entry to be
- * added to the UserActionsMenu.
- *
- * @param callback Script method to execute when the UserActionsMenu is about to be shown.
- * @return void
- * @see actionsForUserActionMenu
- **/
- void registerUseractionsMenuCallback(QScriptValue callback);
- /**
- * @brief Creates actions for the UserActionsMenu by invoking the registered callbacks.
- *
- * This method invokes all the callbacks previously registered with registerUseractionsMenuCallback.
- * The Client @p c is passed in as an argument to the invoked method.
- *
- * The invoked method is supposed to return a JavaScript object containing either the menu or
- * menu entry to be added. In case the callback returns a null or undefined or any other invalid
- * value, it is not considered for adding to the menu.
- *
- * The JavaScript object structure for a menu entry looks like the following:
- * @code
- * {
- * title: "My Menu Entry",
- * checkable: true,
- * checked: false,
- * triggered: function (action) {
- * // callback when the menu entry is triggered with the QAction as argument
- * }
- * }
- * @endcode
- *
- * To construct a complete Menu the JavaScript object looks like the following:
- * @code
- * {
- * title: "My Menu Title",
- * items: [{...}, {...}, ...] // list of menu entries as described above
- * }
- * @endcode
- *
- * The returned JavaScript object is introspected and for a menu entry a QAction is created,
- * while for a menu a QMenu is created and QActions for the individual entries. Of course it
- * is allowed to have nested structures.
- *
- * All created objects are (grand) children to the passed in @p parent menu, so that they get
- * deleted whenever the menu is destroyed.
- *
- * @param c The Client for which the menu is invoked, passed to the callback
- * @param parent The Parent for the created Menus or Actions
- * @return QList< QAction* > List of QActions obtained from asking the registered callbacks
- * @see registerUseractionsMenuCallback
- **/
- QList actionsForUserActionMenu(Client *c, QMenu *parent);
-
- KConfigGroup config() const;
- const QHash &shortcutCallbacks() const {
- return m_shortcutCallbacks;
- }
- QHash > &screenEdgeCallbacks() {
- return m_screenEdgeCallbacks;
- }
-
- int registerCallback(QScriptValue value);
-
-public Q_SLOTS:
- Q_SCRIPTABLE void stop();
- Q_SCRIPTABLE virtual void run() = 0;
- void slotPendingDBusCall(QDBusPendingCallWatcher *watcher);
-
-private Q_SLOTS:
- void globalShortcutTriggered();
- bool borderActivated(ElectricBorder edge);
- /**
- * @brief Slot invoked when a menu action is destroyed. Used to remove the action and callback
- * from the map of actions.
- *
- * @param object The destroyed action
- **/
- void actionDestroyed(QObject *object);
-
-Q_SIGNALS:
- Q_SCRIPTABLE void print(const QString &text);
-
-protected:
- QFile &scriptFile() {
- return m_scriptFile;
- }
- bool running() const {
- return m_running;
- }
- void setRunning(bool running) {
- m_running = running;
- }
- int scriptId() const {
- return m_scriptId;
- }
-
- WorkspaceWrapper *workspace() {
- return m_workspace;
- }
-
- void installScriptFunctions(QScriptEngine *engine);
-
-private:
- /**
- * @brief Parses the @p value to either a QMenu or QAction.
- *
- * @param value The ScriptValue describing either a menu or action
- * @param parent The parent to use for the created menu or action
- * @return QAction* The parsed action or menu action, if parsing fails returns @c null.
- **/
- QAction *scriptValueToAction(QScriptValue &value, QMenu *parent);
- /**
- * @brief Creates a new QAction from the provided data and registers it for invoking the
- * @p callback when the action is triggered.
- *
- * The created action is added to the map of actions and callbacks shared with the global
- * shortcuts.
- *
- * @param title The title of the action
- * @param checkable Whether the action is checkable
- * @param checked Whether the checkable action is checked
- * @param callback The callback to invoke when the action is triggered
- * @param parent The parent to be used for the new created action
- * @return QAction* The created action
- **/
- QAction *createAction(const QString &title, bool checkable, bool checked, QScriptValue &callback, QMenu *parent);
- /**
- * @brief Parses the @p items and creates a QMenu from it.
- *
- * @param title The title of the Menu.
- * @param items JavaScript Array containing Menu items.
- * @param parent The parent to use for the new created menu
- * @return QAction* The menu action for the new Menu
- **/
- QAction *createMenu(const QString &title, QScriptValue &items, QMenu *parent);
- int m_scriptId;
- QFile m_scriptFile;
- QString m_pluginName;
- bool m_running;
- WorkspaceWrapper *m_workspace;
- QHash m_shortcutCallbacks;
- QHash > m_screenEdgeCallbacks;
- QHash m_callbacks;
- /**
- * @brief List of registered functions to call when the UserActionsMenu is about to show
- * to add further entries.
- **/
- QList m_userActionsMenuCallbacks;
-};
-
-class Script : public AbstractScript
-{
- Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
-public:
-
- Script(int id, QString scriptName, QString pluginName, QObject *parent = NULL);
- virtual ~Script();
- QScriptEngine *engine() {
- return m_engine;
- }
-
-public Q_SLOTS:
- Q_SCRIPTABLE void run();
-
-Q_SIGNALS:
- Q_SCRIPTABLE void printError(const QString &text);
-
-private slots:
- /**
- * A nice clean way to handle exceptions in scripting.
- * TODO: Log to file, show from notifier..
- */
- void sigException(const QScriptValue &exception);
- /**
- * Callback for when loadScriptFromFile has finished.
- **/
- void slotScriptLoadedFromFile();
-
-private:
- /**
- * Read the script from file into a byte array.
- * If file cannot be read an empty byte array is returned.
- **/
- QByteArray loadScriptFromFile();
- QScriptEngine *m_engine;
- bool m_starting;
- QScopedPointer m_agent;
-};
-
-class ScriptUnloaderAgent : public QScriptEngineAgent
-{
-public:
- explicit ScriptUnloaderAgent(Script *script);
- virtual void scriptUnload(qint64 id);
-
-private:
- Script *m_script;
-};
-
-class DeclarativeScript : public AbstractScript
-{
- Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
-public:
- explicit DeclarativeScript(int id, QString scriptName, QString pluginName, QObject *parent = 0);
- virtual ~DeclarativeScript();
-
-public Q_SLOTS:
- Q_SCRIPTABLE void run();
-
-private Q_SLOTS:
- void createComponent();
-
-private:
- QDeclarativeEngine *m_engine;
- QDeclarativeComponent *m_component;
- QGraphicsScene *m_scene;
-};
-
-/**
- * The heart of KWin::Scripting. Infinite power lies beyond
- */
-class Scripting : public QObject
-{
- Q_OBJECT
- Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Scripting")
-private:
- explicit Scripting(QObject *parent);
- QStringList scriptList;
- QList scripts;
- /**
- * Lock to protect the scripts member variable.
- **/
- QScopedPointer m_scriptsLock;
-
- // Preferably call ONLY at load time
- void runScripts();
-
-public:
- ~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());
- Q_SCRIPTABLE Q_INVOKABLE bool isScriptLoaded(const QString &pluginName) const;
- Q_SCRIPTABLE Q_INVOKABLE bool unloadScript(const QString &pluginName);
-
- /**
- * @brief Invokes all registered callbacks to add actions to the UserActionsMenu.
- *
- * @param c The Client for which the UserActionsMenu is about to be shown
- * @param parent The parent menu to which to add created child menus and items
- * @return QList< QAction* > List of all actions aggregated from all scripts.
- **/
- 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();
-
-private Q_SLOTS:
- void slotScriptsQueried();
-
-private:
- LoadScriptList queryScriptsToLoad();
- static Scripting *s_self;
-};
-
-inline
-Scripting *Scripting::self()
-{
- return s_self;
-}
-
-}
-#endif
diff --git a/kwin/scripting/scripting_model.cpp b/kwin/scripting/scripting_model.cpp
deleted file mode 100644
index 75929323..00000000
--- a/kwin/scripting/scripting_model.cpp
+++ /dev/null
@@ -1,852 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2013 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-#include "scripting_model.h"
-#include "activities.h"
-#include "client.h"
-#include "screens.h"
-#include "workspace.h"
-
-#include
-
-namespace KWin {
-namespace ScriptingClientModel {
-
-static quint32 nextId() {
- static quint32 counter = 0;
- return ++counter;
-}
-
-ClientLevel::ClientLevel(ClientModel *model, AbstractLevel *parent)
- : AbstractLevel(model, parent)
-{
- connect(Workspace::self(), SIGNAL(clientAdded(KWin::Client*)), SLOT(clientAdded(KWin::Client*)));
- connect(Workspace::self(), SIGNAL(clientRemoved(KWin::Client*)), SLOT(clientRemoved(KWin::Client*)));
- connect(model, SIGNAL(exclusionsChanged()), SLOT(reInit()));
-}
-
-ClientLevel::~ClientLevel()
-{
-}
-
-void ClientLevel::clientAdded(Client *client)
-{
- setupClientConnections(client);
- checkClient(client);
-}
-
-void ClientLevel::clientRemoved(Client *client)
-{
- removeClient(client);
-}
-
-void ClientLevel::setupClientConnections(Client *client)
-{
- connect(client, SIGNAL(desktopChanged()), SLOT(checkClient()));
- connect(client, SIGNAL(screenChanged()), SLOT(checkClient()));
- connect(client, SIGNAL(activitiesChanged(KWin::Toplevel*)), SLOT(checkClient()));
-}
-
-void ClientLevel::checkClient()
-{
- checkClient(static_cast(sender()));
-}
-
-void ClientLevel::checkClient(Client *client)
-{
- const bool shouldInclude = !exclude(client) && shouldAdd(client);
- const bool contains = containsClient(client);
-
- if (shouldInclude && !contains) {
- addClient(client);
- } else if (!shouldInclude && contains) {
- removeClient(client);
- }
-}
-
-bool ClientLevel::exclude(Client *client) const
-{
- ClientModel::Exclusions exclusions = model()->exclusions();
- if (exclusions == ClientModel::NoExclusion) {
- return false;
- }
- if (exclusions & ClientModel::DesktopWindowsExclusion) {
- if (client->isDesktop()) {
- return true;
- }
- }
- if (exclusions & ClientModel::DockWindowsExclusion) {
- if (client->isDock()) {
- return true;
- }
- }
- if (exclusions & ClientModel::UtilityWindowsExclusion) {
- if (client->isUtility()) {
- return true;
- }
- }
- if (exclusions & ClientModel::SpecialWindowsExclusion) {
- if (client->isSpecialWindow()) {
- return true;
- }
- }
- if (exclusions & ClientModel::SkipTaskbarExclusion) {
- if (client->skipTaskbar()) {
- return true;
- }
- }
- if (exclusions & ClientModel::SkipPagerExclusion) {
- if (client->skipPager()) {
- return true;
- }
- }
- if (exclusions & ClientModel::SwitchSwitcherExclusion) {
- if (client->skipSwitcher()) {
- return true;
- }
- }
- if (exclusions & ClientModel::OtherDesktopsExclusion) {
- if (!client->isOnCurrentDesktop()) {
- return true;
- }
- }
- if (exclusions & ClientModel::OtherActivitiesExclusion) {
- if (!client->isOnCurrentActivity()) {
- return true;
- }
- }
- if (exclusions & ClientModel::MinimizedExclusion) {
- if (client->isMinimized()) {
- return true;
- }
- }
- if (exclusions & ClientModel::NonSelectedWindowTabExclusion) {
- if (!client->isCurrentTab()) {
- return true;
- }
- }
- if (exclusions & ClientModel::NotAcceptingFocusExclusion) {
- if (!client->wantsInput()) {
- return true;
- }
- }
- return false;
-}
-
-bool ClientLevel::shouldAdd(Client *client) const
-{
- if (restrictions() == ClientModel::NoRestriction) {
- return true;
- }
- if (restrictions() & ClientModel::ActivityRestriction) {
- if (!client->isOnActivity(activity())) {
- return false;
- }
- }
- if (restrictions() & ClientModel::VirtualDesktopRestriction) {
- if (!client->isOnDesktop(virtualDesktop())) {
- return false;
- }
- }
- if (restrictions() & ClientModel::ScreenRestriction) {
- if (client->screen() != int(screen())) {
- return false;
- }
- }
- return true;
-}
-
-void ClientLevel::addClient(Client *client)
-{
- if (containsClient(client)) {
- return;
- }
- emit beginInsert(m_clients.count(), m_clients.count(), id());
- m_clients.insert(nextId(), client);
- emit endInsert();
-}
-
-void ClientLevel::removeClient(Client *client)
-{
- int index = 0;
- QMap::iterator it = m_clients.begin();
- for (; it != m_clients.end(); ++it, ++index) {
- if (it.value() == client) {
- break;
- }
- }
- if (it == m_clients.end()) {
- return;
- }
- emit beginRemove(index, index, id());
- m_clients.erase(it);
- emit endRemove();
-}
-
-void ClientLevel::init()
-{
- const ClientList &clients = Workspace::self()->clientList();
- for (ClientList::const_iterator it = clients.begin(); it != clients.end(); ++it) {
- Client *client = *it;
- setupClientConnections(client);
- if (!exclude(client) && shouldAdd(client)) {
- m_clients.insert(nextId(), client);
- }
- }
-}
-
-void ClientLevel::reInit()
-{
- const ClientList &clients = Workspace::self()->clientList();
- for (ClientList::const_iterator it = clients.begin(); it != clients.end(); ++it) {
- checkClient((*it));
- }
-}
-
-quint32 ClientLevel::idForRow(int row) const
-{
- if (row >= m_clients.size()) {
- return 0;
- }
- QMap::const_iterator it = m_clients.constBegin();
- for (int i=0; i::const_iterator it = m_clients.constBegin();
- it != m_clients.constEnd();
- ++it, ++row) {
- if (it.key() == id) {
- return row;
- }
- }
- return -1;
-}
-
-Client *ClientLevel::clientForId(quint32 child) const
-{
- QMap::const_iterator it = m_clients.constFind(child);
- if (it == m_clients.constEnd()) {
- return NULL;
- }
- return it.value();
-}
-
-bool ClientLevel::containsClient(Client *client) const
-{
- for (QMap::const_iterator it = m_clients.constBegin();
- it != m_clients.constEnd();
- ++it) {
- if (it.value() == client) {
- return true;
- }
- }
- return false;
-}
-
-const AbstractLevel *ClientLevel::levelForId(quint32 id) const
-{
- if (id == AbstractLevel::id()) {
- return this;
- }
- return NULL;
-}
-
-AbstractLevel *ClientLevel::parentForId(quint32 child) const
-{
- if (child == id()) {
- return parentLevel();
- }
- if (m_clients.contains(child)) {
- return const_cast(this);
- }
- return NULL;
-}
-
-AbstractLevel *AbstractLevel::create(const QList< ClientModel::LevelRestriction > &restrictions, ClientModel::LevelRestrictions parentRestrictions, ClientModel *model, AbstractLevel *parent)
-{
- if (restrictions.isEmpty() || restrictions.first() == ClientModel::NoRestriction) {
- ClientLevel *leaf = new ClientLevel(model, parent);
- leaf->setRestrictions(parentRestrictions);
- if (!parent) {
- leaf->setParent(model);
- }
- return leaf;
- }
- // create a level
- QList childRestrictions(restrictions);
- ClientModel::LevelRestriction restriction = childRestrictions.takeFirst();
- ClientModel::LevelRestrictions childrenRestrictions = restriction | parentRestrictions;
- ForkLevel *currentLevel = new ForkLevel(childRestrictions, model, parent);
- currentLevel->setRestrictions(childrenRestrictions);
- currentLevel->setRestriction(restriction);
- if (!parent) {
- currentLevel->setParent(model);
- }
- switch (restriction) {
- case ClientModel::ActivityRestriction: {
- return NULL;
- }
- case ClientModel::ScreenRestriction:
- for (int i=0; icount(); ++i) {
- AbstractLevel *childLevel = create(childRestrictions, childrenRestrictions, model, currentLevel);
- if (!childLevel) {
- continue;
- }
- childLevel->setScreen(i);
- currentLevel->addChild(childLevel);
- }
- break;
- case ClientModel::VirtualDesktopRestriction:
- for (uint i=1; i<=VirtualDesktopManager::self()->count(); ++i) {
- AbstractLevel *childLevel = create(childRestrictions, childrenRestrictions, model, currentLevel);
- if (!childLevel) {
- continue;
- }
- childLevel->setVirtualDesktop(i);
- currentLevel->addChild(childLevel);
- }
- break;
- default:
- // invalid
- return NULL;
- }
-
- return currentLevel;
-}
-
-AbstractLevel::AbstractLevel(ClientModel *model, AbstractLevel *parent)
- : QObject(parent)
- , m_model(model)
- , m_parent(parent)
- , m_screen(0)
- , m_virtualDesktop(0)
- , m_activity()
- , m_restriction(ClientModel::ClientModel::NoRestriction)
- , m_restrictions(ClientModel::NoRestriction)
- , m_id(nextId())
-{
-}
-
-AbstractLevel::~AbstractLevel()
-{
-}
-
-void AbstractLevel::setRestriction(ClientModel::LevelRestriction restriction)
-{
- m_restriction = restriction;
-}
-
-void AbstractLevel::setActivity(const QString &activity)
-{
- m_activity = activity;
-}
-
-void AbstractLevel::setScreen(uint screen)
-{
- m_screen = screen;
-}
-
-void AbstractLevel::setVirtualDesktop(uint virtualDesktop)
-{
- m_virtualDesktop = virtualDesktop;
-}
-
-void AbstractLevel::setRestrictions(ClientModel::LevelRestrictions restrictions)
-{
- m_restrictions = restrictions;
-}
-
-ForkLevel::ForkLevel(const QList &childRestrictions, ClientModel *model, AbstractLevel *parent)
- : AbstractLevel(model, parent)
- , m_childRestrictions(childRestrictions)
-{
- connect(VirtualDesktopManager::self(), SIGNAL(countChanged(uint,uint)), SLOT(desktopCountChanged(uint,uint)));
- connect(screens(), SIGNAL(countChanged(int,int)), SLOT(screenCountChanged(int,int)));
-}
-
-ForkLevel::~ForkLevel()
-{
-}
-
-void ForkLevel::desktopCountChanged(uint previousCount, uint newCount)
-{
- if (restriction() != ClientModel::ClientModel::VirtualDesktopRestriction) {
- return;
- }
- if (previousCount != uint(count())) {
- return;
- }
- if (previousCount > newCount) {
- // desktops got removed
- emit beginRemove(newCount, previousCount-1, id());
- while (uint(m_children.count()) > newCount) {
- delete m_children.takeLast();
- }
- emit endRemove();
- } else {
- // desktops got added
- emit beginInsert(previousCount, newCount-1, id());
- for (uint i=previousCount+1; i<=newCount; ++i) {
- AbstractLevel *childLevel = AbstractLevel::create(m_childRestrictions, restrictions(), model(), this);
- if (!childLevel) {
- continue;
- }
- childLevel->setVirtualDesktop(i);
- childLevel->init();
- addChild(childLevel);
- }
- emit endInsert();
- }
-}
-
-void ForkLevel::screenCountChanged(int previousCount, int newCount)
-{
- if (restriction() != ClientModel::ClientModel::ClientModel::ScreenRestriction) {
- return;
- }
- if (newCount == previousCount || previousCount != count()) {
- return;
- }
-
- if (previousCount > newCount) {
- // screens got removed
- emit beginRemove(newCount, previousCount-1, id());
- while (m_children.count() > newCount) {
- delete m_children.takeLast();
- }
- emit endRemove();
- } else {
- // screens got added
- emit beginInsert(previousCount, newCount-1, id());
- for (int i=previousCount; isetScreen(i);
- childLevel->init();
- addChild(childLevel);
- }
- emit endInsert();
- }
-}
-
-void ForkLevel::activityAdded(const QString &activityId)
-{
-}
-
-void ForkLevel::activityRemoved(const QString &activityId)
-{
-}
-
-int ForkLevel::count() const
-{
- return m_children.count();
-}
-
-void ForkLevel::addChild(AbstractLevel *child)
-{
- m_children.append(child);
- connect(child, SIGNAL(beginInsert(int,int,quint32)), SIGNAL(beginInsert(int,int,quint32)));
- connect(child, SIGNAL(beginRemove(int,int,quint32)), SIGNAL(beginRemove(int,int,quint32)));
- connect(child, SIGNAL(endInsert()), SIGNAL(endInsert()));
- connect(child, SIGNAL(endRemove()), SIGNAL(endRemove()));
-}
-
-void ForkLevel::setActivity(const QString &activity)
-{
- AbstractLevel::setActivity(activity);
- for (QList::iterator it = m_children.begin(); it != m_children.end(); ++it) {
- (*it)->setActivity(activity);
- }
-}
-
-void ForkLevel::setScreen(uint screen)
-{
- AbstractLevel::setScreen(screen);
- for (QList::iterator it = m_children.begin(); it != m_children.end(); ++it) {
- (*it)->setScreen(screen);
- }
-}
-
-void ForkLevel::setVirtualDesktop(uint virtualDesktop)
-{
- AbstractLevel::setVirtualDesktop(virtualDesktop);
- for (QList::iterator it = m_children.begin(); it != m_children.end(); ++it) {
- (*it)->setVirtualDesktop(virtualDesktop);
- }
-}
-
-void ForkLevel::init()
-{
- for (QList::iterator it = m_children.begin(); it != m_children.end(); ++it) {
- (*it)->init();
- }
-}
-
-quint32 ForkLevel::idForRow(int row) const
-{
- if (row >= m_children.length()) {
- return 0;
- }
- return m_children.at(row)->id();
-}
-
-const AbstractLevel *ForkLevel::levelForId(quint32 id) const
-{
- if (id == AbstractLevel::id()) {
- return this;
- }
- for (QList::const_iterator it = m_children.constBegin(); it != m_children.constEnd(); ++it) {
- if (const AbstractLevel *child = (*it)->levelForId(id)) {
- return child;
- }
- }
- // not found
- return NULL;
-}
-
-AbstractLevel *ForkLevel::parentForId(quint32 child) const
-{
- if (child == id()) {
- return parentLevel();
- }
- for (QList::const_iterator it = m_children.constBegin(); it != m_children.constEnd(); ++it) {
- if (AbstractLevel *parent = (*it)->parentForId(child)) {
- return parent;
- }
- }
- // not found
- return NULL;
-}
-
-int ForkLevel::rowForId(quint32 child) const
-{
- if (id() == child) {
- return 0;
- }
- for (int i=0; iid() == child) {
- return i;
- }
- }
- // do recursion
- for (QList::const_iterator it = m_children.constBegin(); it != m_children.constEnd(); ++it) {
- int row = (*it)->rowForId(child);
- if (row != -1) {
- return row;
- }
- }
- // not found
- return -1;
-}
-
-Client *ForkLevel::clientForId(quint32 child) const
-{
- for (QList::const_iterator it = m_children.constBegin(); it != m_children.constEnd(); ++it) {
- if (Client *client = (*it)->clientForId(child)) {
- return client;
- }
- }
- // not found
- return NULL;
-}
-
-ClientModel::ClientModel(QObject *parent)
- : QAbstractItemModel(parent)
- , m_root(NULL)
- , m_exclusions(NoExclusion)
-{
- QHash roleNames;
- roleNames.insert(Qt::DisplayRole, "display");
- roleNames.insert(ClientRole, "client");
- roleNames.insert(ScreenRole, "screen");
- roleNames.insert(DesktopRole, "desktop");
- roleNames.insert(ActivityRole, "activity");
- setRoleNames(roleNames);
-}
-
-ClientModel::~ClientModel()
-{
-}
-
-void ClientModel::setLevels(QList< ClientModel::LevelRestriction > restrictions)
-{
- beginResetModel();
- if (m_root) {
- delete m_root;
- }
- m_root = AbstractLevel::create(restrictions, NoRestriction, this);
- connect(m_root, SIGNAL(beginInsert(int,int,quint32)), SLOT(levelBeginInsert(int,int,quint32)));
- connect(m_root, SIGNAL(beginRemove(int,int,quint32)), SLOT(levelBeginRemove(int,int,quint32)));
- connect(m_root, SIGNAL(endInsert()), SLOT(levelEndInsert()));
- connect(m_root, SIGNAL(endRemove()), SLOT(levelEndRemove()));
- m_root->init();
- endResetModel();
-}
-
-void ClientModel::setExclusions(ClientModel::Exclusions exclusions)
-{
- if (exclusions == m_exclusions) {
- return;
- }
- m_exclusions = exclusions;
- emit exclusionsChanged();
-}
-
-QVariant ClientModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid() || index.column() != 0) {
- return QVariant();
- }
- if (const AbstractLevel *level = getLevel(index)) {
- LevelRestriction restriction = level->restriction();
- if (restriction == ActivityRestriction && (role == Qt::DisplayRole || role == ActivityRole)) {
- return level->activity();
- } else if (restriction == VirtualDesktopRestriction && (role == Qt::DisplayRole || role == DesktopRole)) {
- return level->virtualDesktop();
- } else if (restriction ==ScreenRestriction && (role == Qt::DisplayRole || role == ScreenRole)) {
- return level->screen();
- } else {
- return QVariant();
- }
- }
- if (role == Qt::DisplayRole || role == ClientRole) {
- if (Client *client = m_root->clientForId(index.internalId())) {
- return qVariantFromValue(client);
- }
- }
- return QVariant();
-}
-
-int ClientModel::columnCount(const QModelIndex &parent) const
-{
- Q_UNUSED(parent)
- return 1;
-}
-
-int ClientModel::rowCount(const QModelIndex &parent) const
-{
- if (!m_root) {
- return 0;
- }
- if (!parent.isValid()) {
- return m_root->count();
- }
- if (const AbstractLevel *level = getLevel(parent)) {
- if (level->id() != parent.internalId()) {
- // not a real level - no children
- return 0;
- }
- return level->count();
- }
- return 0;
-}
-
-QModelIndex ClientModel::parent(const QModelIndex &child) const
-{
- if (!child.isValid() || child.column() != 0) {
- return QModelIndex();
- }
- return parentForId(child.internalId());
-}
-
-QModelIndex ClientModel::parentForId(quint32 childId) const
-{
- if (childId == m_root->id()) {
- // asking for parent of our toplevel
- return QModelIndex();
- }
- if (AbstractLevel *parentLevel = m_root->parentForId(childId)) {
- if (parentLevel == m_root) {
- return QModelIndex();
- }
- const int row = m_root->rowForId(parentLevel->id());
- if (row == -1) {
- // error
- return QModelIndex();
- }
- return createIndex(row, 0, parentLevel->id());
- }
- return QModelIndex();
-}
-
-QModelIndex ClientModel::index(int row, int column, const QModelIndex &parent) const
-{
- if (column != 0 || row < 0 || !m_root) {
- return QModelIndex();
- }
- if (!parent.isValid()) {
- if (row >= rowCount()) {
- return QModelIndex();
- }
- return createIndex(row, 0, m_root->idForRow(row));
- }
- const AbstractLevel *parentLevel = getLevel(parent);
- if (!parentLevel) {
- return QModelIndex();
- }
- if (row >= parentLevel->count()) {
- return QModelIndex();
- }
- const quint32 id = parentLevel->idForRow(row);
- if (id == 0) {
- return QModelIndex();
- }
- return createIndex(row, column, id);
-}
-
-const AbstractLevel *ClientModel::getLevel(const QModelIndex &index) const
-{
- if (!index.isValid()) {
- return m_root;
- }
- return m_root->levelForId(index.internalId());
-}
-
-void ClientModel::levelBeginInsert(int rowStart, int rowEnd, quint32 id)
-{
- const int row = m_root->rowForId(id);
- QModelIndex parent;
- if (row != -1) {
- parent = createIndex(row, 0, id);
- }
- beginInsertRows(parent, rowStart, rowEnd);
-}
-
-void ClientModel::levelBeginRemove(int rowStart, int rowEnd, quint32 id)
-{
- const int row = m_root->rowForId(id);
- QModelIndex parent;
- if (row != -1) {
- parent = createIndex(row, 0, id);
- }
- beginRemoveRows(parent, rowStart, rowEnd);
-}
-
-void ClientModel::levelEndInsert()
-{
- endInsertRows();
-}
-
-void ClientModel::levelEndRemove()
-{
- endRemoveRows();
-}
-
-#define CLIENT_MODEL_WRAPPER(name, levels) \
-name::name(QObject *parent) \
- : ClientModel(parent) \
-{ \
- setLevels(levels); \
-} \
-name::~name() {}
-
-CLIENT_MODEL_WRAPPER(SimpleClientModel, QList())
-CLIENT_MODEL_WRAPPER(ClientModelByScreen, QList() << ScreenRestriction)
-CLIENT_MODEL_WRAPPER(ClientModelByScreenAndDesktop, QList() << ScreenRestriction << VirtualDesktopRestriction)
-#undef CLIENT_MODEL_WRAPPER
-
-ClientFilterModel::ClientFilterModel(QObject *parent)
- : QSortFilterProxyModel(parent)
- , m_clientModel(NULL)
-{
-}
-
-ClientFilterModel::~ClientFilterModel()
-{
-}
-
-void ClientFilterModel::setClientModel(ClientModel *clientModel)
-{
- if (clientModel == m_clientModel) {
- return;
- }
- m_clientModel = clientModel;
- setSourceModel(m_clientModel);
- emit clientModelChanged();
-}
-
-void ClientFilterModel::setFilter(const QString &filter)
-{
- if (filter == m_filter) {
- return;
- }
- m_filter = filter;
- emit filterChanged();
- invalidateFilter();
-}
-
-bool ClientFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
-{
- if (!m_clientModel) {
- return false;
- }
- if (m_filter.isEmpty()) {
- return true;
- }
- QModelIndex index = m_clientModel->index(sourceRow, 0, sourceParent);
- if (!index.isValid()) {
- return false;
- }
- QVariant data = index.data();
- if (!data.isValid()) {
- // an invalid QVariant is valid data
- return true;
- }
- // TODO: introduce a type as a data role and properly check, this seems dangerous
- if (data.type() == QVariant::Int || data.type() == QVariant::UInt || data.type() == QVariant::String) {
- // we do not filter out screen, desktop and activity
- return true;
- }
- Client *client = qvariant_cast(data);
- if (!client) {
- return false;
- }
- if (client->caption().contains(m_filter, Qt::CaseInsensitive)) {
- return true;
- }
- const QString windowRole(client->windowRole());
- if (windowRole.contains(m_filter, Qt::CaseInsensitive)) {
- return true;
- }
- const QString resourceName(client->resourceName());
- if (resourceName.contains(m_filter, Qt::CaseInsensitive)) {
- return true;
- }
- const QString resourceClass(client->resourceClass());
- if (resourceClass.contains(m_filter, Qt::CaseInsensitive)) {
- return true;
- }
- return false;
-}
-
-} // namespace Scripting
-} // namespace KWin
diff --git a/kwin/scripting/scripting_model.h b/kwin/scripting/scripting_model.h
deleted file mode 100644
index 23cf75ed..00000000
--- a/kwin/scripting/scripting_model.h
+++ /dev/null
@@ -1,380 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2013 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-#ifndef KWIN_SCRIPTING_MODEL_H
-#define KWIN_SCRIPTING_MODEL_H
-
-#include
-#include
-#include
-
-namespace KWin {
-class Client;
-
-namespace ScriptingClientModel {
-
-class AbstractLevel;
-
-class ClientModel : public QAbstractItemModel
-{
- Q_OBJECT
- Q_ENUMS(Exclude)
- Q_ENUMS(LevelRestriction)
- Q_PROPERTY(Exclusions exclusions READ exclusions WRITE setExclusions NOTIFY exclusionsChanged)
-public:
- enum Exclusion {
- NoExclusion = 0,
- // window types
- DesktopWindowsExclusion = 1 << 0,
- DockWindowsExclusion = 1 << 1,
- UtilityWindowsExclusion = 1 << 2,
- SpecialWindowsExclusion = 1 << 3,
- // windows with flags
- SkipTaskbarExclusion = 1 << 4,
- SkipPagerExclusion = 1 << 5,
- SwitchSwitcherExclusion = 1 << 6,
- // based on state
- OtherDesktopsExclusion = 1 << 7,
- OtherActivitiesExclusion = 1 << 8,
- MinimizedExclusion = 1 << 9,
- NonSelectedWindowTabExclusion = 1 << 10,
- NotAcceptingFocusExclusion = 1 << 11
- };
- Q_DECLARE_FLAGS(Exclusions, Exclusion)
- Q_FLAGS(Exclusions)
- enum LevelRestriction {
- NoRestriction = 0,
- VirtualDesktopRestriction = 1 << 0,
- ScreenRestriction = 1 << 1,
- ActivityRestriction = 1 << 2
- };
- Q_DECLARE_FLAGS(LevelRestrictions, LevelRestriction)
- Q_FLAGS(LevelRestrictions)
- explicit ClientModel(QObject *parent);
- virtual ~ClientModel();
- virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
- virtual QModelIndex parent(const QModelIndex &child) const;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
-
- void setExclusions(ClientModel::Exclusions exclusions);
- Exclusions exclusions() const;
-
-Q_SIGNALS:
- void exclusionsChanged();
-
-private Q_SLOTS:
- void levelBeginInsert(int rowStart, int rowEnd, quint32 parentId);
- void levelEndInsert();
- void levelBeginRemove(int rowStart, int rowEnd, quint32 parentId);
- void levelEndRemove();
-
-protected:
- enum ClientModelRoles {
- ClientRole = Qt::UserRole,
- ScreenRole,
- DesktopRole,
- ActivityRole
- };
- void setLevels(QList restrictions);
-
-private:
- QModelIndex parentForId(quint32 childId) const;
- const AbstractLevel *getLevel(const QModelIndex &index) const;
- AbstractLevel *m_root;
- Exclusions m_exclusions;
-};
-
-/**
- * @brief The data structure of the Model.
- *
- * The model is implemented as a Tree consisting of AbstractLevels as the levels of the tree.
- * A non leaf level is represented by the inheriting class @link ForkLevel, the last level above a
- * leaf is represented by the inheriting class @link ClientLevel, which contains the Clients - each
- * Client is one leaf.
- *
- * In case the tree would only consist of Clients - leafs - it has always one ClientLevel as the root
- * of the tree.
- *
- * The number of levels in the tree is controlled by the LevelRestrictions. For each existing
- * LevelRestriction a new Level is created, if there are no more restrictions a ClientLevel is created.
- *
- * To build up the tree the static factory method @link create has to be used. It will recursively
- * build up the tree. After the tree has been build up use @link init to initialize the tree which
- * will add the Clients to the ClientLevel.
- *
- * Each element of the tree has a unique id which can be used by the QAbstractItemModel as the
- * internal id for its QModelIndex. Note: the ids have no ordering, if trying to get a specific element
- * the tree performs a depth-first search.
- *
- */
-class AbstractLevel : public QObject
-{
- Q_OBJECT
-public:
- virtual ~AbstractLevel();
- virtual int count() const = 0;
- virtual void init() = 0;
- virtual quint32 idForRow(int row) const = 0;
-
- uint screen() const;
- uint virtualDesktop() const;
- const QString &activity() const;
- ClientModel::LevelRestrictions restrictions() const;
- void setRestrictions(ClientModel::LevelRestrictions restrictions);
- ClientModel::LevelRestriction restriction() const;
- void setRestriction(ClientModel::LevelRestriction restriction);
- quint32 id() const;
- AbstractLevel *parentLevel() const;
- virtual const AbstractLevel *levelForId(quint32 id) const = 0;
- virtual AbstractLevel *parentForId(quint32 child) const = 0;
- virtual int rowForId(quint32 child) const = 0;
- virtual Client *clientForId(quint32 child) const = 0;
-
- virtual void setScreen(uint screen);
- virtual void setVirtualDesktop(uint virtualDesktop);
- virtual void setActivity(const QString &activity);
-
- static AbstractLevel *create(const QList &restrictions, ClientModel::LevelRestrictions parentRestrictions, ClientModel *model, AbstractLevel *parent = NULL);
-
-Q_SIGNALS:
- void beginInsert(int rowStart, int rowEnd, quint32 parentId);
- void endInsert();
- void beginRemove(int rowStart, int rowEnd, quint32 parentId);
- void endRemove();
-protected:
- AbstractLevel(ClientModel *model, AbstractLevel *parent);
- ClientModel *model() const;
-private:
- ClientModel *m_model;
- AbstractLevel *m_parent;
- uint m_screen;
- uint m_virtualDesktop;
- QString m_activity;
- ClientModel::LevelRestriction m_restriction;
- ClientModel::LevelRestrictions m_restrictions;
- quint32 m_id;
-};
-
-class ForkLevel : public AbstractLevel
-{
- Q_OBJECT
-public:
- ForkLevel(const QList &childRestrictions, ClientModel *model, AbstractLevel *parent);
- virtual ~ForkLevel();
- virtual int count() const;
- virtual void init();
- virtual quint32 idForRow(int row) const;
- void addChild(AbstractLevel *child);
- virtual void setScreen(uint screen);
- virtual void setVirtualDesktop(uint virtualDesktop);
- virtual void setActivity(const QString &activity);
- virtual const AbstractLevel *levelForId(quint32 id) const;
- virtual AbstractLevel *parentForId(quint32 child) const;
- virtual int rowForId(quint32 child) const;
- virtual Client *clientForId(quint32 child) const;
-private Q_SLOTS:
- void desktopCountChanged(uint previousCount, uint newCount);
- void screenCountChanged(int previousCount, int newCount);
- void activityAdded(const QString &id);
- void activityRemoved(const QString &id);
-private:
- QList m_children;
- QList m_childRestrictions;
-};
-
-/**
- * @brief The actual leafs of the model's tree containing the Client's in this branch of the tree.
- *
- * This class groups all the Clients of one branch of the tree and takes care of updating the tree
- * when a Client changes its state in a way that it should be excluded/included or gets added or
- * removed.
- *
- * The Clients in this group are not sorted in any particular way. It's a simple list which only
- * gets added to. If some sorting should be applied, use a QSortFilterProxyModel.
- */
-class ClientLevel : public AbstractLevel
-{
- Q_OBJECT
-public:
- explicit ClientLevel(ClientModel *model, AbstractLevel *parent);
- virtual ~ClientLevel();
-
- void init();
-
- int count() const;
- quint32 idForRow(int row) const;
- bool containsId(quint32 id) const;
- int rowForId(quint32 row) const;
- Client *clientForId(quint32 child) const;
- virtual const AbstractLevel *levelForId(quint32 id) const;
- virtual AbstractLevel *parentForId(quint32 child) const;
-public Q_SLOTS:
- void clientAdded(KWin::Client *client);
- void clientRemoved(KWin::Client *client);
-private Q_SLOTS:
- // uses sender()
- void checkClient();
- void reInit();
-private:
- void checkClient(KWin::Client *client);
- void setupClientConnections(Client *client);
- void addClient(Client *client);
- void removeClient(Client *client);
- bool shouldAdd(Client *client) const;
- bool exclude(Client *client) const;
- bool containsClient(Client *client) const;
- QMap m_clients;
-};
-
-class SimpleClientModel : public ClientModel
-{
- Q_OBJECT
-public:
- SimpleClientModel(QObject *parent = NULL);
- virtual ~SimpleClientModel();
-};
-
-class ClientModelByScreen : public ClientModel
-{
- Q_OBJECT
-public:
- ClientModelByScreen(QObject *parent = NULL);
- virtual ~ClientModelByScreen();
-};
-
-class ClientModelByScreenAndDesktop : public ClientModel
-{
- Q_OBJECT
-public:
- ClientModelByScreenAndDesktop(QObject *parent = NULL);
- virtual ~ClientModelByScreenAndDesktop();
-};
-
-/**
- * @brief Custom QSortFilterProxyModel to filter on Client caption, role and class.
- *
- */
-class ClientFilterModel : public QSortFilterProxyModel
-{
- Q_OBJECT
- Q_PROPERTY(KWin::ScriptingClientModel::ClientModel *clientModel READ clientModel WRITE setClientModel NOTIFY clientModelChanged)
- Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
-public:
- ClientFilterModel(QObject *parent = 0);
- virtual ~ClientFilterModel();
- ClientModel *clientModel() const;
- const QString &filter() const;
-
-public Q_SLOTS:
- void setClientModel(ClientModel *clientModel);
- void setFilter(const QString &filter);
-
-protected:
- virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
-
-Q_SIGNALS:
- void clientModelChanged();
- void filterChanged();
-
-private:
- ClientModel *m_clientModel;
- QString m_filter;
-};
-
-inline
-int ClientLevel::count() const
-{
- return m_clients.count();
-}
-
-inline
-const QString &AbstractLevel::activity() const
-{
- return m_activity;
-}
-
-inline
-AbstractLevel *AbstractLevel::parentLevel() const
-{
- return m_parent;
-}
-
-inline
-ClientModel *AbstractLevel::model() const
-{
- return m_model;
-}
-
-inline
-uint AbstractLevel::screen() const
-{
- return m_screen;
-}
-
-inline
-uint AbstractLevel::virtualDesktop() const
-{
- return m_virtualDesktop;
-}
-
-inline
-ClientModel::LevelRestriction AbstractLevel::restriction() const
-{
- return m_restriction;
-}
-
-inline
-ClientModel::LevelRestrictions AbstractLevel::restrictions() const
-{
- return m_restrictions;
-}
-
-inline
-quint32 AbstractLevel::id() const
-{
- return m_id;
-}
-
-inline
-ClientModel::Exclusions ClientModel::exclusions() const
-{
- return m_exclusions;
-}
-
-inline
-ClientModel *ClientFilterModel::clientModel() const
-{
- return m_clientModel;
-}
-
-inline
-const QString &ClientFilterModel::filter() const
-{
- return m_filter;
-}
-
-} // namespace Scripting
-} // namespace KWin
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::ScriptingClientModel::ClientModel::Exclusions)
-Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::ScriptingClientModel::ClientModel::LevelRestrictions)
-
-#endif // KWIN_SCRIPTING_MODEL_H
diff --git a/kwin/scripting/scriptingutils.cpp b/kwin/scripting/scriptingutils.cpp
deleted file mode 100644
index b89818bc..00000000
--- a/kwin/scripting/scriptingutils.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
- Copyright (C) 2012 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-#include "scriptingutils.h"
-
-namespace KWin
-{
-bool validateParameters(QScriptContext *context, int min, int max)
-{
- if (context->argumentCount() < min || context->argumentCount() > max) {
- context->throwError(QScriptContext::SyntaxError,
- i18nc("syntax error in KWin script", "Invalid number of arguments"));
- return false;
- }
- return true;
-}
-
-template<>
-bool validateArgumentType(QScriptContext *context, int argument)
-{
- const bool result =context->argument(argument).toVariant().isValid();
- if (!result) {
- context->throwError(QScriptContext::TypeError,
- i18nc("KWin Scripting function received incorrect value for an expected type",
- "%1 is not a variant type", context->argument(argument).toString()));
- }
- return result;
-}
-
-}
diff --git a/kwin/scripting/scriptingutils.h b/kwin/scripting/scriptingutils.h
deleted file mode 100644
index 6f4a5684..00000000
--- a/kwin/scripting/scriptingutils.h
+++ /dev/null
@@ -1,284 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
- Copyright (C) 2012 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#ifndef KWIN_SCRIPTINGUTILS_H
-#define KWIN_SCRIPTINGUTILS_H
-
-#include "workspace.h"
-#ifdef KWIN_BUILD_SCREENEDGES
-#include "screenedge.h"
-#endif
-
-#include
-#include
-#include
-#include
-#include
-
-namespace KWin
-{
-
-/**
- * Validates that argument at @p index of given @p context is of required type.
- * Throws a type error in the scripting context if there is a type mismatch.
- * @param context The scripting context in which the argument type needs to be validated.
- * @param index The argument index to validate
- * @returns @c true if the argument is of required type, @c false otherwise
- **/
-template
-bool validateArgumentType(QScriptContext *context, int index)
-{
- const bool result = context->argument(index).toVariant().canConvert();
- if (!result) {
- context->throwError(QScriptContext::TypeError,
- i18nc("KWin Scripting function received incorrect value for an expected type",
- "%1 is not of required type", context->argument(index).toString()));
- }
- return result;
-}
-
-/**
- * Validates that the argument of @p context is of specified type.
- * Throws a type error in the scripting context if there is a type mismatch.
- * @param context The scripting context in which the argument type needs to be validated.
- * @returns @c true if the argument is of required type, @c false otherwise
- **/
-template
-bool validateArgumentType(QScriptContext *context)
-{
- return validateArgumentType(context, 0);
-}
-
-template
-bool validateArgumentType(QScriptContext *context)
-{
- if (!validateArgumentType(context)) {
- return false;
- }
- return validateArgumentType(context, 1);
-}
-
-template
-bool validateArgumentType(QScriptContext *context)
-{
- if (!validateArgumentType(context)) {
- return false;
- }
- return validateArgumentType(context, 2);
-}
-
-template
-bool validateArgumentType(QScriptContext *context)
-{
- if (!validateArgumentType(context)) {
- return false;
- }
- return validateArgumentType(context, 3);
-}
-
-/**
- * Validates that the argument count of @p context is at least @p min and @p max.
- * Throws a syntax error in the script context if argument count mismatch.
- * @param context The ScriptContext for which the argument count needs to be validated
- * @param min The minimum number of arguments.
- * @param max The maximum number of arguments
- * @returns @c true if the argument count is correct, otherwise @c false
- **/
-bool validateParameters(QScriptContext *context, int min, int max);
-
-template
-QScriptValue globalShortcut(QScriptContext *context, QScriptEngine *engine)
-{
- T script = qobject_cast(context->callee().data().toQObject());
- if (!script) {
- return engine->undefinedValue();
- }
- if (context->argumentCount() != 4) {
- kDebug(1212) << "Incorrect number of arguments! Expected: title, text, keySequence, callback";
- return engine->undefinedValue();
- }
- KActionCollection* actionCollection = new KActionCollection(script);
- KAction* a = (KAction*)actionCollection->addAction(context->argument(0).toString());
- a->setText(context->argument(1).toString());
- a->setGlobalShortcut(KShortcut(context->argument(2).toString()));
- script->registerShortcut(a, context->argument(3));
- return engine->newVariant(true);
-}
-
-template
-void callGlobalShortcutCallback(T script, QObject *sender)
-{
- QAction *a = qobject_cast(sender);
- if (!a) {
- return;
- }
- QHash::const_iterator it = script->shortcutCallbacks().find(a);
- if (it == script->shortcutCallbacks().end()) {
- return;
- }
- QScriptValue value(it.value());
- QScriptValueList arguments;
- arguments << value.engine()->newQObject(a);
- value.call(QScriptValue(), arguments);
-}
-
-template
-QScriptValue registerScreenEdge(QScriptContext *context, QScriptEngine *engine)
-{
- T script = qobject_cast(context->callee().data().toQObject());
- if (!script) {
- return engine->undefinedValue();
- }
- if (!validateParameters(context, 2, 2)) {
- return engine->undefinedValue();
- }
- if (!validateArgumentType(context)) {
- return engine->undefinedValue();
- }
- if (!context->argument(1).isFunction()) {
- context->throwError(QScriptContext::SyntaxError, i18nc("KWin Scripting error thrown due to incorrect argument",
- "Second argument to registerScreenEdge needs to be a callback"));
- }
-
- const int edge = context->argument(0).toVariant().toInt();
- QHash >::iterator it = script->screenEdgeCallbacks().find(edge);
- if (it == script->screenEdgeCallbacks().end()) {
- // not yet registered
-#ifdef KWIN_BUILD_SCREENEDGES
- ScreenEdges::self()->reserve(static_cast(edge), script, "borderActivated");
-#endif
- script->screenEdgeCallbacks().insert(edge, QList() << context->argument(1));
- } else {
- it->append(context->argument(1));
- }
- return engine->newVariant(true);
-}
-
-template
-QScriptValue registerUserActionsMenu(QScriptContext *context, QScriptEngine *engine)
-{
- T script = qobject_cast(context->callee().data().toQObject());
- if (!script) {
- return engine->undefinedValue();
- }
- if (!validateParameters(context, 1, 1)) {
- return engine->undefinedValue();
- }
- if (!context->argument(0).isFunction()) {
- context->throwError(QScriptContext::SyntaxError, i18nc("KWin Scripting error thrown due to incorrect argument",
- "Argument for registerUserActionsMenu needs to be a callback"));
- return engine->undefinedValue();
- }
- script->registerUseractionsMenuCallback(context->argument(0));
- return engine->newVariant(true);
-}
-
-template
-void screenEdgeActivated(T *script, int edge)
-{
- QHash >::iterator it = script->screenEdgeCallbacks().find(edge);
- if (it != script->screenEdgeCallbacks().end()) {
- foreach (const QScriptValue &value, it.value()) {
- QScriptValue callback(value);
- callback.call();
- }
- }
-}
-
-template
-QScriptValue scriptingAssert(QScriptContext *context, QScriptEngine *engine, int min, int max, T defaultVal = T())
-{
- if (!validateParameters(context, min, max)) {
- return engine->undefinedValue();
- }
- switch (context->argumentCount()) {
- case 1:
- if (!validateArgumentType(context)) {
- return engine->undefinedValue();
- }
- break;
- case 2:
- if (max == 2) {
- if (!validateArgumentType(context)) {
- return engine->undefinedValue();
- }
- } else {
- if (!validateArgumentType(context)) {
- return engine->undefinedValue();
- }
- }
- break;
- case 3:
- if (!validateArgumentType(context)) {
- return engine->undefinedValue();
- }
- break;
- }
- if (max == 2) {
- if (context->argument(0).toVariant().value() != defaultVal) {
- if (context->argumentCount() == max) {
- context->throwError(QScriptContext::UnknownError, context->argument(max - 1).toString());
- } else {
- context->throwError(QScriptContext::UnknownError,
- i18nc("Assertion failed in KWin script with given value",
- "Assertion failed: %1", context->argument(0).toString()));
- }
- return engine->undefinedValue();
- }
- } else {
- if (context->argument(0).toVariant().value() != context->argument(1).toVariant().value()) {
- if (context->argumentCount() == max) {
- context->throwError(QScriptContext::UnknownError, context->argument(max - 1).toString());
- } else {
- context->throwError(QScriptContext::UnknownError,
- i18nc("Assertion failed in KWin script with expected value and actual value",
- "Assertion failed: Expected %1, got %2",
- context->argument(0).toString(), context->argument(1).toString()));
- }
- return engine->undefinedValue();
- }
- }
- return engine->newVariant(true);
-}
-
-inline void registerGlobalShortcutFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function)
-{
- QScriptValue shortcutFunc = engine->newFunction(function);
- shortcutFunc.setData(engine->newQObject(parent));
- engine->globalObject().setProperty("registerShortcut", shortcutFunc);
-}
-
-inline void registerScreenEdgeFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function)
-{
- QScriptValue shortcutFunc = engine->newFunction(function);
- shortcutFunc.setData(engine->newQObject(parent));
- engine->globalObject().setProperty("registerScreenEdge", shortcutFunc);
-}
-
-inline void regesterUserActionsMenuFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function)
-{
- QScriptValue shortcutFunc = engine->newFunction(function);
- shortcutFunc.setData(engine->newQObject(parent));
- engine->globalObject().setProperty("registerUserActionsMenu", shortcutFunc);
-}
-
-} // namespace KWin
-
-#endif // KWIN_SCRIPTINGUTILS_H
diff --git a/kwin/scripting/timer.cpp b/kwin/scripting/timer.cpp
deleted file mode 100644
index c990e901..00000000
--- a/kwin/scripting/timer.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2007 Richard J. Moore
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License version 2 as
- * published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-Q_DECLARE_METATYPE(QTimer*)
-
-static QScriptValue newTimer(QScriptEngine *eng, QTimer *timer)
-{
- return eng->newQObject(timer, QScriptEngine::AutoOwnership);
-}
-
-static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
-{
- return newTimer(eng, new QTimer(qscriptvalue_cast(ctx->argument(0))));
-}
-
-QScriptValue constructTimerClass(QScriptEngine *eng)
-{
- QScriptValue proto = newTimer(eng, new QTimer());
- eng->setDefaultPrototype(qMetaTypeId(), proto);
-
- return eng->newFunction(ctor, proto);
-}
diff --git a/kwin/scripting/workspace_wrapper.cpp b/kwin/scripting/workspace_wrapper.cpp
deleted file mode 100644
index 456773cc..00000000
--- a/kwin/scripting/workspace_wrapper.cpp
+++ /dev/null
@@ -1,280 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2010 Rohan Prabhu
-Copyright (C) 2011, 2012 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*********************************************************************/
-
-#include "workspace_wrapper.h"
-#include "../client.h"
-#include "../outline.h"
-#include "../screens.h"
-#include "../virtualdesktops.h"
-#include "../workspace.h"
-
-#include
-
-namespace KWin {
-
-WorkspaceWrapper::WorkspaceWrapper(QObject* parent) : QObject(parent)
-{
- KWin::Workspace *ws = KWin::Workspace::self();
- KWin::VirtualDesktopManager *vds = KWin::VirtualDesktopManager::self();
- connect(ws, SIGNAL(desktopPresenceChanged(KWin::Client*,int)), SIGNAL(desktopPresenceChanged(KWin::Client*,int)));
- connect(ws, SIGNAL(currentDesktopChanged(int,KWin::Client*)), SIGNAL(currentDesktopChanged(int,KWin::Client*)));
- connect(ws, SIGNAL(clientAdded(KWin::Client*)), SIGNAL(clientAdded(KWin::Client*)));
- connect(ws, SIGNAL(clientAdded(KWin::Client*)), SLOT(setupClientConnections(KWin::Client*)));
- connect(ws, SIGNAL(clientRemoved(KWin::Client*)), SIGNAL(clientRemoved(KWin::Client*)));
- connect(ws, SIGNAL(clientActivated(KWin::Client*)), SIGNAL(clientActivated(KWin::Client*)));
- connect(vds, SIGNAL(countChanged(uint,uint)), SIGNAL(numberDesktopsChanged(uint)));
- connect(vds, SIGNAL(layoutChanged(int,int)), SIGNAL(desktopLayoutChanged()));
- connect(ws, SIGNAL(clientDemandsAttentionChanged(KWin::Client*,bool)), SIGNAL(clientDemandsAttentionChanged(KWin::Client*,bool)));
- connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), SIGNAL(numberScreensChanged(int)));
- connect(QApplication::desktop(), SIGNAL(resized(int)), SIGNAL(screenResized(int)));
- foreach (KWin::Client *client, ws->clientList()) {
- setupClientConnections(client);
- }
-}
-
-int WorkspaceWrapper::currentDesktop() const
-{
- return VirtualDesktopManager::self()->current();
-}
-
-int WorkspaceWrapper::numberOfDesktops() const
-{
- return VirtualDesktopManager::self()->count();
-}
-
-void WorkspaceWrapper::setCurrentDesktop(int desktop)
-{
- VirtualDesktopManager::self()->setCurrent(desktop);
-}
-
-void WorkspaceWrapper::setNumberOfDesktops(int count)
-{
- VirtualDesktopManager::self()->setCount(count);
-}
-
-#define GETTER( rettype, getterName ) \
-rettype WorkspaceWrapper::getterName( ) const { \
- return Workspace::self()->getterName(); \
-}
-GETTER(KWin::Client*, activeClient)
-GETTER(QList< KWin::Client* >, clientList)
-
-#undef GETTER
-
-QString WorkspaceWrapper::currentActivity() const
-{
- return QString();
-}
-
-QStringList WorkspaceWrapper::activityList() const
-{
- return QStringList();
-}
-
-#define SLOTWRAPPER(name) \
-void WorkspaceWrapper::name( ) { \
- Workspace::self()->name(); \
-}
-
-SLOTWRAPPER(slotSwitchToNextScreen)
-SLOTWRAPPER(slotWindowToNextScreen)
-SLOTWRAPPER(slotToggleShowDesktop)
-
-SLOTWRAPPER(slotWindowMaximize)
-SLOTWRAPPER(slotWindowMaximizeVertical)
-SLOTWRAPPER(slotWindowMaximizeHorizontal)
-SLOTWRAPPER(slotWindowMinimize)
-SLOTWRAPPER(slotWindowShade)
-SLOTWRAPPER(slotWindowRaise)
-SLOTWRAPPER(slotWindowLower)
-SLOTWRAPPER(slotWindowRaiseOrLower)
-SLOTWRAPPER(slotActivateAttentionWindow)
-SLOTWRAPPER(slotWindowPackLeft)
-SLOTWRAPPER(slotWindowPackRight)
-SLOTWRAPPER(slotWindowPackUp)
-SLOTWRAPPER(slotWindowPackDown)
-SLOTWRAPPER(slotWindowGrowHorizontal)
-SLOTWRAPPER(slotWindowGrowVertical)
-SLOTWRAPPER(slotWindowShrinkHorizontal)
-SLOTWRAPPER(slotWindowShrinkVertical)
-SLOTWRAPPER(slotWindowQuickTileLeft)
-SLOTWRAPPER(slotWindowQuickTileRight)
-SLOTWRAPPER(slotWindowQuickTileTopLeft)
-SLOTWRAPPER(slotWindowQuickTileTopRight)
-SLOTWRAPPER(slotWindowQuickTileBottomLeft)
-SLOTWRAPPER(slotWindowQuickTileBottomRight)
-
-SLOTWRAPPER(slotSwitchWindowUp)
-SLOTWRAPPER(slotSwitchWindowDown)
-SLOTWRAPPER(slotSwitchWindowRight)
-SLOTWRAPPER(slotSwitchWindowLeft)
-
-SLOTWRAPPER(slotIncreaseWindowOpacity)
-SLOTWRAPPER(slotLowerWindowOpacity)
-
-SLOTWRAPPER(slotWindowOperations)
-SLOTWRAPPER(slotWindowClose)
-SLOTWRAPPER(slotWindowMove)
-SLOTWRAPPER(slotWindowResize)
-SLOTWRAPPER(slotWindowAbove)
-SLOTWRAPPER(slotWindowBelow)
-SLOTWRAPPER(slotWindowOnAllDesktops)
-SLOTWRAPPER(slotWindowFullScreen)
-SLOTWRAPPER(slotWindowNoBorder)
-
-SLOTWRAPPER(slotWindowToNextDesktop)
-SLOTWRAPPER(slotWindowToPreviousDesktop)
-SLOTWRAPPER(slotWindowToDesktopRight)
-SLOTWRAPPER(slotWindowToDesktopLeft)
-SLOTWRAPPER(slotWindowToDesktopUp)
-SLOTWRAPPER(slotWindowToDesktopDown)
-
-#undef SLOTWRAPPER
-
-#define SLOTWRAPPER(name,direction) \
-void WorkspaceWrapper::name( ) { \
- VirtualDesktopManager::self()->moveTo(options->isRollOverDesktops()); \
-}
-
-SLOTWRAPPER(slotSwitchDesktopNext,DesktopNext)
-SLOTWRAPPER(slotSwitchDesktopPrevious,DesktopPrevious)
-SLOTWRAPPER(slotSwitchDesktopRight,DesktopRight)
-SLOTWRAPPER(slotSwitchDesktopLeft,DesktopLeft)
-SLOTWRAPPER(slotSwitchDesktopUp,DesktopAbove)
-SLOTWRAPPER(slotSwitchDesktopDown,DesktopBelow)
-
-#undef SLOTWRAPPER
-
-void WorkspaceWrapper::setActiveClient(KWin::Client* client)
-{
- KWin::Workspace::self()->activateClient(client);
-}
-
-QSize WorkspaceWrapper::workspaceSize() const
-{
- return QSize(workspaceWidth(), workspaceHeight());
-}
-
-QSize WorkspaceWrapper::displaySize() const
-{
- return QSize(KWin::displayWidth(), KWin::displayHeight());
-}
-
-int WorkspaceWrapper::displayWidth() const
-{
- return KWin::displayWidth();
-}
-
-int WorkspaceWrapper::displayHeight() const
-{
- return KWin::displayHeight();
-}
-
-QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const QPoint &p, int desktop) const
-{
- return Workspace::self()->clientArea(static_cast(option), p, desktop);
-}
-
-QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const KWin::Client *c) const
-{
- return Workspace::self()->clientArea(static_cast(option), c);
-}
-
-QRect WorkspaceWrapper::clientArea(ClientAreaOption option, int screen, int desktop) const
-{
- return Workspace::self()->clientArea(static_cast(option), screen, desktop);
-}
-
-QString WorkspaceWrapper::desktopName(int desktop) const
-{
- return VirtualDesktopManager::self()->name(desktop);
-}
-
-QString WorkspaceWrapper::supportInformation() const
-{
- return Workspace::self()->supportInformation();
-}
-
-void WorkspaceWrapper::setupClientConnections(KWin::Client *client)
-{
- connect(client, SIGNAL(clientMinimized(KWin::Client*,bool)), SIGNAL(clientMinimized(KWin::Client*)));
- connect(client, SIGNAL(clientUnminimized(KWin::Client*,bool)), SIGNAL(clientUnminimized(KWin::Client*)));
- connect(client, SIGNAL(clientManaging(KWin::Client*)), SIGNAL(clientManaging(KWin::Client*)));
- connect(client, SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)), SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)));
- connect(client, SIGNAL(clientMaximizedStateChanged(KWin::Client*,bool,bool)), SIGNAL(clientMaximizeSet(KWin::Client*,bool,bool)));
-}
-
-void WorkspaceWrapper::showOutline(const QRect &geometry)
-{
- outline()->show(geometry);
-}
-
-void WorkspaceWrapper::showOutline(int x, int y, int width, int height)
-{
- outline()->show(QRect(x, y, width, height));
-}
-
-void WorkspaceWrapper::hideOutline()
-{
- outline()->hide();
-}
-
-Client *WorkspaceWrapper::getClient(qulonglong windowId)
-{
- return Workspace::self()->findClient(WindowMatchPredicate(windowId));
-}
-
-QSize WorkspaceWrapper::desktopGridSize() const
-{
- return VirtualDesktopManager::self()->grid().size();
-}
-
-int WorkspaceWrapper::desktopGridWidth() const
-{
- return desktopGridSize().width();
-}
-
-int WorkspaceWrapper::desktopGridHeight() const
-{
- return desktopGridSize().height();
-}
-
-int WorkspaceWrapper::workspaceHeight() const
-{
- return desktopGridHeight() * displayHeight();
-}
-
-int WorkspaceWrapper::workspaceWidth() const
-{
- return desktopGridWidth() * displayWidth();
-}
-
-int WorkspaceWrapper::numScreens() const
-{
- return screens()->count();
-}
-
-int WorkspaceWrapper::activeScreen() const
-{
- return screens()->current();
-}
-
-} // KWin
diff --git a/kwin/scripting/workspace_wrapper.h b/kwin/scripting/workspace_wrapper.h
deleted file mode 100644
index b32f84c8..00000000
--- a/kwin/scripting/workspace_wrapper.h
+++ /dev/null
@@ -1,322 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2010 Rohan Prabhu
-Copyright (C) 2012 Martin Gräßlin
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see