[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kwin/scripting2] scripting: animate
From: David Edmundson <null () kde ! org>
Date: 2018-07-31 21:37:18
Message-ID: E1fkcKU-0001yG-Ov () code ! kde ! org
[Download RAW message or body]
Git commit 63d4b8b68972d4f4f5a911f26a20ac266d0452bd by David Edmundson.
Committed on 31/07/2018 at 20:28.
Pushed by davidedmundson into branch 'scripting2'.
animate
M +46 -125 scripting/scriptedeffect.cpp
M +15 -5 scripting/scriptedeffect.h
https://commits.kde.org/kwin/63d4b8b68972d4f4f5a911f26a20ac266d0452bd
diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp
index 5f6c0c177..1a2e9109b 100644
--- a/scripting/scriptedeffect.cpp
+++ b/scripting/scriptedeffect.cpp
@@ -100,6 +100,9 @@ AnimationSettings animationSettingsFromObject(QJSValue &object)
return settings;
}
+//takes exactly one argument, an object
+//returns list of animations and the effect window
+
//QList<AnimationSettings> animationSettings(QScriptContext *context, ScriptedEffect \
*effect, EffectWindow **window) //{
// QList<AnimationSettings> settings;
@@ -234,6 +237,7 @@ QJSValue kwinEffectAnimate(QScriptContext *context, QJSEngine \
*engine) return QJSValue();
}
+
QJSValue kwinEffectSet(QScriptContext *context, QJSEngine *engine)
{
return QJSValue();
@@ -290,98 +294,24 @@ QList<quint64> animations(const QVariant &v, bool *ok)
return animIds;
}
-QJSValue fpx2ToScriptValue(QJSEngine *eng, const KWin::FPx2 &fpx2)
-{
- QJSValue val = eng->newObject();
- val.setProperty(QStringLiteral("value1"), fpx2[0]);
- val.setProperty(QStringLiteral("value2"), fpx2[1]);
- return val;
-}
-
-void fpx2FromScriptValue(const QJSValue &value, KWin::FPx2 &fpx2)
+KWin::FPx2 fpx2FromScriptValue(const QJSValue &value)
{
if (value.isNull()) {
- fpx2 = FPx2();
- return;
+ return FPx2();
}
if (value.isNumber()) {
- fpx2 = FPx2(value.toNumber());
- return;
+ return FPx2(value.toNumber());
}
if (value.isObject()) {
QJSValue value1 = value.property(QStringLiteral("value1"));
QJSValue value2 = value.property(QStringLiteral("value2"));
if (!value1.isNumber() || !value2.isNumber()) {
qCDebug(KWIN_SCRIPTING) << "Cannot cast scripted FPx2 to C++";
- fpx2 = FPx2();
- return;
+ return FPx2();
}
- fpx2 = FPx2(value1.toNumber(), value2.toNumber());
- }
-}
-
-QJSValue kwinEffectRetarget(QScriptContext *context, QJSEngine *engine)
-{
-// ScriptedEffect *effect = \
qobject_cast<ScriptedEffect*>(context->callee().data().toQObject());
-// if (context->argumentCount() < 2 || context->argumentCount() > 3) {
-// context->throwError(QScriptContext::SyntaxError, QStringLiteral("2 or 3 \
arguments expected"));
-// return QJSValue();
-// }
-// QVariant v = context->argument(0).toVariant();
-// bool ok = false;
-// QList<quint64> animIds = animations(v, &ok);
-// if (!ok) {
-// context->throwError(QScriptContext::TypeError, QStringLiteral("Argument \
needs to be one or several quint64"));
-// return QJSValue();
-// }
-// FPx2 target;
-// fpx2FromScriptValue(context->argument(1), target);
-
-// ok = false;
-// const int remainingTime = context->argumentCount() == 3 ? \
context->argument(2).toVariant().toInt() : -1;
-// foreach (const quint64 &animId, animIds) {
-// ok = effect->retarget(animId, target, remainingTime);
-// if (!ok) {
-// break;
-// }
-// }
-
- return QJSValue();
-}
-
-QJSValue kwinEffectCancel(QScriptContext *context, QJSEngine *engine)
-{
- ScriptedEffect *effect = \
qobject_cast<ScriptedEffect*>(context->callee().data().toQObject());
- if (context->argumentCount() != 1) {
- context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one \
argument expected"));
- return QJSValue();
- }
- QVariant v = context->argument(0).toVariant();
- bool ok = false;
- QList<quint64> animIds = animations(v, &ok);
- if (!ok) {
- context->throwError(QScriptContext::TypeError, QStringLiteral("Argument \
needs to be one or several quint64"));
- return QJSValue();
- }
- foreach (const quint64 &animId, animIds) {
- ok |= effect->cancel(animId);
+ return FPx2(value1.toNumber(), value2.toNumber());
}
-
- return QJSValue(ok);
-}
-
-QJSValue effectWindowToScriptValue(QJSEngine *eng, const KEffectWindowRef &window)
-{
-
- //TODO
- return eng->newQObject(window);
-// return eng->newQObject(window, QJSEngine::QtOwnership,
-// QJSEngine::ExcludeChildObjects | \
QJSEngine::ExcludeDeleteLater | \
QJSEngine::PreferExistingWrapperObject);
-}
-
-void effectWindowFromScriptValue(const QJSValue &value, EffectWindow* &window)
-{
- window = qobject_cast<EffectWindow*>(value.toQObject());
+ return FPx2();
}
ScriptedEffect *ScriptedEffect::create(const KPluginMetaData &effect)
@@ -424,6 +354,8 @@ ScriptedEffect::ScriptedEffect()
, m_config(nullptr)
, m_chainPosition(0)
{
+
+
// connect(m_engine, SIGNAL(signalHandlerException(QJSValue)), \
SLOT(signalHandlerException(QJSValue))); }
@@ -467,6 +399,7 @@ bool ScriptedEffect::init(const QString &effectName, const \
QString &pathToScript #ifndef KWIN_UNIT_TEST
m_engine->globalObject().setProperty(QStringLiteral("KWin"), \
m_engine->newQMetaObject(&QtScriptWorkspaceWrapper::staticMetaObject)); #endif
+
m_engine->globalObject().setProperty(QStringLiteral("QEasingCurve"), \
m_engine->newQMetaObject(&QEasingCurve::staticMetaObject));
m_engine->globalObject().setProperty("effect", selfWrapper);
@@ -482,54 +415,18 @@ bool ScriptedEffect::init(const QString &effectName, const \
QString &pathToScript
engine()->globalObject().setProperty("registerTouchScreenEdge", \
selfWrapper.property("registerTouchScreenEdge"));
engine()->globalObject().setProperty("unregisterTouchScreenEdge", \
selfWrapper.property("unregisterTouchScreenEdge"));
- engine()->globalObject().setProperty("animate", \
selfWrapper.property("animate")); +// \
engine()->globalObject().setProperty("animate", \
selfWrapper.property("animateInternal")); +// \
engine()->globalObject().setProperty("set", \
selfWrapper.property("setInternal"));
engine()->globalObject().setProperty("retarget", \
selfWrapper.property("retarget"));
- engine()->globalObject().setProperty("set", selfWrapper.property("set"));
engine()->globalObject().setProperty("cancel", selfWrapper.property("cancel"));
engine()->globalObject().setProperty("print", selfWrapper.property("print"));
-//TODO
-// fpx2
-// print
- // animate + friends
- //screen edge
- //touchscreen function
-
-
// MetaScripting::registration(m_engine);
// qScriptRegisterMetaType<KWin::FPx2>(m_engine, fpx2ToScriptValue, \
fpx2FromScriptValue); // qScriptRegisterSequenceMetaType<QList< \
KWin::EffectWindow* > >(m_engine);
-// // add our print
-// QJSValue printFunc = m_engine->newFunction(kwinEffectScriptPrint);
-// printFunc.setData(m_engine->newQObject(this));
-// m_engine->globalObject().setProperty(QStringLiteral("print"), printFunc);
-
-// // add global Shortcut
-// registerScreenEdgeFunction(this, m_engine, kwinScriptScreenEdge);
-// registerTouchScreenEdgeFunction(this, m_engine, kwinRegisterTouchScreenEdge);
-// unregisterTouchScreenEdgeFunction(this, m_engine, \
kwinUnregisterTouchScreenEdge);
-
-// // add the animate method
-// QJSValue animateFunc = m_engine->newFunction(kwinEffectAnimate);
-// animateFunc.setData(m_engine->newQObject(this));
-// m_engine->globalObject().setProperty(QStringLiteral("animate"), animateFunc);
-
-// // and the set variant
-// QJSValue setFunc = m_engine->newFunction(kwinEffectSet);
-// setFunc.setData(m_engine->newQObject(this));
-// m_engine->globalObject().setProperty(QStringLiteral("set"), setFunc);
-
-// // retarget
-// QJSValue retargetFunc = m_engine->newFunction(kwinEffectRetarget);
-// retargetFunc.setData(m_engine->newQObject(this));
-// m_engine->globalObject().setProperty(QStringLiteral("retarget"), \
retargetFunc);
-
-// // cancel...
-// QJSValue cancelFunc = m_engine->newFunction(kwinEffectCancel);
-// cancelFunc.setData(m_engine->newQObject(this));
-// m_engine->globalObject().setProperty(QStringLiteral("cancel"), cancelFunc);
+
QJSValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll()));
@@ -591,31 +488,55 @@ void ScriptedEffect::animationEnded(KWin::EffectWindow *w, \
Attribute a, uint met // }
//}
-quint64 ScriptedEffect::animate(KWin::EffectWindow* w, \
KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint \
metaData, QEasingCurve::Type curve, int delay) +quint64 \
ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, \
int ms, const QJSValue &to, const QJSValue &from, uint metaData, QEasingCurve::Type \
curve, int delay) {
QEasingCurve qec;
if (curve < QEasingCurve::Custom)
qec.setType(curve);
else if (static_cast<int>(curve) == static_cast<int>(GaussianCurve))
qec.setCustomType(qecGaussian);
- return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, from);
+ return AnimationEffect::animate(w, a, metaData, ms, fpx2FromScriptValue(to), \
qec, delay, fpx2FromScriptValue(from)); }
-quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute \
a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, QEasingCurve::Type curve, \
int delay) +quint64 ScriptedEffect::set(KWin::EffectWindow* w, \
KWin::AnimationEffect::Attribute a, int ms, const QJSValue &to, const QJSValue &from, \
uint metaData, QEasingCurve::Type curve, int delay) {
QEasingCurve qec;
if (curve < QEasingCurve::Custom)
qec.setType(curve);
else if (static_cast<int>(curve) == static_cast<int>(GaussianCurve))
qec.setCustomType(qecGaussian);
- return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from);
+ return AnimationEffect::set(w, a, metaData, ms, fpx2FromScriptValue(to), qec, \
delay, fpx2FromScriptValue(from)); }
-bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int \
newRemainingTime) +bool ScriptedEffect::retarget(quint64 animationId, const QJSValue \
&newTarget, int newRemainingTime) {
- return AnimationEffect::retarget(animationId, newTarget, newRemainingTime);
+ return AnimationEffect::retarget(animationId, fpx2FromScriptValue(newTarget), \
newRemainingTime); }
+bool ScriptedEffect::retarget(QList<quint64> animationIds, const QJSValue \
&newTarget, int newRemainingTime) +{
+ bool ok = true;
+ for(quint64 animationId: animationIds) {
+ ok |= retarget(animationId, newTarget, newRemainingTime);
+ }
+ return true;
+}
+
+bool ScriptedEffect::cancel(quint64 animationId)
+{
+ return AnimationEffect::cancel(animationId);
+}
+
+bool ScriptedEffect::cancel(QList<quint64> animationIds)
+{
+ bool ok = true;
+ for(quint64 animationId: animationIds) {
+ ok |= cancel(animationId);
+ }
+ return true;
+}
+
+
bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole)
{
void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>();
diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h
index 0830ffd39..eca4d61ed 100644
--- a/scripting/scriptedeffect.h
+++ b/scripting/scriptedeffect.h
@@ -27,10 +27,10 @@ class KConfigLoader;
class KPluginMetaData;
class QJSEngine;
class QJSValue;
-typedef QList<QJSValue> QJSValueList;
namespace KWin
{
+
class KWIN_EXPORT ScriptedEffect : public KWin::AnimationEffect
{
Q_OBJECT
@@ -105,10 +105,19 @@ public:
return m_screenEdgeCallbacks;
}
public Q_SLOTS:
- quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, \
KWin::FPx2 from = KWin::FPx2(), uint metaData = 0, 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(), uint metaData = 0, QEasingCurve::Type curve = \
QEasingCurve::Linear, int delay = 0);
- bool retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime = \
-1);
- bool cancel(quint64 animationId) { return AnimationEffect::cancel(animationId); \
} + //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); +
+ bool retarget(quint64 animationId, const QJSValue &newTarget, int \
newRemainingTime = -1); + bool retarget(QList<quint64> animationIds, const \
QJSValue &newTarget, int newRemainingTime = -1); +
+ bool cancel(quint64 animationId);
+ bool cancel(QList<quint64> animationIds);
+
+// QJSValue animateInternal(const QJSValue &args) {}
+// QJSValue setInternal(const QJSValue &args) {}
+
bool borderActivated(ElectricBorder border) override;
Q_SIGNALS:
@@ -134,6 +143,7 @@ private:
QHash<int, QAction*> m_touchScreenEdgeCallbacks;
};
+
}
#endif // KWIN_SCRIPTEDEFFECT_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic