Changeset View
Changeset View
Standalone View
Standalone View
scripting/scriptedeffect.cpp
Show First 20 Lines • Show All 432 Lines • ▼ Show 20 Line(s) | 431 | foreach (const quint64 &animId, animIds) { | |||
---|---|---|---|---|---|
433 | if (!ok) { | 433 | if (!ok) { | ||
434 | break; | 434 | break; | ||
435 | } | 435 | } | ||
436 | } | 436 | } | ||
437 | 437 | | |||
438 | return QScriptValue(ok); | 438 | return QScriptValue(ok); | ||
439 | } | 439 | } | ||
440 | 440 | | |||
441 | QScriptValue kwinEffectRedirect(QScriptContext *context, QScriptEngine *engine) | ||||
442 | { | ||||
443 | if (context->argumentCount() != 2 && context->argumentCount() != 3) { | ||||
444 | const QString errorMessage = QStringLiteral("redirect() takes either 2 or 3 arguments (%1 given)") | ||||
445 | .arg(context->argumentCount()); | ||||
446 | context->throwError(QScriptContext::SyntaxError, errorMessage); | ||||
447 | return engine->undefinedValue(); | ||||
448 | } | ||||
449 | | ||||
450 | bool ok = false; | ||||
451 | QList<quint64> animationIds = animations(context->argument(0).toVariant(), &ok); | ||||
452 | if (!ok) { | ||||
453 | context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); | ||||
454 | return engine->undefinedValue(); | ||||
455 | } | ||||
456 | | ||||
457 | const QScriptValue wrappedDirection = context->argument(1); | ||||
458 | if (!wrappedDirection.isNumber()) { | ||||
459 | context->throwError(QScriptContext::TypeError, QStringLiteral("Direction has invalid type")); | ||||
460 | return engine->undefinedValue(); | ||||
461 | } | ||||
462 | | ||||
463 | const auto direction = static_cast<AnimationEffect::Direction>(wrappedDirection.toInt32()); | ||||
464 | switch (direction) { | ||||
465 | case AnimationEffect::Forward: | ||||
466 | case AnimationEffect::Backward: | ||||
467 | break; | ||||
468 | | ||||
469 | default: | ||||
470 | context->throwError(QScriptContext::SyntaxError, QStringLiteral("Unknown direction")); | ||||
471 | return engine->undefinedValue(); | ||||
472 | } | ||||
473 | | ||||
474 | AnimationEffect::TerminationFlags terminationFlags = AnimationEffect::TerminateAtSource; | ||||
475 | if (context->argumentCount() >= 3) { | ||||
476 | const QScriptValue wrappedTerminationFlags = context->argument(2); | ||||
477 | if (!wrappedTerminationFlags.isNumber()) { | ||||
478 | context->throwError(QScriptContext::TypeError, QStringLiteral("Termination flags argument has invalid type")); | ||||
479 | return engine->undefinedValue(); | ||||
480 | } | ||||
481 | | ||||
482 | terminationFlags = static_cast<AnimationEffect::TerminationFlags>(wrappedTerminationFlags.toInt32()); | ||||
483 | } | ||||
484 | | ||||
485 | ScriptedEffect *effect = qobject_cast<ScriptedEffect *>(context->callee().data().toQObject()); | ||||
486 | for (const quint64 &animationId : qAsConst(animationIds)) { | ||||
487 | if (!effect->redirect(animationId, direction, terminationFlags)) { | ||||
488 | return QScriptValue(false); | ||||
489 | } | ||||
490 | } | ||||
491 | | ||||
492 | return QScriptValue(true); | ||||
493 | } | ||||
494 | | ||||
441 | QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) | 495 | QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) | ||
442 | { | 496 | { | ||
443 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | 497 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | ||
444 | if (context->argumentCount() != 1) { | 498 | if (context->argumentCount() != 1) { | ||
445 | context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); | 499 | context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); | ||
446 | return engine->undefinedValue(); | 500 | return engine->undefinedValue(); | ||
447 | } | 501 | } | ||
448 | QVariant v = context->argument(0).toVariant(); | 502 | QVariant v = context->argument(0).toVariant(); | ||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Line(s) | 609 | #endif | |||
587 | setFunc.setData(m_engine->newQObject(this)); | 641 | setFunc.setData(m_engine->newQObject(this)); | ||
588 | m_engine->globalObject().setProperty(QStringLiteral("set"), setFunc); | 642 | m_engine->globalObject().setProperty(QStringLiteral("set"), setFunc); | ||
589 | 643 | | |||
590 | // retarget | 644 | // retarget | ||
591 | QScriptValue retargetFunc = m_engine->newFunction(kwinEffectRetarget); | 645 | QScriptValue retargetFunc = m_engine->newFunction(kwinEffectRetarget); | ||
592 | retargetFunc.setData(m_engine->newQObject(this)); | 646 | retargetFunc.setData(m_engine->newQObject(this)); | ||
593 | m_engine->globalObject().setProperty(QStringLiteral("retarget"), retargetFunc); | 647 | m_engine->globalObject().setProperty(QStringLiteral("retarget"), retargetFunc); | ||
594 | 648 | | |||
649 | // redirect | ||||
650 | QScriptValue redirectFunc = m_engine->newFunction(kwinEffectRedirect); | ||||
651 | redirectFunc.setData(m_engine->newQObject(this)); | ||||
652 | m_engine->globalObject().setProperty(QStringLiteral("redirect"), redirectFunc); | ||||
653 | | ||||
595 | // cancel... | 654 | // cancel... | ||
596 | QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel); | 655 | QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel); | ||
597 | cancelFunc.setData(m_engine->newQObject(this)); | 656 | cancelFunc.setData(m_engine->newQObject(this)); | ||
598 | m_engine->globalObject().setProperty(QStringLiteral("cancel"), cancelFunc); | 657 | m_engine->globalObject().setProperty(QStringLiteral("cancel"), cancelFunc); | ||
599 | 658 | | |||
600 | QScriptValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll())); | 659 | QScriptValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll())); | ||
601 | 660 | | |||
602 | if (ret.isError()) { | 661 | if (ret.isError()) { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 705 | { | |||
652 | return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from, fullScreen, keepAlive); | 711 | return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from, fullScreen, keepAlive); | ||
653 | } | 712 | } | ||
654 | 713 | | |||
655 | bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) | 714 | bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) | ||
656 | { | 715 | { | ||
657 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | 716 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | ||
658 | } | 717 | } | ||
659 | 718 | | |||
719 | bool ScriptedEffect::redirect(quint64 animationId, Direction direction, TerminationFlags terminationFlags) | ||||
720 | { | ||||
721 | return AnimationEffect::redirect(animationId, direction, terminationFlags); | ||||
722 | } | ||||
723 | | ||||
660 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | 724 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | ||
661 | { | 725 | { | ||
662 | void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>(); | 726 | void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>(); | ||
663 | if (e) { | 727 | if (e) { | ||
664 | return e != this; | 728 | return e != this; | ||
665 | } else { | 729 | } else { | ||
666 | return false; | 730 | return false; | ||
667 | } | 731 | } | ||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |