[effects/fadedesktop] Rewrite it
ClosedPublic

Authored by zzag on Oct 27 2018, 9:23 AM.

Details

Reviewers
None
Group Reviewers
KWin
Commits
R108:01b75b39bb62: [effects/fadedesktop] Rewrite it
Summary

The primary reason for rewriting this effect was to clean up code and
fix spawning of multiple animations for a single window when user cycles
through virtual desktops very quickly.

Visually, the rewritten version doesn't deviate from the old version.

Diff Detail

Repository
R108 KWin
Branch
libkwineffects-reverse
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 4321
Build 4339: arc lint + arc unit
zzag created this revision.Oct 27 2018, 9:23 AM
Restricted Application added a project: KWin. · View Herald TranscriptOct 27 2018, 9:23 AM
Restricted Application added a subscriber: kwin. · View Herald Transcript
zzag requested review of this revision.Oct 27 2018, 9:23 AM
zzag updated this revision to Diff 44433.Oct 29 2018, 11:11 AM

Rebase.

Code is ok, ship it if you want, but I think we can make it a lot simpler.

effects/fadedesktop/package/contents/code/main.js
26

In QJSEngine, we can just write "use strict" once at the top of the file and it will apply for all functions.

I haven't tested QtScript, but I would be surprised if it's different.

29

One of the reasons we said redirect should have an absolute direction rather than "reverse" was so that we can squash this code into something more like:

fadeWindow(window, direction) {
   if (window.animation) {
       redirect(window.animation, direction);
   } else {
      window.animation = animate(....);
      redirect(window, direction);
   }
}

which IMHO would be a lot easier to read compared to two functions which have to handle 3 possible states of existing animations.

zzag added inline comments.Nov 1 2018, 11:22 AM
effects/fadedesktop/package/contents/code/main.js
29

We don't delete window.animation, so we can't just simply redirect the animation.

Also, from the API standpoint, redirect() can return false, which means it couldn't redirect the animation and some further actions have to be taken (e.g. cancel the animation).

In order to delete window.animation, I assume we need some inspection mechanism to figure out whether all animations has finished.

davidedmundson added inline comments.Nov 1 2018, 11:27 AM
effects/fadedesktop/package/contents/code/main.js
29

In order to delete window.animation

effect.animationEnded.connect(function(window) {

delete window.animation;

});

(And if we were doing multiple animations in an array then we change the above code to remove the array entry and delete the property if it's empty)

zzag added inline comments.Nov 1 2018, 11:32 AM
effects/fadedesktop/package/contents/code/main.js
29

Oh, I forgot that there's the second parameter.

zzag added inline comments.Nov 1 2018, 11:44 AM
effects/fadedesktop/package/contents/code/main.js
29

Well, we still need

if (window.animation) {
    if (redirect(window.animation, Effect.SomewhereIBelong) {
        return;
    }
    cancel(window.animation);
}

window.animation = animate({ ... });

because redirect can fail. It most likely won't happen, but we still need to handle such cases.

davidedmundson added inline comments.Nov 1 2018, 12:02 PM
effects/fadedesktop/package/contents/code/main.js
29

AFAIK it can only fail if you call redirect inside a slot directly connected to animationEnded

but sure, we can have that check.

zzag updated this revision to Diff 44848.Nov 4 2018, 1:30 PM

Move use strict to the beginning of the script.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 17 2018, 12:06 PM
This revision was automatically updated to reflect the committed changes.