diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp index 2d6537fe08..0165d1b1c6 100644 --- a/scripting/scriptedeffect.cpp +++ b/scripting/scriptedeffect.cpp @@ -308,53 +308,27 @@ QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine) return engine->newVariant(animIds); } -QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) +QList animations(const QVariant &v, bool *ok) { - ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); - if (context->argumentCount() != 1) { - context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); - return engine->undefinedValue(); - } - QVariant v = context->argument(0).toVariant(); QList animIds; - bool ok = false; + *ok = false; if (v.isValid()) { - quint64 animId = v.toULongLong(&ok); - if (ok) + quint64 animId = v.toULongLong(ok); + if (*ok) animIds << animId; } - if (!ok) { // may still be a variantlist of variants being quint64 + if (!*ok) { // may still be a variantlist of variants being quint64 QList list = v.toList(); if (!list.isEmpty()) { foreach (const QVariant &vv, list) { - quint64 animId = vv.toULongLong(&ok); - if (ok) + quint64 animId = vv.toULongLong(ok); + if (*ok) animIds << animId; } - ok = !animIds.isEmpty(); + *ok = !animIds.isEmpty(); } } - if (!ok) { - context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); - return engine->undefinedValue(); - } - - foreach (const quint64 &animId, animIds) { - ok |= engine->newVariant(effect->cancel(animId)).toBool(); - } - - return engine->newVariant(ok); -} - -QScriptValue effectWindowToScriptValue(QScriptEngine *eng, const KEffectWindowRef &window) -{ - return eng->newQObject(window, QScriptEngine::QtOwnership, - QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject); -} - -void effectWindowFromScriptValue(const QScriptValue &value, EffectWindow* &window) -{ - window = qobject_cast(value.toQObject()); + return animIds; } QScriptValue fpx2ToScriptValue(QScriptEngine *eng, const KWin::FPx2 &fpx2) @@ -387,6 +361,63 @@ void fpx2FromScriptValue(const QScriptValue &value, KWin::FPx2 &fpx2) } } +QScriptValue kwinEffectRetarget(QScriptContext *context, QScriptEngine *engine) +{ + ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); + if (context->argumentCount() < 2 || context->argumentCount() > 3) { + context->throwError(QScriptContext::SyntaxError, QStringLiteral("2 or 3 arguments expected")); + return engine->undefinedValue(); + } + QVariant v = context->argument(0).toVariant(); + bool ok = false; + QList animIds = animations(v, &ok); + if (!ok) { + context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); + return engine->undefinedValue(); + } + FPx2 target; + fpx2FromScriptValue(context->argument(1), target); + + const int remainingTime = context->argumentCount() == 2 ? context->argument(1).toVariant().toInt() : -1; + foreach (const quint64 &animId, animIds) { + ok |= engine->newVariant(effect->retarget(animId, target, remainingTime)).toBool(); + } + + return engine->newVariant(ok); +} + +QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) +{ + ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); + if (context->argumentCount() != 1) { + context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); + return engine->undefinedValue(); + } + QVariant v = context->argument(0).toVariant(); + bool ok = false; + QList animIds = animations(v, &ok); + if (!ok) { + context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); + return engine->undefinedValue(); + } + foreach (const quint64 &animId, animIds) { + ok |= engine->newVariant(effect->cancel(animId)).toBool(); + } + + return engine->newVariant(ok); +} + +QScriptValue effectWindowToScriptValue(QScriptEngine *eng, const KEffectWindowRef &window) +{ + return eng->newQObject(window, QScriptEngine::QtOwnership, + QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject); +} + +void effectWindowFromScriptValue(const QScriptValue &value, EffectWindow* &window) +{ + window = qobject_cast(value.toQObject()); +} + ScriptedEffect *ScriptedEffect::create(const KPluginMetaData &effect) { const QString name = effect.pluginId(); @@ -486,6 +517,11 @@ bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript setFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("set"), setFunc); + // retarget + QScriptValue retargetFunc = m_engine->newFunction(kwinEffectRetarget); + retargetFunc.setData(m_engine->newQObject(this)); + m_engine->globalObject().setProperty(QStringLiteral("retarget"), retargetFunc); + // cancel... QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel); cancelFunc.setData(m_engine->newQObject(this)); @@ -541,6 +577,11 @@ quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attrib return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from); } +bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) +{ + return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); +} + bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) { void *e = w->data(static_cast(grabRole)).value(); diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h index 2a77a2f302..589943c1bc 100644 --- a/scripting/scriptedeffect.h +++ b/scripting/scriptedeffect.h @@ -93,6 +93,7 @@ public: 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); } virtual bool borderActivated(ElectricBorder border);