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(QScriptContext *context, Scri= ptedEffect *effect, EffectWindow **window) //{ // QList settings; @@ -234,6 +237,7 @@ QJSValue kwinEffectAnimate(QScriptContext *context, QJS= Engine *engine) return QJSValue(); } = + QJSValue kwinEffectSet(QScriptContext *context, QJSEngine *engine) { return QJSValue(); @@ -290,98 +294,24 @@ QList animations(const QVariant &v, bool *ok) return animIds; } = -QJSValue fpx2ToScriptValue(QJSEngine *eng, const KWin::FPx2 &fpx2) -{ - QJSValue val =3D 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 =3D FPx2(); - return; + return FPx2(); } if (value.isNumber()) { - fpx2 =3D FPx2(value.toNumber()); - return; + return FPx2(value.toNumber()); } if (value.isObject()) { QJSValue value1 =3D value.property(QStringLiteral("value1")); QJSValue value2 =3D value.property(QStringLiteral("value2")); if (!value1.isNumber() || !value2.isNumber()) { qCDebug(KWIN_SCRIPTING) << "Cannot cast scripted FPx2 to C++"; - fpx2 =3D FPx2(); - return; + return FPx2(); } - fpx2 =3D FPx2(value1.toNumber(), value2.toNumber()); - } -} - -QJSValue kwinEffectRetarget(QScriptContext *context, QJSEngine *engine) -{ -// ScriptedEffect *effect =3D qobject_cast(context->ca= llee().data().toQObject()); -// if (context->argumentCount() < 2 || context->argumentCount() > 3) { -// context->throwError(QScriptContext::SyntaxError, QStringLiteral(= "2 or 3 arguments expected")); -// return QJSValue(); -// } -// QVariant v =3D context->argument(0).toVariant(); -// bool ok =3D false; -// QList animIds =3D animations(v, &ok); -// if (!ok) { -// context->throwError(QScriptContext::TypeError, QStringLiteral("A= rgument needs to be one or several quint64")); -// return QJSValue(); -// } -// FPx2 target; -// fpx2FromScriptValue(context->argument(1), target); - -// ok =3D false; -// const int remainingTime =3D context->argumentCount() =3D=3D 3 ? cont= ext->argument(2).toVariant().toInt() : -1; -// foreach (const quint64 &animId, animIds) { -// ok =3D effect->retarget(animId, target, remainingTime); -// if (!ok) { -// break; -// } -// } - - return QJSValue(); -} - -QJSValue kwinEffectCancel(QScriptContext *context, QJSEngine *engine) -{ - ScriptedEffect *effect =3D qobject_cast(context->call= ee().data().toQObject()); - if (context->argumentCount() !=3D 1) { - context->throwError(QScriptContext::SyntaxError, QStringLiteral("E= xactly one argument expected")); - return QJSValue(); - } - QVariant v =3D context->argument(0).toVariant(); - bool ok =3D false; - QList animIds =3D animations(v, &ok); - if (!ok) { - context->throwError(QScriptContext::TypeError, QStringLiteral("Arg= ument needs to be one or several quint64")); - return QJSValue(); - } - foreach (const quint64 &animId, animIds) { - ok |=3D 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::E= xcludeDeleteLater | QJSEngine::PreferExistingWrapperObject); -} - -void effectWindowFromScriptValue(const QJSValue &value, EffectWindow* &win= dow) -{ - window =3D qobject_cast(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(sig= nalHandlerException(QJSValue))); } = @@ -467,6 +399,7 @@ bool ScriptedEffect::init(const QString &effectName, co= nst 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", selfWr= apper.property("registerTouchScreenEdge")); engine()->globalObject().setProperty("unregisterTouchScreenEdge", self= Wrapper.property("unregisterTouchScreenEdge")); = - engine()->globalObject().setProperty("animate", selfWrapper.property("= animate")); +// engine()->globalObject().setProperty("animate", selfWrapper.property= ("animateInternal")); +// engine()->globalObject().setProperty("set", selfWrapper.property("s= etInternal")); engine()->globalObject().setProperty("retarget", selfWrapper.property(= "retarget")); - engine()->globalObject().setProperty("set", selfWrapper.property("set"= )); engine()->globalObject().setProperty("cancel", selfWrapper.property("c= ancel")); = engine()->globalObject().setProperty("print", selfWrapper.property("pr= int")); = = -//TODO -// fpx2 -// print - // animate + friends - //screen edge - //touchscreen function - - // MetaScripting::registration(m_engine); // qScriptRegisterMetaType(m_engine, fpx2ToScriptValue, fpx= 2FromScriptValue); // qScriptRegisterSequenceMetaType >(m_eng= ine); -// // add our print -// QJSValue printFunc =3D m_engine->newFunction(kwinEffectScriptPrint); -// printFunc.setData(m_engine->newQObject(this)); -// m_engine->globalObject().setProperty(QStringLiteral("print"), printF= unc); - -// // add global Shortcut -// registerScreenEdgeFunction(this, m_engine, kwinScriptScreenEdge); -// registerTouchScreenEdgeFunction(this, m_engine, kwinRegisterTouchScr= eenEdge); -// unregisterTouchScreenEdgeFunction(this, m_engine, kwinUnregisterTouc= hScreenEdge); - -// // add the animate method -// QJSValue animateFunc =3D m_engine->newFunction(kwinEffectAnimate); -// animateFunc.setData(m_engine->newQObject(this)); -// m_engine->globalObject().setProperty(QStringLiteral("animate"), anim= ateFunc); - -// // and the set variant -// QJSValue setFunc =3D m_engine->newFunction(kwinEffectSet); -// setFunc.setData(m_engine->newQObject(this)); -// m_engine->globalObject().setProperty(QStringLiteral("set"), setFunc); - -// // retarget -// QJSValue retargetFunc =3D m_engine->newFunction(kwinEffectRetarget); -// retargetFunc.setData(m_engine->newQObject(this)); -// m_engine->globalObject().setProperty(QStringLiteral("retarget"), ret= argetFunc); - -// // cancel... -// QJSValue cancelFunc =3D m_engine->newFunction(kwinEffectCancel); -// cancelFunc.setData(m_engine->newQObject(this)); -// m_engine->globalObject().setProperty(QStringLiteral("cancel"), cance= lFunc); + = QJSValue ret =3D m_engine->evaluate(QString::fromUtf8(scriptFile.readA= ll())); = @@ -591,31 +488,55 @@ void ScriptedEffect::animationEnded(KWin::EffectWindo= w *w, Attribute a, uint met // } //} = -quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffe= ct::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, QEa= singCurve::Type curve, int delay) +quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffe= ct::Attribute a, int ms, const QJSValue &to, const QJSValue &from, uint met= aData, QEasingCurve::Type curve, int delay) { QEasingCurve qec; if (curve < QEasingCurve::Custom) qec.setType(curve); else if (static_cast(curve) =3D=3D static_cast(GaussianCurve= )) qec.setCustomType(qecGaussian); - return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, fr= om); + return AnimationEffect::animate(w, a, metaData, ms, fpx2FromScriptValu= e(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, QEasing= Curve::Type curve, int delay) +quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::= Attribute a, int ms, const QJSValue &to, const QJSValue &from, uint metaDat= a, QEasingCurve::Type curve, int delay) { QEasingCurve qec; if (curve < QEasingCurve::Custom) qec.setType(curve); else if (static_cast(curve) =3D=3D static_cast(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, i= nt newRemainingTime) +bool ScriptedEffect::retarget(quint64 animationId, const QJSValue &newTarg= et, int newRemainingTime) { - return AnimationEffect::retarget(animationId, newTarget, newRemainingT= ime); + return AnimationEffect::retarget(animationId, fpx2FromScriptValue(newT= arget), newRemainingTime); } = +bool ScriptedEffect::retarget(QList animationIds, const QJSValue = &newTarget, int newRemainingTime) +{ + bool ok =3D true; + for(quint64 animationId: animationIds) { + ok |=3D retarget(animationId, newTarget, newRemainingTime); + } + return true; +} + +bool ScriptedEffect::cancel(quint64 animationId) +{ + return AnimationEffect::cancel(animationId); +} + +bool ScriptedEffect::cancel(QList animationIds) +{ + bool ok =3D true; + for(quint64 animationId: animationIds) { + ok |=3D cancel(animationId); + } + return true; +} + + bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole g= rabRole) { void *e =3D w->data(static_cast(grabRole)).value(); 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 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 =3D KWin::FPx2(), uint metaData =3D 0, QEasingCurve::T= ype curve =3D QEasingCurve::Linear, int delay =3D 0); - quint64 set(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to,= KWin::FPx2 from =3D KWin::FPx2(), uint metaData =3D 0, QEasingCurve::Type = curve =3D QEasingCurve::Linear, int delay =3D 0); - bool retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemain= ingTime =3D -1); - bool cancel(quint64 animationId) { return AnimationEffect::cancel(anim= ationId); } + //from =3D QJSValue() + quint64 animate(KWin::EffectWindow *w, Attribute a, int ms, const QJSV= alue &to, const QJSValue &from, uint metaData =3D 0, QEasingCurve::Type cur= ve =3D QEasingCurve::Linear, int delay =3D 0); + quint64 set(KWin::EffectWindow *w, Attribute a, int ms, const QJSValue= &to, const QJSValue &from, uint metaData =3D 0, QEasingCurve::Type curve = =3D QEasingCurve::Linear, int delay =3D 0); + + bool retarget(quint64 animationId, const QJSValue &newTarget, int newR= emainingTime =3D -1); + bool retarget(QList animationIds, const QJSValue &newTarget, = int newRemainingTime =3D -1); + + bool cancel(quint64 animationId); + bool cancel(QList animationIds); + +// QJSValue animateInternal(const QJSValue &args) {} +// QJSValue setInternal(const QJSValue &args) {} + bool borderActivated(ElectricBorder border) override; = Q_SIGNALS: @@ -134,6 +143,7 @@ private: QHash m_touchScreenEdgeCallbacks; }; = + } = #endif // KWIN_SCRIPTEDEFFECT_H