From kde-commits Tue Jul 31 21:37:18 2018 From: David Edmundson Date: Tue, 31 Jul 2018 21:37:18 +0000 To: kde-commits Subject: [kwin/scripting2] scripting: ASDFA ASDFASDFEWRWER Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=153307305910833 Git commit a8393c8b8249262317593d02ac959c9dc4bab565 by David Edmundson. Committed on 31/07/2018 at 20:28. Pushed by davidedmundson into branch 'scripting2'. ASDFA ASDFASDFEWRWER M +104 -109 scripting/scriptedeffect.cpp M +6 -2 scripting/scriptedeffect.h https://commits.kde.org/kwin/a8393c8b8249262317593d02ac959c9dc4bab565 diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp index 1a2e9109b..a642b7717 100644 --- a/scripting/scriptedeffect.cpp +++ b/scripting/scriptedeffect.cpp @@ -103,108 +103,95 @@ AnimationSettings animationSettingsFromObject(QJSVal= ue &object) //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; -// if (!effect) { -// context->throwError(QScriptContext::ReferenceError, QStringLiter= al("Internal Scripted KWin Effect error")); -// return settings; -// } -// if (context->argumentCount() !=3D 1) { -// context->throwError(QScriptContext::SyntaxError, QStringLiteral(= "Exactly one argument expected")); -// return settings; -// } -// if (!context->argument(0).isObject()) { -// context->throwError(QScriptContext::TypeError, QStringLiteral("A= rgument needs to be an object")); -// return settings; -// } -// QJSValue object =3D context->argument(0); -// QJSValue windowProperty =3D object.property(QStringLiteral("window")= ); -// if (!windowProperty.isValid() || !windowProperty.isObject()) { +QList animationSettings(const QJSValue& object EffectWi= ndow **window) +{ + QList settings; + QJSValue windowProperty =3D object.property(QStringLiteral("window")); + if (!windowProperty.isValid() || !windowProperty.isObject()) { // context->throwError(QScriptContext::TypeError, QStringLiteral("W= indow property missing in animation options")); -// return settings; -// } -// *window =3D qobject_cast(windowProperty.toQObject()); - -// settings << animationSettingsFromObject(object); // global - -// QJSValue animations =3D object.property(QStringLiteral("animations")= ); // array -// if (!animations.isNull()) { -// if (!animations.isArray()) { -// context->throwError(QScriptContext::TypeError, QStringLitera= l("Animations provided but not an array")); -// settings.clear(); -// return settings; -// } -// const int length =3D static_cast(animations.property(QStrin= gLiteral("length")).toInteger()); -// for (int i=3D0; ithrowError(QScriptContext::TypeError, QStri= ngLiteral("Type property missing in animation options")); -// continue; -// } -// if (!(set & AnimationSettings::Duration)) { -// context->throwError(QScriptContext::TypeError, QStri= ngLiteral("Duration property missing in animation options")); -// continue; -// } -// // Complete local animations from global settings -// if (!(s.set & AnimationSettings::Duration)) { -// s.duration =3D settings.at(0).duration; -// } -// if (!(s.set & AnimationSettings::Curve)) { -// s.curve =3D settings.at(0).curve; -// } -// if (!(s.set & AnimationSettings::Delay)) { -// s.delay =3D settings.at(0).delay; -// } - -// s.metaData =3D 0; -// typedef QMap MetaTyp= eMap; -// static MetaTypeMap metaTypes({ -// {AnimationEffect::SourceAnchor, QStringLiteral("sour= ceAnchor")}, -// {AnimationEffect::TargetAnchor, QStringLiteral("targ= etAnchor")}, -// {AnimationEffect::RelativeSourceX, QStringLiteral("r= elativeSourceX")}, -// {AnimationEffect::RelativeSourceY, QStringLiteral("r= elativeSourceY")}, -// {AnimationEffect::RelativeTargetX, QStringLiteral("r= elativeTargetX")}, -// {AnimationEffect::RelativeTargetY, QStringLiteral("r= elativeTargetY")}, -// {AnimationEffect::Axis, QStringLiteral("axis")} -// }); - -// for (MetaTypeMap::const_iterator it =3D metaTypes.constB= egin(), -// end =3D metaTypes.constE= nd(); it !=3D end; ++it) { -// QJSValue metaVal =3D value.property(*it); -// if (metaVal.isNumber()) { -// AnimationEffect::setMetaData(it.key(), metaVal.t= oInt(), s.metaData); -// } -// } - -// settings << s; -// } -// } -// } - -// if (settings.count() =3D=3D 1) { -// const uint set =3D settings.at(0).set; -// if (!(set & AnimationSettings::Type)) { -// context->throwError(QScriptContext::TypeError, QStringLitera= l("Type property missing in animation options")); -// settings.clear(); -// } -// if (!(set & AnimationSettings::Duration)) { -// context->throwError(QScriptContext::TypeError, QStringLitera= l("Duration property missing in animation options")); -// settings.clear(); -// } -// } else if (!(settings.at(0).set & AnimationSettings::Type)) { // inv= alid global -// settings.removeAt(0); // -> get rid of it, only used to complete= the others -// } - -// return settings; -//} + return settings; + } + *window =3D qobject_cast(windowProperty.toQObject()); + + settings << animationSettingsFromObject(object); // global + + QJSValue animations =3D 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 =3D static_cast(animations.property(QStringLi= teral("length")).toInteger()); + for (int i=3D0; ithrowError(QScriptContext::TypeError, QStringL= iteral("Type property missing in animation options")); + continue; + } + if (!(set & AnimationSettings::Duration)) { + context->throwError(QScriptContext::TypeError, QStringL= iteral("Duration property missing in animation options")); + continue; + } + // Complete local animations from global settings + if (!(s.set & AnimationSettings::Duration)) { + s.duration =3D settings.at(0).duration; + } + if (!(s.set & AnimationSettings::Curve)) { + s.curve =3D settings.at(0).curve; + } + if (!(s.set & AnimationSettings::Delay)) { + s.delay =3D settings.at(0).delay; + } + + s.metaData =3D 0; + typedef QMap MetaTypeMa= p; + static MetaTypeMap metaTypes({ + {AnimationEffect::SourceAnchor, QStringLiteral("sourceA= nchor")}, + {AnimationEffect::TargetAnchor, QStringLiteral("targetA= nchor")}, + {AnimationEffect::RelativeSourceX, QStringLiteral("rela= tiveSourceX")}, + {AnimationEffect::RelativeSourceY, QStringLiteral("rela= tiveSourceY")}, + {AnimationEffect::RelativeTargetX, QStringLiteral("rela= tiveTargetX")}, + {AnimationEffect::RelativeTargetY, QStringLiteral("rela= tiveTargetY")}, + {AnimationEffect::Axis, QStringLiteral("axis")} + }); + + for (MetaTypeMap::const_iterator it =3D metaTypes.constBegi= n(), + end =3D metaTypes.constEnd(= ); it !=3D end; ++it) { + QJSValue metaVal =3D value.property(*it); + if (metaVal.isNumber()) { + AnimationEffect::setMetaData(it.key(), metaVal.toIn= t(), s.metaData); + } + } + + settings << s; + } + } + } + + if (settings.count() =3D=3D 1) { + const uint set =3D 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)) { // invali= d global + settings.removeAt(0); // -> get rid of it, only used to complete th= e others + } + + return settings; +} = QJSValue kwinEffectAnimate(QScriptContext *context, QJSEngine *engine) { @@ -415,19 +402,13 @@ 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= ("animateInternal")); -// engine()->globalObject().setProperty("set", selfWrapper.property("s= etInternal")); + engine()->globalObject().setProperty("animate", selfWrapper.property("= animateGlobal")); + engine()->globalObject().setProperty("set", selfWrapper.property("setG= lobal")); engine()->globalObject().setProperty("retarget", selfWrapper.property(= "retarget")); engine()->globalObject().setProperty("cancel", selfWrapper.property("c= ancel")); = engine()->globalObject().setProperty("print", selfWrapper.property("pr= int")); = - -// MetaScripting::registration(m_engine); -// qScriptRegisterMetaType(m_engine, fpx2ToScriptValue, fpx= 2FromScriptValue); -// qScriptRegisterSequenceMetaType >(m_eng= ine); - - QJSValue ret =3D m_engine->evaluate(QString::fromUtf8(scriptFile.readA= ll())); = if (ret.isError()) { @@ -522,6 +503,20 @@ bool ScriptedEffect::retarget(QList animation= Ids, const QJSValue &newTa return true; } = +QJSValue ScriptedEffect::animateGlobal(const QJSValue &args) +{ + return startAnimation(args, false); +} + +QJSValue ScriptedEffect::setGlobal(const QJSValue &args) +{ + return startAnimation(args, true); +} + +QJSValue startAnimation(const QJSValue &value, bool set) +{ +} + bool ScriptedEffect::cancel(quint64 animationId) { return AnimationEffect::cancel(animationId); diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h index eca4d61ed..a56ca6794 100644 --- a/scripting/scriptedeffect.h +++ b/scripting/scriptedeffect.h @@ -115,8 +115,10 @@ public Q_SLOTS: bool cancel(quint64 animationId); bool cancel(QList animationIds); = -// QJSValue animateInternal(const QJSValue &args) {} -// QJSValue setInternal(const QJSValue &args) {} + //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); = bool borderActivated(ElectricBorder border) override; = @@ -134,6 +136,8 @@ protected: void animationEnded(KWin::EffectWindow *w, Attribute a, uint meta); = private: + //wrapper round animateGlobal/setGlobal that parses the animations blo= b. + QJSValue startAnimation(const QJSValue &value, bool set); QJSEngine *m_engine; QString m_effectName; QString m_scriptFile;