Changeset View
Changeset View
Standalone View
Standalone View
scripting/scriptedeffect.cpp
Show All 37 Lines | |||||
38 | typedef KWin::EffectWindow* KEffectWindowRef; | 38 | typedef KWin::EffectWindow* KEffectWindowRef; | ||
39 | 39 | | |||
40 | Q_DECLARE_METATYPE(KSharedConfigPtr) | 40 | Q_DECLARE_METATYPE(KSharedConfigPtr) | ||
41 | 41 | | |||
42 | namespace KWin | 42 | namespace KWin | ||
43 | { | 43 | { | ||
44 | 44 | | |||
45 | struct AnimationSettings { | 45 | struct AnimationSettings { | ||
46 | enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3 }; | 46 | enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3, FullScreen = 1<<4 }; | ||
47 | AnimationEffect::Attribute type; | 47 | AnimationEffect::Attribute type; | ||
48 | QEasingCurve::Type curve; | 48 | QEasingCurve::Type curve; | ||
49 | QJSValue from; //should be a KFx2 | 49 | QJSValue from; //should be a KFx2 | ||
50 | QJSValue to; | 50 | QJSValue to; | ||
51 | int delay; | 51 | int delay; | ||
52 | uint duration; | 52 | uint duration; | ||
53 | uint set; | 53 | uint set; | ||
54 | uint metaData; | 54 | uint metaData; | ||
55 | bool fullScreenEffect; | ||||
55 | }; | 56 | }; | ||
56 | 57 | | |||
57 | AnimationSettings animationSettingsFromObject(const QJSValue &object) | 58 | AnimationSettings animationSettingsFromObject(const QJSValue &object) | ||
58 | { | 59 | { | ||
59 | AnimationSettings settings; | 60 | AnimationSettings settings; | ||
60 | settings.set = 0; | 61 | settings.set = 0; | ||
61 | settings.metaData = 0; | 62 | settings.metaData = 0; | ||
62 | 63 | | |||
Show All 26 Lines | |||||
89 | 90 | | |||
90 | QJSValue type = object.property(QStringLiteral("type")); | 91 | QJSValue type = object.property(QStringLiteral("type")); | ||
91 | if (type.isNumber()) { | 92 | if (type.isNumber()) { | ||
92 | settings.type = static_cast<AnimationEffect::Attribute>(type.toInt()); | 93 | settings.type = static_cast<AnimationEffect::Attribute>(type.toInt()); | ||
93 | settings.set |= AnimationSettings::Type; | 94 | settings.set |= AnimationSettings::Type; | ||
94 | } else { | 95 | } else { | ||
95 | settings.type = static_cast<AnimationEffect::Attribute>(-1); | 96 | settings.type = static_cast<AnimationEffect::Attribute>(-1); | ||
96 | } | 97 | } | ||
98 | | ||||
99 | QJSValue 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. | |||||
100 | if (isFullScreen.isBool()) { | ||||
101 | settings.fullScreenEffect = isFullScreen.toBool(); | ||||
102 | settings.set |= AnimationSettings::FullScreen; | ||||
103 | } else { | ||||
104 | settings.fullScreenEffect = false; | ||||
105 | } | ||||
97 | return settings; | 106 | return settings; | ||
98 | } | 107 | } | ||
99 | 108 | | |||
100 | KWin::FPx2 fpx2FromScriptValue(const QJSValue &value) | 109 | KWin::FPx2 fpx2FromScriptValue(const QJSValue &value) | ||
101 | { | 110 | { | ||
102 | if (value.isNull()) { | 111 | if (value.isNull()) { | ||
103 | return FPx2(); | 112 | return FPx2(); | ||
104 | } | 113 | } | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
152 | 161 | | |||
153 | ScriptedEffect::ScriptedEffect() | 162 | ScriptedEffect::ScriptedEffect() | ||
154 | : AnimationEffect() | 163 | : AnimationEffect() | ||
155 | , m_engine(new QJSEngine(this)) | 164 | , m_engine(new QJSEngine(this)) | ||
156 | , m_scriptFile(QString()) | 165 | , m_scriptFile(QString()) | ||
157 | , m_config(nullptr) | 166 | , m_config(nullptr) | ||
158 | , m_chainPosition(0) | 167 | , m_chainPosition(0) | ||
159 | { | 168 | { | ||
169 | Q_ASSERT(effects); | ||||
170 | connect(effects, &EffectsHandler::activeFullScreenEffectChanged, this, &ScriptedEffect::activeFullScreenEffectChanged); | ||||
160 | } | 171 | } | ||
161 | 172 | | |||
162 | ScriptedEffect::~ScriptedEffect() | 173 | ScriptedEffect::~ScriptedEffect() | ||
163 | { | 174 | { | ||
164 | } | 175 | } | ||
165 | 176 | | |||
166 | bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript) | 177 | bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript) | ||
167 | { | 178 | { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 237 | if (ret.isError()) { | |||
228 | qCDebug(KWIN_SCRIPTING) << "Message: " << ret.property("message").toString(); | 239 | qCDebug(KWIN_SCRIPTING) << "Message: " << ret.property("message").toString(); | ||
229 | qCDebug(KWIN_SCRIPTING) << ": " << ret.toString(); | 240 | qCDebug(KWIN_SCRIPTING) << ": " << ret.toString(); | ||
230 | return false; | 241 | return false; | ||
231 | } | 242 | } | ||
232 | scriptFile.close(); | 243 | scriptFile.close(); | ||
233 | return true; | 244 | return true; | ||
234 | } | 245 | } | ||
235 | 246 | | |||
247 | ScriptedEffect::ActiveFullScreenEffectState ScriptedEffect::fullScreenEffectState() const | ||||
248 | { | ||||
249 | const auto *activeEffect = effects->activeFullScreenEffect(); | ||||
250 | if (!activeEffect) { | ||||
251 | return ScriptedEffect::InactiveFullScreenEffect; | ||||
252 | } | ||||
253 | if (activeEffect == this) { | ||||
254 | return ScriptedEffect::OwnedFullScreenEffect; | ||||
255 | } | ||||
256 | return ScriptedEffect::ActiveFullScreenEffect; | ||||
257 | } | ||||
258 | | ||||
236 | int ScriptedEffect::displayHeight() const | 259 | int ScriptedEffect::displayHeight() const | ||
237 | { | 260 | { | ||
238 | return screens()->displaySize().height(); | 261 | return screens()->displaySize().height(); | ||
239 | } | 262 | } | ||
240 | 263 | | |||
241 | int ScriptedEffect::animationTime(int defaultTime) const | 264 | int ScriptedEffect::animationTime(int defaultTime) const | ||
242 | { | 265 | { | ||
243 | return Effect::animationTime(defaultTime); | 266 | return Effect::animationTime(defaultTime); | ||
244 | } | 267 | } | ||
245 | 268 | | |||
246 | int ScriptedEffect::displayWidth() const | 269 | int ScriptedEffect::displayWidth() const | ||
247 | { | 270 | { | ||
248 | return screens()->displaySize().width(); | 271 | return screens()->displaySize().width(); | ||
249 | } | 272 | } | ||
250 | 273 | | |||
251 | void ScriptedEffect::animationEnded(KWin::EffectWindow *w, Attribute a, uint meta) | 274 | void ScriptedEffect::animationEnded(KWin::EffectWindow *w, Attribute a, uint meta) | ||
252 | { | 275 | { | ||
253 | AnimationEffect::animationEnded(w, a, meta); | 276 | AnimationEffect::animationEnded(w, a, meta); | ||
254 | emit animationEnded(w, 0); | 277 | emit animationEnded(w, 0); | ||
255 | } | 278 | } | ||
256 | 279 | | |||
257 | int ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, const QJSValue &to, const QJSValue &from, uint metaData, int curve, int delay) | 280 | int ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, const QJSValue &to, const QJSValue &from, uint metaData, int curve, int delay, bool fullScreen) | ||
258 | { | 281 | { | ||
259 | QEasingCurve qec; | 282 | QEasingCurve qec; | ||
260 | if (curve < QEasingCurve::Custom) | 283 | if (curve < QEasingCurve::Custom) | ||
261 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | 284 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | ||
262 | else if (curve == GaussianCurve) | 285 | else if (curve == GaussianCurve) | ||
263 | qec.setCustomType(qecGaussian); | 286 | qec.setCustomType(qecGaussian); | ||
264 | return AnimationEffect::animate(w, a, metaData, ms, fpx2FromScriptValue(to), qec, delay, fpx2FromScriptValue(from)); | 287 | | ||
288 | return AnimationEffect::animate(w, a, metaData, ms, fpx2FromScriptValue(to), qec, delay, fpx2FromScriptValue(from), fullScreen); | ||||
265 | } | 289 | } | ||
266 | 290 | | |||
267 | int ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, const QJSValue &to, const QJSValue &from, uint metaData, int curve, int delay) | 291 | int ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, const QJSValue &to, const QJSValue &from, uint metaData, int curve, int delay, bool fullScreen) | ||
268 | { | 292 | { | ||
269 | QEasingCurve qec; | 293 | QEasingCurve qec; | ||
270 | if (curve < QEasingCurve::Custom) | 294 | if (curve < QEasingCurve::Custom) | ||
271 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | 295 | qec.setType(static_cast<QEasingCurve::Type>(curve)); | ||
272 | else if (curve == GaussianCurve) | 296 | else if (curve == GaussianCurve) | ||
273 | qec.setCustomType(qecGaussian); | 297 | qec.setCustomType(qecGaussian); | ||
274 | return AnimationEffect::set(w, a, metaData, ms, fpx2FromScriptValue(to), qec, delay, fpx2FromScriptValue(from)); | 298 | return AnimationEffect::set(w, a, metaData, ms, fpx2FromScriptValue(to), qec, delay, fpx2FromScriptValue(from), fullScreen); | ||
275 | } | 299 | } | ||
276 | 300 | | |||
277 | bool ScriptedEffect::retarget(int animationId, const QJSValue &newTarget, int newRemainingTime) | 301 | bool ScriptedEffect::retarget(int animationId, const QJSValue &newTarget, int newRemainingTime) | ||
278 | { | 302 | { | ||
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… | |||||
279 | return AnimationEffect::retarget(animationId, fpx2FromScriptValue(newTarget), newRemainingTime); | 303 | return AnimationEffect::retarget(animationId, fpx2FromScriptValue(newTarget), newRemainingTime); | ||
280 | } | 304 | } | ||
281 | 305 | | |||
282 | bool ScriptedEffect::retarget(const QList<int> &animationIds, const QJSValue &newTarget, int newRemainingTime) | 306 | bool ScriptedEffect::retarget(const QList<int> &animationIds, const QJSValue &newTarget, int newRemainingTime) | ||
283 | { | 307 | { | ||
284 | bool ok = true; | 308 | bool ok = true; | ||
285 | for (int animationId: qAsConst(animationIds)) { | 309 | for (int animationId: qAsConst(animationIds)) { | ||
286 | ok |= retarget(animationId, newTarget, newRemainingTime); | 310 | ok |= retarget(animationId, newTarget, newRemainingTime); | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 414 | for (int i = 0; i < settings.count(); i++) { | |||
393 | if (settingPersists) { | 417 | if (settingPersists) { | ||
394 | animationId = set(window, | 418 | animationId = set(window, | ||
395 | setting.type, | 419 | setting.type, | ||
396 | setting.duration, | 420 | setting.duration, | ||
397 | setting.to, | 421 | setting.to, | ||
398 | setting.from, | 422 | setting.from, | ||
399 | setting.metaData, | 423 | setting.metaData, | ||
400 | setting.curve, | 424 | setting.curve, | ||
401 | setting.delay); | 425 | setting.delay, | ||
426 | setting.fullScreenEffect); | ||||
427 | | ||||
402 | } else { | 428 | } else { | ||
403 | animationId = animate(window, | 429 | animationId = animate(window, | ||
404 | setting.type, | 430 | setting.type, | ||
405 | setting.duration, | 431 | setting.duration, | ||
406 | setting.to, | 432 | setting.to, | ||
407 | setting.from, | 433 | setting.from, | ||
408 | setting.metaData, | 434 | setting.metaData, | ||
409 | setting.curve, | 435 | setting.curve, | ||
410 | setting.delay); | 436 | setting.delay, | ||
437 | setting.fullScreenEffect); | ||||
411 | } | 438 | } | ||
412 | array.setProperty(i, animationId); | 439 | array.setProperty(i, animationId); | ||
413 | } | 440 | } | ||
414 | return array; | 441 | return array; | ||
415 | } | 442 | } | ||
416 | 443 | | |||
417 | bool ScriptedEffect::cancel(int animationId) | 444 | bool ScriptedEffect::cancel(int animationId) | ||
418 | { | 445 | { | ||
▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines |
I think it would be better to capitalize 'screen', so it's consistent with the rest of api: