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, KeepAlive = 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 keepAlive; | ||||
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 keepAlive = object.property(QStringLiteral("keepAlive")); | ||||
160 | if (keepAlive.isValid() && keepAlive.isBool()) { | ||||
161 | settings.keepAlive = keepAlive.toBool(); | ||||
162 | settings.set |= AnimationSettings::KeepAlive; | ||||
163 | } else { | ||||
164 | settings.keepAlive = true; | ||||
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 47 Lines • ▼ Show 20 Line(s) | 221 | if (!(s.set & AnimationSettings::Duration)) { | |||
213 | s.duration = settings.at(0).duration; | 222 | s.duration = settings.at(0).duration; | ||
214 | } | 223 | } | ||
215 | if (!(s.set & AnimationSettings::Curve)) { | 224 | if (!(s.set & AnimationSettings::Curve)) { | ||
216 | s.curve = settings.at(0).curve; | 225 | s.curve = settings.at(0).curve; | ||
217 | } | 226 | } | ||
218 | if (!(s.set & AnimationSettings::Delay)) { | 227 | if (!(s.set & AnimationSettings::Delay)) { | ||
219 | s.delay = settings.at(0).delay; | 228 | s.delay = settings.at(0).delay; | ||
220 | } | 229 | } | ||
230 | if (!(s.set & AnimationSettings::KeepAlive)) { | ||||
231 | s.keepAlive = settings.at(0).keepAlive; | ||||
232 | } | ||||
221 | 233 | | |||
222 | s.metaData = 0; | 234 | s.metaData = 0; | ||
223 | typedef QMap<AnimationEffect::MetaType, QString> MetaTypeMap; | 235 | typedef QMap<AnimationEffect::MetaType, QString> MetaTypeMap; | ||
224 | static MetaTypeMap metaTypes({ | 236 | static MetaTypeMap metaTypes({ | ||
225 | {AnimationEffect::SourceAnchor, QStringLiteral("sourceAnchor")}, | 237 | {AnimationEffect::SourceAnchor, QStringLiteral("sourceAnchor")}, | ||
226 | {AnimationEffect::TargetAnchor, QStringLiteral("targetAnchor")}, | 238 | {AnimationEffect::TargetAnchor, QStringLiteral("targetAnchor")}, | ||
227 | {AnimationEffect::RelativeSourceX, QStringLiteral("relativeSourceX")}, | 239 | {AnimationEffect::RelativeSourceX, QStringLiteral("relativeSourceX")}, | ||
228 | {AnimationEffect::RelativeSourceY, QStringLiteral("relativeSourceY")}, | 240 | {AnimationEffect::RelativeSourceY, QStringLiteral("relativeSourceY")}, | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 277 | { | |||
280 | foreach (const AnimationSettings &setting, settings) { | 292 | foreach (const AnimationSettings &setting, settings) { | ||
281 | array.setProperty(i, (uint)effect->animate(window, | 293 | array.setProperty(i, (uint)effect->animate(window, | ||
282 | setting.type, | 294 | setting.type, | ||
283 | setting.duration, | 295 | setting.duration, | ||
284 | setting.to, | 296 | setting.to, | ||
285 | setting.from, | 297 | setting.from, | ||
286 | setting.metaData, | 298 | setting.metaData, | ||
287 | setting.curve, | 299 | setting.curve, | ||
288 | setting.delay)); | 300 | setting.delay, | ||
301 | setting.keepAlive)); | ||||
289 | ++i; | 302 | ++i; | ||
290 | } | 303 | } | ||
291 | return array; | 304 | return array; | ||
292 | } | 305 | } | ||
293 | 306 | | |||
294 | QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine) | 307 | QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine) | ||
295 | { | 308 | { | ||
296 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | 309 | ScriptedEffect *effect = qobject_cast<ScriptedEffect*>(context->callee().data().toQObject()); | ||
Show All 13 Lines | |||||
310 | foreach (const AnimationSettings &setting, settings) { | 323 | foreach (const AnimationSettings &setting, settings) { | ||
311 | animIds << QVariant(effect->set(window, | 324 | animIds << QVariant(effect->set(window, | ||
312 | setting.type, | 325 | setting.type, | ||
313 | setting.duration, | 326 | setting.duration, | ||
314 | setting.to, | 327 | setting.to, | ||
315 | setting.from, | 328 | setting.from, | ||
316 | setting.metaData, | 329 | setting.metaData, | ||
317 | setting.curve, | 330 | setting.curve, | ||
318 | setting.delay)); | 331 | setting.delay, | ||
332 | setting.keepAlive)); | ||||
319 | } | 333 | } | ||
320 | 334 | | |||
321 | return engine->newVariant(animIds); | 335 | return engine->newVariant(animIds); | ||
322 | } | 336 | } | ||
323 | 337 | | |||
324 | QList<quint64> animations(const QVariant &v, bool *ok) | 338 | QList<quint64> animations(const QVariant &v, bool *ok) | ||
325 | { | 339 | { | ||
326 | QList<quint64> animIds; | 340 | QList<quint64> animIds; | ||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Line(s) | 586 | if (value.isError()) { | |||
576 | QScriptValueIterator iter(value); | 590 | QScriptValueIterator iter(value); | ||
577 | while (iter.hasNext()) { | 591 | while (iter.hasNext()) { | ||
578 | iter.next(); | 592 | iter.next(); | ||
579 | qCDebug(KWIN_SCRIPTING) << " " << iter.name() << ": " << iter.value().toString(); | 593 | qCDebug(KWIN_SCRIPTING) << " " << iter.name() << ": " << iter.value().toString(); | ||
580 | } | 594 | } | ||
581 | } | 595 | } | ||
582 | } | 596 | } | ||
583 | 597 | | |||
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) | 598 | 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 keepAlive) | ||
585 | { | 599 | { | ||
586 | QEasingCurve qec; | 600 | QEasingCurve qec; | ||
587 | if (curve < QEasingCurve::Custom) | 601 | if (curve < QEasingCurve::Custom) | ||
588 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | 602 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | ||
589 | else if (curve == GaussianCurve) | 603 | else if (curve == GaussianCurve) | ||
590 | qec.setCustomType(qecGaussian); | 604 | qec.setCustomType(qecGaussian); | ||
591 | return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, from); | 605 | return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, from, keepAlive); | ||
592 | } | 606 | } | ||
593 | 607 | | |||
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) | 608 | 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 keepAlive) | ||
595 | { | 609 | { | ||
596 | QEasingCurve qec; | 610 | QEasingCurve qec; | ||
597 | if (curve < QEasingCurve::Custom) | 611 | if (curve < QEasingCurve::Custom) | ||
598 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | 612 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | ||
599 | else if (curve == GaussianCurve) | 613 | else if (curve == GaussianCurve) | ||
600 | qec.setCustomType(qecGaussian); | 614 | qec.setCustomType(qecGaussian); | ||
601 | return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from); | 615 | return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from, keepAlive); | ||
602 | } | 616 | } | ||
603 | 617 | | |||
604 | bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) | 618 | bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) | ||
605 | { | 619 | { | ||
606 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | 620 | return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); | ||
607 | } | 621 | } | ||
608 | 622 | | |||
609 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | 623 | bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) | ||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |