[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kwin/scripting2] /: asfsf
From: David Edmundson <null () kde ! org>
Date: 2018-07-31 21:37:18
Message-ID: E1fkcKU-0001yG-U1 () code ! kde ! org
[Download RAW message or body]
Git commit 1741fdb02fc50c68c19643df9f053eb6b5653471 by David Edmundson.
Committed on 31/07/2018 at 20:28.
Pushed by davidedmundson into branch 'scripting2'.
asfsf
M +2 -0 autotests/CMakeLists.txt
M +184 -163 scripting/scriptedeffect.cpp
M +7 -7 scripting/scriptedeffect.h
https://commits.kde.org/kwin/1741fdb02fc50c68c19643df9f053eb6b5653471
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 35b420233..24a55c64f 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -139,6 +139,7 @@ set_target_properties(testBuiltInEffectLoader PROPERTIES \
COMPILE_DEFINITIONS "NO target_link_libraries(testBuiltInEffectLoader
Qt5::Concurrent
Qt5::Test
+ Qt5::Qml
Qt5::X11Extras
KF5::Package
kwineffects
@@ -201,6 +202,7 @@ add_executable( testPluginEffectLoader \
${testPluginEffectLoader_SRCS}) target_link_libraries(testPluginEffectLoader
Qt5::Concurrent
Qt5::Test
+ Qt5::Qml
Qt5::X11Extras
KF5::Package
kwineffects
diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp
index a642b7717..80d75ff6e 100644
--- a/scripting/scriptedeffect.cpp
+++ b/scripting/scriptedeffect.cpp
@@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
+ Copyright (C) 2018 David Edmundson <davidedmundson@kde.org>
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
@@ -34,8 +35,7 @@ along with this program. If not, see \
<http://www.gnu.org/licenses/>. #include <QQmlEngine>
#include <QJSValueIterator>
#include <QStandardPaths>
-
-#include <QGridLayout>
+//#include <QGridLayout>
typedef KWin::EffectWindow* KEffectWindowRef;
@@ -48,22 +48,24 @@ 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;
+ QJSValue from; //should be a KFx2
+ QJSValue to;
int delay;
uint duration;
uint set;
uint metaData;
};
-AnimationSettings animationSettingsFromObject(QJSValue &object)
+AnimationSettings animationSettingsFromObject(const QJSValue &object)
{
AnimationSettings settings;
settings.set = 0;
settings.metaData = 0;
- settings.to = object.property(QStringLiteral("to")).toVariant().value<FPx2>();
- settings.from = \
object.property(QStringLiteral("from")).toVariant().value<FPx2>(); + settings.to = \
object.property(QStringLiteral("to")); + // .toVariant().value<FPx2>();
+ settings.from = object.property(QStringLiteral("from"));
+ // .toVariant().value<FPx2>();
QJSValue duration = object.property(QStringLiteral("duration"));
if (duration.isNumber()) {
@@ -96,131 +98,37 @@ AnimationSettings animationSettingsFromObject(QJSValue &object)
} else {
settings.type = static_cast<AnimationEffect::Attribute>(-1);
}
-
return settings;
}
-//takes exactly one argument, an object
-//returns list of animations and the effect window
-
-QList<AnimationSettings> animationSettings(const QJSValue& object EffectWindow \
**window)
-{
- QList<AnimationSettings> settings;
- QJSValue windowProperty = object.property(QStringLiteral("window"));
- if (!windowProperty.isValid() || !windowProperty.isObject()) {
-// context->throwError(QScriptContext::TypeError, QStringLiteral("Window \
property missing in animation options"));
- return settings;
- }
- *window = qobject_cast<EffectWindow*>(windowProperty.toQObject());
-
- settings << animationSettingsFromObject(object); // global
-
- QJSValue animations = object.property(QStringLiteral("animations")); // array
- if (!animations.isNull()) {
- if (!animations.isArray()) {
- context->throwError(QScriptContext::TypeError, QStringLiteral("Animations \
provided but not an array"));
- settings.clear();
- return settings;
- }
- const int length = \
static_cast<int>(animations.property(QStringLiteral("length")).toInteger());
- for (int i=0; i<length; ++i) {
- QJSValue value = animations.property(QString::number(i));
- if (!value.isValid()) {
- continue;
- }
- if (value.isObject()) {
- AnimationSettings s = animationSettingsFromObject(value);
- const uint set = s.set | settings.at(0).set;
- // Catch show stoppers (incompletable animation)
- if (!(set & AnimationSettings::Type)) {
- context->throwError(QScriptContext::TypeError, \
QStringLiteral("Type property missing in animation options"));
- continue;
- }
- if (!(set & AnimationSettings::Duration)) {
- context->throwError(QScriptContext::TypeError, \
QStringLiteral("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;
- }
-
- s.metaData = 0;
- typedef QMap<AnimationEffect::MetaType, QString> MetaTypeMap;
- static MetaTypeMap metaTypes({
- {AnimationEffect::SourceAnchor, QStringLiteral("sourceAnchor")},
- {AnimationEffect::TargetAnchor, QStringLiteral("targetAnchor")},
- {AnimationEffect::RelativeSourceX, \
QStringLiteral("relativeSourceX")},
- {AnimationEffect::RelativeSourceY, \
QStringLiteral("relativeSourceY")},
- {AnimationEffect::RelativeTargetX, \
QStringLiteral("relativeTargetX")},
- {AnimationEffect::RelativeTargetY, \
QStringLiteral("relativeTargetY")},
- {AnimationEffect::Axis, QStringLiteral("axis")}
- });
-
- for (MetaTypeMap::const_iterator it = metaTypes.constBegin(),
- end = metaTypes.constEnd(); it != \
end; ++it) {
- QJSValue metaVal = value.property(*it);
- if (metaVal.isNumber()) {
- AnimationEffect::setMetaData(it.key(), metaVal.toInt(), \
s.metaData);
- }
- }
-
- settings << s;
- }
- }
- }
-
- if (settings.count() == 1) {
- const uint set = settings.at(0).set;
- if (!(set & AnimationSettings::Type)) {
- context->throwError(QScriptContext::TypeError, QStringLiteral("Type \
property missing in animation options"));
- settings.clear();
- }
- if (!(set & AnimationSettings::Duration)) {
- context->throwError(QScriptContext::TypeError, QStringLiteral("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;
-}
-
QJSValue kwinEffectAnimate(QScriptContext *context, QJSEngine *engine)
{
-// ScriptedEffect *effect = \
qobject_cast<ScriptedEffect*>(context->callee().data().toQObject());
-// EffectWindow *window;
-// QList<AnimationSettings> settings = animationSettings(context, effect, \
&window);
-// if (settings.empty()) {
-// context->throwError(QScriptContext::TypeError, QStringLiteral("No \
animations provided"));
-// return QJSValue();
-// }
-// if (!window) {
-// context->throwError(QScriptContext::TypeError, QStringLiteral("Window \
property does not contain an EffectWindow"));
-// return QJSValue();
-// }
-
-// QJSValue array = engine->newArray(settings.length());
-// int i = 0;
-// foreach (const AnimationSettings &setting, settings) {
-// array.setProperty(i, (uint)effect->animate(window,
-// setting.type,
-// setting.duration,
-// setting.to,
-// setting.from,
-// setting.metaData,
-// setting.curve,
-// setting.delay));
-// ++i;
-// }
-// return array;
+ // ScriptedEffect *effect = \
qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); + // \
EffectWindow *window; + // QList<AnimationSettings> settings = \
animationSettings(context, effect, &window); + // if (settings.empty()) {
+ // context->createError(QScriptContext::TypeError, QStringLiteral("No \
animations provided")); + // return QJSValue();
+ // }
+ // if (!window) {
+ // context->createError(QScriptContext::TypeError, QStringLiteral("Window \
property does not contain an EffectWindow")); + // return QJSValue();
+ // }
+
+ // QJSValue array = engine->newArray(settings.length());
+ // int i = 0;
+ // foreach (const AnimationSettings &setting, settings) {
+ // array.setProperty(i, (uint)effect->animate(window,
+ // setting.type,
+ // setting.duration,
+ // setting.to,
+ // setting.from,
+ // setting.metaData,
+ // setting.curve,
+ // setting.delay));
+ // ++i;
+ // }
+ // return array;
return QJSValue();
}
@@ -230,32 +138,32 @@ QJSValue kwinEffectSet(QScriptContext *context, QJSEngine \
*engine) return QJSValue();
-// ScriptedEffect *effect = \
qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); + // \
ScriptedEffect *effect = \
qobject_cast<ScriptedEffect*>(context->callee().data().toQObject());
-// EffectWindow *window;
-// QList<AnimationSettings> settings = animationSettings(context, effect, \
&window);
-// if (settings.empty()) {
-// context->throwError(QScriptContext::TypeError, QStringLiteral("No \
animations provided"));
-// return QJSValue();
-// }
-// if (!window) {
-// context->throwError(QScriptContext::TypeError, QStringLiteral("Window \
property does not contain an EffectWindow"));
-// return QJSValue();
-// }
+ // EffectWindow *window;
+ // QList<AnimationSettings> settings = animationSettings(context, effect, \
&window); + // if (settings.empty()) {
+ // context->createError(QScriptContext::TypeError, QStringLiteral("No \
animations provided")); + // return QJSValue();
+ // }
+ // if (!window) {
+ // context->createError(QScriptContext::TypeError, QStringLiteral("Window \
property does not contain an EffectWindow")); + // return QJSValue();
+ // }
-// QList<QVariant> animIds;
-// foreach (const AnimationSettings &setting, settings) {
-// animIds << QVariant(effect->set(window,
-// setting.type,
-// setting.duration,
-// setting.to,
-// setting.from,
-// setting.metaData,
-// setting.curve,
-// setting.delay));
-// }
+ // QList<QVariant> animIds;
+ // foreach (const AnimationSettings &setting, settings) {
+ // animIds << QVariant(effect->set(window,
+ // setting.type,
+ // setting.duration,
+ // setting.to,
+ // setting.from,
+ // setting.metaData,
+ // setting.curve,
+ // setting.delay));
+ // }
-// return engine->newVariant(animIds);
+ // return engine->newVariant(animIds);
}
QList<quint64> animations(const QVariant &v, bool *ok)
@@ -343,7 +251,7 @@ ScriptedEffect::ScriptedEffect()
{
-// connect(m_engine, SIGNAL(signalHandlerException(QJSValue)), \
SLOT(signalHandlerException(QJSValue))); + // connect(m_engine, \
SIGNAL(signalHandlerException(QJSValue)), SLOT(signalHandlerException(QJSValue))); }
ScriptedEffect::~ScriptedEffect()
@@ -414,7 +322,7 @@ bool ScriptedEffect::init(const QString &effectName, const \
QString &pathToScript if (ret.isError()) {
qDebug() <<" HERE! " << ret.property("lineNumber").toInt() << \
ret.toString();
-// signalHandlerException(ret);
+ // signalHandlerException(ret);
return false;
}
scriptFile.close();
@@ -508,13 +416,126 @@ QJSValue ScriptedEffect::animateGlobal(const QJSValue &args)
return startAnimation(args, false);
}
-QJSValue ScriptedEffect::setGlobal(const QJSValue &args)
+QJSValue ScriptedEffect::setGlobal(const QJSValue &object)
{
- return startAnimation(args, true);
+ return startAnimation(object, true);
+}
+
+QJSValue createError(const QString &error) {
+ return QJSValue();
}
-QJSValue startAnimation(const QJSValue &value, bool set)
+QJSValue ScriptedEffect::startAnimation(const QJSValue &object, bool \
settingPersists) {
+ QVector<AnimationSettings> settings;
+ QJSValue windowProperty = object.property(QStringLiteral("window"));
+ if (!windowProperty.isObject()) {
+ return createError(QStringLiteral("Window property missing in animation \
options")); + }
+ auto window = qobject_cast<EffectWindow*>(windowProperty.toQObject());
+ if (!window) {
+ return createError(QStringLiteral("Window property references invalid \
window")); + }
+
+ settings << animationSettingsFromObject(object); // global
+
+ QJSValue animations = object.property(QStringLiteral("animations")); // array
+ if (!animations.isNull()) {
+ if (!animations.isArray()) {
+ return createError(QStringLiteral("Animations provided but not an \
array")); + }
+ const int length = \
static_cast<int>(animations.property(QStringLiteral("length")).toInt()); + for \
(int i=0; i<length; ++i) { + QJSValue value = \
animations.property(QString::number(i)); + if (value.isObject()) {
+ AnimationSettings s = animationSettingsFromObject(value);
+ const uint set = s.set | settings.at(0).set;
+ // Catch show stoppers (incompletable animation)
+ if (!(set & AnimationSettings::Type)) {
+ return createError(QStringLiteral("Type property missing in \
animation options")); + }
+ if (!(set & AnimationSettings::Duration)) {
+ return createError(QStringLiteral("Duration property missing in \
animation options")); + }
+ // 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;
+ }
+
+ s.metaData = 0;
+ typedef QMap<AnimationEffect::MetaType, QString> MetaTypeMap;
+ static MetaTypeMap metaTypes({
+ {AnimationEffect::SourceAnchor, \
QStringLiteral("sourceAnchor")}, + \
{AnimationEffect::TargetAnchor, QStringLiteral("targetAnchor")}, + \
{AnimationEffect::RelativeSourceX, QStringLiteral("relativeSourceX")}, + \
{AnimationEffect::RelativeSourceY, QStringLiteral("relativeSourceY")}, + \
{AnimationEffect::RelativeTargetX, QStringLiteral("relativeTargetX")}, + \
{AnimationEffect::RelativeTargetY, QStringLiteral("relativeTargetY")}, + \
{AnimationEffect::Axis, QStringLiteral("axis")} + \
}); +
+ for (MetaTypeMap::const_iterator it = metaTypes.constBegin(),
+ end = metaTypes.constEnd(); it != end; ++it) {
+ QJSValue metaVal = value.property(*it);
+ if (metaVal.isNumber()) {
+ AnimationEffect::setMetaData(it.key(), metaVal.toInt(), \
s.metaData); + }
+ }
+
+ settings << s;
+ }
+ }
+ }
+
+ if (settings.count() == 1) {
+ const uint set = settings.at(0).set;
+ if (!(set & AnimationSettings::Type)) {
+ return createError(QStringLiteral("Type property missing in animation \
options")); + }
+ if (!(set & AnimationSettings::Duration)) {
+ return createError(QStringLiteral("Duration property missing in \
animation options")); + }
+ } else if (!(settings.at(0).set & AnimationSettings::Type)) { // invalid global
+ settings.removeAt(0); // -> get rid of it, only used to complete the others
+ }
+
+ if (settings.isEmpty()) {
+ return createError(QStringLiteral("No animations provided"));
+ }
+
+
+ QJSValue array = m_engine->newArray(settings.length());
+ for (int i = 0 ; i < settings.count() ; i++) {
+ const AnimationSettings &setting = settings[i];
+ int animationId;
+ if (settingPersists) {
+ animationId = set(window,
+ setting.type,
+ setting.duration,
+ setting.to,
+ setting.from,
+ setting.metaData,
+ setting.curve,
+ setting.delay);
+ } else {
+ animationId = animate(window,
+ setting.type,
+ setting.duration,
+ setting.to,
+ setting.from,
+ setting.metaData,
+ setting.curve,
+ setting.delay);
+ }
+ array.setProperty(i, animationId);
+ }
+ return array;
}
bool ScriptedEffect::cancel(quint64 animationId)
@@ -563,10 +584,10 @@ bool ScriptedEffect::registerShortcut(const QString \
&objectName, const QString & connect(a, &QAction::triggered, this, [this, a, \
callback]() { QJSValue c(callback);
-// QJSValue value(it.value());
- //DAVE - WTF is this for? why would a JS script need to know the action? it \
can just use a different callback?
-// arguments << m_engine->newQObject(a);
-// auto c = const_cast<QJSValue>(callback); // see docs in QJSValue::call \
it's safe + // QJSValue value(it.value());
+ //DAVE - what is this for? why would a JS script need to know the action? it \
can just use a different callback? + // arguments << \
m_engine->newQObject(a); + // auto c = const_cast<QJSValue>(callback);
c.call(QJSValueList());
});
return true;
@@ -624,10 +645,10 @@ bool ScriptedEffect::registerTouchScreenEdge(int edge, const \
QJSValue &callback) }
QAction *action = new QAction(this);
connect(action, &QAction::triggered, this,
- [callback] {
- QJSValue invoke(callback);
- invoke.call();
- }
+ [callback] {
+ QJSValue invoke(callback);
+ invoke.call();
+ }
);
ScreenEdges::self()->reserveTouch(KWin::ElectricBorder(edge), action);
m_touchScreenEdgeCallbacks.insert(edge, action);
diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h
index a56ca6794..8d70fa693 100644
--- a/scripting/scriptedeffect.h
+++ b/scripting/scriptedeffect.h
@@ -23,10 +23,11 @@ along with this program. If not, see \
<http://www.gnu.org/licenses/>.
#include <kwinanimationeffect.h>
+#include <QJSValue>
+
class KConfigLoader;
class KPluginMetaData;
class QJSEngine;
-class QJSValue;
namespace KWin
{
@@ -105,9 +106,8 @@ public:
return m_screenEdgeCallbacks;
}
public Q_SLOTS:
- //from = QJSValue()
- quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, const QJSValue &to, \
const QJSValue &from, uint metaData = 0, QEasingCurve::Type curve = \
QEasingCurve::Linear, int delay = 0);
- quint64 set(KWin::EffectWindow *w, Attribute a, int ms, const QJSValue &to, \
const QJSValue &from, uint metaData = 0, QEasingCurve::Type curve = \
QEasingCurve::Linear, int delay = 0); + quint64 animate(KWin::EffectWindow *w, \
Attribute a, int ms, const QJSValue &to, const QJSValue &from = QJSValue(), uint \
metaData = 0, QEasingCurve::Type curve = QEasingCurve::Linear, int delay = 0); + \
quint64 set(KWin::EffectWindow *w, Attribute a, int ms, const QJSValue &to, const \
QJSValue &from = QJSValue(), uint metaData = 0, QEasingCurve::Type curve = \
QEasingCurve::Linear, int delay = 0);
bool retarget(quint64 animationId, const QJSValue &newTarget, int \
newRemainingTime = -1);
bool retarget(QList<quint64> animationIds, const QJSValue &newTarget, int \
newRemainingTime = -1); @@ -117,8 +117,8 @@ public Q_SLOTS:
//takes a big object blob of data, returns an array of
//or throws an error
- QJSValue animateGlobal(const QJSValue &args);
- QJSValue setGlobal(const QJSValue &args);
+ QJSValue animateGlobal(const QJSValue &object);
+ QJSValue setGlobal(const QJSValue &object);
bool borderActivated(ElectricBorder border) override;
@@ -137,7 +137,7 @@ protected:
private:
//wrapper round animateGlobal/setGlobal that parses the animations blob.
- QJSValue startAnimation(const QJSValue &value, bool set);
+ QJSValue startAnimation(const QJSValue &object, bool settingPersists);
QJSEngine *m_engine;
QString m_effectName;
QString m_scriptFile;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic