Changeset View
Changeset View
Standalone View
Standalone View
scripting/scriptedeffect.cpp
Show First 20 Lines • Show All 495 Lines • ▼ Show 20 Line(s) | 495 | for (const quint64 &animationId : qAsConst(animationIds)) { | |||
---|---|---|---|---|---|
496 | if (!effect->redirect(animationId, direction, terminationPolicy)) { | 496 | if (!effect->redirect(animationId, direction, terminationPolicy)) { | ||
497 | return QScriptValue(false); | 497 | return QScriptValue(false); | ||
498 | } | 498 | } | ||
499 | } | 499 | } | ||
500 | 500 | | |||
501 | return QScriptValue(true); | 501 | return QScriptValue(true); | ||
502 | } | 502 | } | ||
503 | 503 | | |||
504 | QScriptValue kwinEffectComplete(QScriptContext *context, QScriptEngine *engine) | ||||
505 | { | ||||
506 | if (context->argumentCount() != 1) { | ||||
507 | const QString errorMessage = QStringLiteral("complete() takes exactly 1 arguments (%1 given)") | ||||
508 | .arg(context->argumentCount()); | ||||
509 | context->throwError(QScriptContext::SyntaxError, errorMessage); | ||||
510 | return engine->undefinedValue(); | ||||
511 | } | ||||
512 | | ||||
513 | bool ok = false; | ||||
514 | QList<quint64> animationIds = animations(context->argument(0).toVariant(), &ok); | ||||
515 | if (!ok) { | ||||
516 | context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); | ||||
517 | return engine->undefinedValue(); | ||||
518 | } | ||||
519 | | ||||
520 | ScriptedEffect *effect = qobject_cast<ScriptedEffect *>(context->callee().data().toQObject()); | ||||
521 | for (const quint64 &animationId : qAsConst(animationIds)) { | ||||
522 | if (!effect->complete(animationId)) { | ||||
523 | return QScriptValue(false); | ||||
davidedmundson: There's a minor behavioural difference compared to cancel/retarget.
They return false if… | |||||
Won't QList<quint64> animations(const QVariant &v, bool *ok) take care of that? zzag: Won't QList<quint64> animations(const QVariant &v, bool *ok) take care of that? | |||||
davidedmundson: Oh, it does.
(though my QQmlEngine port drops that function)
| |||||
524 | } | ||||
525 | } | ||||
526 | | ||||
527 | return QScriptValue(true); | ||||
528 | } | ||||
529 | | ||||
504 | QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) | 530 | QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) | ||
505 | { | 531 | { | ||
506 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | 532 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | ||
507 | if (context->argumentCount() != 1) { | 533 | if (context->argumentCount() != 1) { | ||
508 | context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); | 534 | context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); | ||
509 | return engine->undefinedValue(); | 535 | return engine->undefinedValue(); | ||
510 | } | 536 | } | ||
511 | QVariant v = context->argument(0).toVariant(); | 537 | QVariant v = context->argument(0).toVariant(); | ||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Line(s) | 644 | #endif | |||
655 | retargetFunc.setData(m_engine->newQObject(this)); | 681 | retargetFunc.setData(m_engine->newQObject(this)); | ||
656 | m_engine->globalObject().setProperty(QStringLiteral("retarget"), retargetFunc); | 682 | m_engine->globalObject().setProperty(QStringLiteral("retarget"), retargetFunc); | ||
657 | 683 | | |||
658 | // redirect | 684 | // redirect | ||
659 | QScriptValue redirectFunc = m_engine->newFunction(kwinEffectRedirect); | 685 | QScriptValue redirectFunc = m_engine->newFunction(kwinEffectRedirect); | ||
660 | redirectFunc.setData(m_engine->newQObject(this)); | 686 | redirectFunc.setData(m_engine->newQObject(this)); | ||
661 | m_engine->globalObject().setProperty(QStringLiteral("redirect"), redirectFunc); | 687 | m_engine->globalObject().setProperty(QStringLiteral("redirect"), redirectFunc); | ||
662 | 688 | | |||
689 | // complete | ||||
690 | QScriptValue completeFunc = m_engine->newFunction(kwinEffectComplete); | ||||
691 | completeFunc.setData(m_engine->newQObject(this)); | ||||
692 | m_engine->globalObject().setProperty(QStringLiteral("complete"), completeFunc); | ||||
693 | | ||||
663 | // cancel... | 694 | // cancel... | ||
664 | QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel); | 695 | QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel); | ||
665 | cancelFunc.setData(m_engine->newQObject(this)); | 696 | cancelFunc.setData(m_engine->newQObject(this)); | ||
666 | m_engine->globalObject().setProperty(QStringLiteral("cancel"), cancelFunc); | 697 | m_engine->globalObject().setProperty(QStringLiteral("cancel"), cancelFunc); | ||
667 | 698 | | |||
668 | QScriptValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll())); | 699 | QScriptValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll())); | ||
669 | 700 | | |||
670 | if (ret.isError()) { | 701 | if (ret.isError()) { | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 755 | { | |||
725 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | 756 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | ||
726 | } | 757 | } | ||
727 | 758 | | |||
728 | bool ScriptedEffect::redirect(quint64 animationId, Direction direction, TerminationPolicy terminationPolicy) | 759 | bool ScriptedEffect::redirect(quint64 animationId, Direction direction, TerminationPolicy terminationPolicy) | ||
729 | { | 760 | { | ||
730 | return AnimationEffect::redirect(animationId, direction, terminationPolicy); | 761 | return AnimationEffect::redirect(animationId, direction, terminationPolicy); | ||
731 | } | 762 | } | ||
732 | 763 | | |||
764 | bool ScriptedEffect::complete(quint64 animationId) | ||||
765 | { | ||||
766 | return AnimationEffect::complete(animationId); | ||||
767 | } | ||||
768 | | ||||
733 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | 769 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | ||
734 | { | 770 | { | ||
735 | void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>(); | 771 | void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>(); | ||
736 | if (e) { | 772 | if (e) { | ||
737 | return e != this; | 773 | return e != this; | ||
738 | } else { | 774 | } else { | ||
739 | return false; | 775 | return false; | ||
740 | } | 776 | } | ||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
There's a minor behavioural difference compared to cancel/retarget.
They return false if animationIds is empty, you return true
(same comment for redirect)
Not a huge issue, but probably worth being consistent.