Changeset View
Changeset View
Standalone View
Standalone View
scripting/scriptedeffect.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
98 | } | 98 | } | ||
99 | 99 | | |||
100 | QScriptValue kwinUnregisterTouchScreenEdge(QScriptContext *context, QScriptEngine *engine) | 100 | QScriptValue kwinUnregisterTouchScreenEdge(QScriptContext *context, QScriptEngine *engine) | ||
101 | { | 101 | { | ||
102 | return unregisterTouchScreenEdge<KWin::ScriptedEffect*>(context, engine); | 102 | return unregisterTouchScreenEdge<KWin::ScriptedEffect*>(context, engine); | ||
103 | } | 103 | } | ||
104 | 104 | | |||
105 | struct AnimationSettings { | 105 | struct AnimationSettings { | ||
106 | enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3 }; | 106 | enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3, FullScreen = 1<<4 }; | ||
107 | AnimationEffect::Attribute type; | 107 | AnimationEffect::Attribute type; | ||
108 | QEasingCurve::Type curve; | 108 | QEasingCurve::Type curve; | ||
109 | FPx2 from; | 109 | FPx2 from; | ||
110 | FPx2 to; | 110 | FPx2 to; | ||
111 | int delay; | 111 | int delay; | ||
112 | uint duration; | 112 | uint duration; | ||
113 | uint set; | 113 | uint set; | ||
114 | uint metaData; | 114 | uint metaData; | ||
115 | bool fullScreenEffect; | ||||
115 | }; | 116 | }; | ||
116 | 117 | | |||
117 | AnimationSettings animationSettingsFromObject(QScriptValue &object) | 118 | AnimationSettings animationSettingsFromObject(QScriptValue &object) | ||
118 | { | 119 | { | ||
119 | AnimationSettings settings; | 120 | AnimationSettings settings; | ||
120 | settings.set = 0; | 121 | settings.set = 0; | ||
121 | settings.metaData = 0; | 122 | settings.metaData = 0; | ||
122 | 123 | | |||
Show All 27 Lines | |||||
150 | QScriptValue type = object.property(QStringLiteral("type")); | 151 | QScriptValue type = object.property(QStringLiteral("type")); | ||
151 | if (type.isValid() && type.isNumber()) { | 152 | if (type.isValid() && type.isNumber()) { | ||
152 | settings.type = static_cast<AnimationEffect::Attribute>(type.toInt32()); | 153 | settings.type = static_cast<AnimationEffect::Attribute>(type.toInt32()); | ||
153 | settings.set |= AnimationSettings::Type; | 154 | settings.set |= AnimationSettings::Type; | ||
154 | } else { | 155 | } else { | ||
155 | settings.type = static_cast<AnimationEffect::Attribute>(-1); | 156 | settings.type = static_cast<AnimationEffect::Attribute>(-1); | ||
156 | } | 157 | } | ||
157 | 158 | | |||
159 | QScriptValue isFullScreen = object.property(QStringLiteral("fullScreen")); | ||||
zzag: I think it would be better to capitalize 'screen', so it's consistent with the rest of api… | |||||
zzag: Can be const. | |||||
160 | if (isFullScreen.isValid() && isFullScreen.isBool()) { | ||||
161 | settings.fullScreenEffect = isFullScreen.toBool(); | ||||
162 | settings.set |= AnimationSettings::FullScreen; | ||||
163 | } else { | ||||
164 | settings.fullScreenEffect = false; | ||||
165 | } | ||||
166 | | ||||
158 | return settings; | 167 | return settings; | ||
159 | } | 168 | } | ||
160 | 169 | | |||
161 | QList<AnimationSettings> animationSettings(QScriptContext *context, ScriptedEffect *effect, EffectWindow **window) | 170 | QList<AnimationSettings> animationSettings(QScriptContext *context, ScriptedEffect *effect, EffectWindow **window) | ||
162 | { | 171 | { | ||
163 | QList<AnimationSettings> settings; | 172 | QList<AnimationSettings> settings; | ||
164 | if (!effect) { | 173 | if (!effect) { | ||
165 | context->throwError(QScriptContext::ReferenceError, QStringLiteral("Internal Scripted KWin Effect error")); | 174 | context->throwError(QScriptContext::ReferenceError, QStringLiteral("Internal Scripted KWin Effect error")); | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 274 | { | |||
280 | foreach (const AnimationSettings &setting, settings) { | 289 | foreach (const AnimationSettings &setting, settings) { | ||
281 | array.setProperty(i, (uint)effect->animate(window, | 290 | array.setProperty(i, (uint)effect->animate(window, | ||
282 | setting.type, | 291 | setting.type, | ||
283 | setting.duration, | 292 | setting.duration, | ||
284 | setting.to, | 293 | setting.to, | ||
285 | setting.from, | 294 | setting.from, | ||
286 | setting.metaData, | 295 | setting.metaData, | ||
287 | setting.curve, | 296 | setting.curve, | ||
288 | setting.delay)); | 297 | setting.delay, | ||
298 | setting.fullScreenEffect)); | ||||
289 | ++i; | 299 | ++i; | ||
290 | } | 300 | } | ||
291 | return array; | 301 | return array; | ||
292 | } | 302 | } | ||
293 | 303 | | |||
294 | QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine) | 304 | QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine) | ||
295 | { | 305 | { | ||
296 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | 306 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | ||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Line(s) | |||||
470 | 480 | | |||
471 | ScriptedEffect::ScriptedEffect() | 481 | ScriptedEffect::ScriptedEffect() | ||
472 | : AnimationEffect() | 482 | : AnimationEffect() | ||
473 | , m_engine(new QScriptEngine(this)) | 483 | , m_engine(new QScriptEngine(this)) | ||
474 | , m_scriptFile(QString()) | 484 | , m_scriptFile(QString()) | ||
475 | , m_config(nullptr) | 485 | , m_config(nullptr) | ||
476 | , m_chainPosition(0) | 486 | , m_chainPosition(0) | ||
477 | { | 487 | { | ||
488 | Q_ASSERT(effects); | ||||
478 | connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue))); | 489 | connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue))); | ||
490 | connect(effects, &EffectsHandler::activeFullScreenEffectChanged, this, [this]() { | ||||
491 | Effect* fullScreenEffect = effects->activeFullScreenEffect(); | ||||
492 | if (fullScreenEffect == m_activeFullScreenEffect) { | ||||
493 | return; | ||||
494 | } | ||||
495 | if (m_activeFullScreenEffect == this || fullScreenEffect == this) { | ||||
496 | emit isActiveFullScreenEffectChanged(); | ||||
497 | } | ||||
498 | m_activeFullScreenEffect = fullScreenEffect; | ||||
499 | }); | ||||
479 | } | 500 | } | ||
480 | 501 | | |||
481 | ScriptedEffect::~ScriptedEffect() | 502 | ScriptedEffect::~ScriptedEffect() | ||
482 | { | 503 | { | ||
483 | } | 504 | } | ||
484 | 505 | | |||
485 | bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript) | 506 | bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript) | ||
486 | { | 507 | { | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | |||||
562 | } | 583 | } | ||
563 | 584 | | |||
564 | void ScriptedEffect::animationEnded(KWin::EffectWindow *w, Attribute a, uint meta) | 585 | void ScriptedEffect::animationEnded(KWin::EffectWindow *w, Attribute a, uint meta) | ||
565 | { | 586 | { | ||
566 | AnimationEffect::animationEnded(w, a, meta); | 587 | AnimationEffect::animationEnded(w, a, meta); | ||
567 | emit animationEnded(w, 0); | 588 | emit animationEnded(w, 0); | ||
568 | } | 589 | } | ||
569 | 590 | | |||
591 | bool ScriptedEffect::isActiveFullScreenEffect() const | ||||
592 | { | ||||
593 | return effects->activeFullScreenEffect() == this; | ||||
594 | } | ||||
595 | | ||||
570 | void ScriptedEffect::signalHandlerException(const QScriptValue &value) | 596 | void ScriptedEffect::signalHandlerException(const QScriptValue &value) | ||
571 | { | 597 | { | ||
572 | if (value.isError()) { | 598 | if (value.isError()) { | ||
573 | qCDebug(KWIN_SCRIPTING) << "KWin Effect script encountered an error at [Line " << m_engine->uncaughtExceptionLineNumber() << "]"; | 599 | qCDebug(KWIN_SCRIPTING) << "KWin Effect script encountered an error at [Line " << m_engine->uncaughtExceptionLineNumber() << "]"; | ||
574 | qCDebug(KWIN_SCRIPTING) << "Message: " << value.toString(); | 600 | qCDebug(KWIN_SCRIPTING) << "Message: " << value.toString(); | ||
575 | 601 | | |||
576 | QScriptValueIterator iter(value); | 602 | QScriptValueIterator iter(value); | ||
577 | while (iter.hasNext()) { | 603 | while (iter.hasNext()) { | ||
578 | iter.next(); | 604 | iter.next(); | ||
579 | qCDebug(KWIN_SCRIPTING) << " " << iter.name() << ": " << iter.value().toString(); | 605 | qCDebug(KWIN_SCRIPTING) << " " << iter.name() << ": " << iter.value().toString(); | ||
580 | } | 606 | } | ||
581 | } | 607 | } | ||
582 | } | 608 | } | ||
583 | 609 | | |||
584 | quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, int curve, int delay) | 610 | quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, int curve, int delay, bool fullScreen) | ||
585 | { | 611 | { | ||
586 | QEasingCurve qec; | 612 | QEasingCurve qec; | ||
587 | if (curve < QEasingCurve::Custom) | 613 | if (curve < QEasingCurve::Custom) | ||
588 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | 614 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | ||
589 | else if (curve == GaussianCurve) | 615 | else if (curve == GaussianCurve) | ||
590 | qec.setCustomType(qecGaussian); | 616 | qec.setCustomType(qecGaussian); | ||
591 | return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, from); | 617 | return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, from, fullScreen); | ||
592 | } | 618 | } | ||
593 | 619 | | |||
594 | quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, int curve, int delay) | 620 | quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, int curve, int delay, bool fullScreen) | ||
595 | { | 621 | { | ||
596 | QEasingCurve qec; | 622 | QEasingCurve qec; | ||
597 | if (curve < QEasingCurve::Custom) | 623 | if (curve < QEasingCurve::Custom) | ||
598 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | 624 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | ||
599 | else if (curve == GaussianCurve) | 625 | else if (curve == GaussianCurve) | ||
600 | qec.setCustomType(qecGaussian); | 626 | qec.setCustomType(qecGaussian); | ||
601 | return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from); | 627 | return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from, fullScreen); | ||
602 | } | 628 | } | ||
603 | 629 | | |||
604 | bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) | 630 | bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) | ||
That's unreachable code. We would hit this code if a compiler has bugs. :-) Also, I think we don't need else because of proceeding return. zzag: That's unreachable code. We would hit this code if a compiler has bugs. :-)
Also, I think we… | |||||
Sure, else or not compiles to the same thing. IMHO this makes it easier to tell the next reader what's going on when you have valid either one or the other situations; but in this case it's only one line so I don't really care. davidedmundson: Sure, else or not compiles to the same thing.
(one jump statement that isn't reachable and… | |||||
605 | { | 631 | { | ||
606 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | 632 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | ||
607 | } | 633 | } | ||
608 | 634 | | |||
609 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | 635 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | ||
610 | { | 636 | { | ||
611 | void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>(); | 637 | void *e = w->data(static_cast<KWin::DataRole>(grabRole)).value<void*>(); | ||
612 | if (e) { | 638 | if (e) { | ||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |
I think it would be better to capitalize 'screen', so it's consistent with the rest of api: