effects/fade: Rewrite the effect using ES6 features
This cleans up the code of the effect.
This commit is contained in:
parent
9fb58479b7
commit
24a474cb6c
1 changed files with 86 additions and 72 deletions
|
@ -4,11 +4,12 @@
|
|||
|
||||
SPDX-FileCopyrightText: 2007 Philip Falkner <philip.falkner@gmail.com>
|
||||
SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
|
||||
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
var blacklist = [
|
||||
const blacklist = [
|
||||
// The logout screen has to be animated only by the logout effect.
|
||||
"ksmserver ksmserver",
|
||||
"ksmserver-logout-greeter ksmserver-logout-greeter",
|
||||
|
@ -17,64 +18,76 @@ var blacklist = [
|
|||
"ksplashqml ksplashqml"
|
||||
];
|
||||
|
||||
function isFadeWindow(w) {
|
||||
if (blacklist.indexOf(w.windowClass) != -1) {
|
||||
return false;
|
||||
}
|
||||
if (w.popupWindow) {
|
||||
return false;
|
||||
}
|
||||
if (w.x11Client && !w.managed) {
|
||||
return false;
|
||||
}
|
||||
if (!w.visible) {
|
||||
return false;
|
||||
}
|
||||
if (w.outline) {
|
||||
return false;
|
||||
}
|
||||
if (w.deleted && effect.isGrabbed(w, Effect.WindowClosedGrabRole)) {
|
||||
return false;
|
||||
} else if (!w.deleted && effect.isGrabbed(w, Effect.WindowAddedGrabRole)) {
|
||||
return false;
|
||||
}
|
||||
return w.normalWindow || w.dialog;
|
||||
}
|
||||
class FadeEffect {
|
||||
constructor() {
|
||||
effect.configChanged.connect(this.loadConfig.bind(this));
|
||||
effects.windowAdded.connect(this.onWindowAdded.bind(this));
|
||||
effects.windowClosed.connect(this.onWindowClosed.bind(this));
|
||||
effects.windowDataChanged.connect(this.onWindowDataChanged.bind(this));
|
||||
|
||||
var fadeInTime, fadeOutTime, fadeWindows;
|
||||
function loadConfig() {
|
||||
fadeInTime = animationTime(effect.readConfig("FadeInTime", 150));
|
||||
fadeOutTime = animationTime(effect.readConfig("FadeOutTime", 150)) * 4;
|
||||
fadeWindows = effect.readConfig("FadeWindows", true);
|
||||
}
|
||||
loadConfig();
|
||||
effect.configChanged.connect(function() {
|
||||
loadConfig();
|
||||
});
|
||||
function fadeInHandler(w) {
|
||||
if (effects.hasActiveFullScreenEffect) {
|
||||
return;
|
||||
this.loadConfig();
|
||||
}
|
||||
if (fadeWindows && isFadeWindow(w)) {
|
||||
if (w.fadeOutWindowTypeAnimation !== undefined) {
|
||||
cancel(w.fadeOutWindowTypeAnimation);
|
||||
w.fadeOutWindowTypeAnimation = undefined;
|
||||
|
||||
loadConfig() {
|
||||
this.fadeInTime = animationTime(effect.readConfig("FadeInTime", 150));
|
||||
this.fadeOutTime = animationTime(effect.readConfig("FadeOutTime", 150)) * 4;
|
||||
this.fadeWindows = effect.readConfig("FadeWindows", true);
|
||||
}
|
||||
|
||||
static isFadeWindow(w) {
|
||||
if (blacklist.indexOf(w.windowClass) != -1) {
|
||||
return false;
|
||||
}
|
||||
w.fadeInWindowTypeAnimation = effect.animate(w, Effect.Opacity, fadeInTime, 1.0, 0.0);
|
||||
if (w.popupWindow) {
|
||||
return false;
|
||||
}
|
||||
if (w.x11Client && !w.managed) {
|
||||
return false;
|
||||
}
|
||||
if (!w.visible) {
|
||||
return false;
|
||||
}
|
||||
if (w.outline) {
|
||||
return false;
|
||||
}
|
||||
if (w.deleted && effect.isGrabbed(w, Effect.WindowClosedGrabRole)) {
|
||||
return false;
|
||||
} else if (!w.deleted && effect.isGrabbed(w, Effect.WindowAddedGrabRole)) {
|
||||
return false;
|
||||
}
|
||||
return w.normalWindow || w.dialog;
|
||||
}
|
||||
}
|
||||
function fadeOutHandler(w) {
|
||||
if (effects.hasActiveFullScreenEffect) {
|
||||
return;
|
||||
}
|
||||
if (fadeWindows && isFadeWindow(w)) {
|
||||
if (w.fadeOutWindowTypeAnimation !== undefined) {
|
||||
// don't animate again as it was already animated through window hidden
|
||||
|
||||
onWindowAdded(window) {
|
||||
if (effects.hasActiveFullScreenEffect) {
|
||||
return;
|
||||
}
|
||||
w.fadeOutWindowTypeAnimation = animate({
|
||||
window: w,
|
||||
duration: fadeOutTime,
|
||||
if (!this.fadeWindows || !FadeEffect.isFadeWindow(window)) {
|
||||
return;
|
||||
}
|
||||
if (window.fadeOutAnimation) {
|
||||
cancel(window.fadeOutAnimation);
|
||||
delete window.fadeOutAnimation;
|
||||
}
|
||||
window.fadeInAnimation = effect.animate({
|
||||
window,
|
||||
duration: this.fadeInTime,
|
||||
type: Effect.Opacity,
|
||||
to: 1.0,
|
||||
from: 0.0
|
||||
});
|
||||
}
|
||||
|
||||
onWindowClosed(window) {
|
||||
if (effects.hasActiveFullScreenEffect) {
|
||||
return;
|
||||
}
|
||||
if (!this.fadeWindows || !FadeEffect.isFadeWindow(window)) {
|
||||
return;
|
||||
}
|
||||
window.fadeOutAnimation = animate({
|
||||
window,
|
||||
duration: this.fadeOutTime,
|
||||
animations: [{
|
||||
type: Effect.Opacity,
|
||||
curve: QEasingCurve.OutQuart,
|
||||
|
@ -82,23 +95,24 @@ function fadeOutHandler(w) {
|
|||
}]
|
||||
});
|
||||
}
|
||||
|
||||
onWindowDataChanged(window, role) {
|
||||
if (role == Effect.WindowAddedGrabRole) {
|
||||
if (effect.isGrabbed(window, Effect.WindowAddedGrabRole)) {
|
||||
if (window.fadeInAnimation) {
|
||||
cancel(window.fadeInAnimation);
|
||||
delete window.fadeInAnimation;
|
||||
}
|
||||
}
|
||||
} else if (role == Effect.WindowClosedGrabRole) {
|
||||
if (effect.isGrabbed(window, Effect.WindowClosedGrabRole)) {
|
||||
if (window.fadeOutAnimation) {
|
||||
cancel(window.fadeOutAnimation);
|
||||
delete window.fadeOutAnimation;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
effects.windowAdded.connect(fadeInHandler);
|
||||
effects.windowClosed.connect(fadeOutHandler);
|
||||
effects.windowDataChanged.connect(function (window, role) {
|
||||
if (role == Effect.WindowAddedGrabRole) {
|
||||
if (effect.isGrabbed(window, Effect.WindowAddedGrabRole)) {
|
||||
if (window.fadeInWindowTypeAnimation !== undefined) {
|
||||
cancel(window.fadeInWindowTypeAnimation);
|
||||
window.fadeInWindowTypeAnimation = undefined;
|
||||
}
|
||||
}
|
||||
} else if (role == Effect.WindowClosedGrabRole) {
|
||||
if (effect.isGrabbed(window, Effect.WindowClosedGrabRole)) {
|
||||
if (window.fadeOutWindowTypeAnimation !== undefined) {
|
||||
cancel(window.fadeOutWindowTypeAnimation);
|
||||
window.fadeOutWindowTypeAnimation = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
new FadeEffect();
|
||||
|
|
Loading…
Reference in a new issue