File indexing completed on 2024-11-10 04:56:58
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2007 Philip Falkner <philip.falkner@gmail.com> 0006 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 0007 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 const blacklist = [ 0013 // The logout screen has to be animated only by the logout effect. 0014 "ksmserver ksmserver", 0015 "ksmserver-logout-greeter ksmserver-logout-greeter", 0016 0017 // The splash screen has to be animated only by the login effect. 0018 "ksplashqml ksplashqml", 0019 0020 // Spectacle needs to be blacklisted in order to stay out of its own screenshots. 0021 "spectacle spectacle", // x11 0022 "spectacle org.kde.spectacle", // wayland 0023 ]; 0024 0025 class FadeEffect { 0026 constructor() { 0027 effect.configChanged.connect(this.loadConfig.bind(this)); 0028 effects.windowAdded.connect(this.onWindowAdded.bind(this)); 0029 effects.windowClosed.connect(this.onWindowClosed.bind(this)); 0030 effects.windowDataChanged.connect(this.onWindowDataChanged.bind(this)); 0031 0032 this.loadConfig(); 0033 } 0034 0035 loadConfig() { 0036 this.fadeInTime = animationTime(effect.readConfig("FadeInTime", 150)); 0037 this.fadeOutTime = animationTime(effect.readConfig("FadeOutTime", 150)) * 4; 0038 } 0039 0040 static isFadeWindow(w) { 0041 if (blacklist.indexOf(w.windowClass) != -1) { 0042 return false; 0043 } 0044 if (w.popupWindow) { 0045 return false; 0046 } 0047 if (!w.managed) { 0048 return false; 0049 } 0050 if (!w.visible) { 0051 return false; 0052 } 0053 if (w.outline) { 0054 return false; 0055 } 0056 if (w.deleted && effect.isGrabbed(w, Effect.WindowClosedGrabRole)) { 0057 return false; 0058 } else if (!w.deleted && effect.isGrabbed(w, Effect.WindowAddedGrabRole)) { 0059 return false; 0060 } 0061 return w.normalWindow || w.dialog; 0062 } 0063 0064 onWindowAdded(window) { 0065 if (effects.hasActiveFullScreenEffect) { 0066 return; 0067 } 0068 if (!FadeEffect.isFadeWindow(window)) { 0069 return; 0070 } 0071 if (window.fadeOutAnimation) { 0072 cancel(window.fadeOutAnimation); 0073 delete window.fadeOutAnimation; 0074 } 0075 window.fadeInAnimation = effect.animate({ 0076 window, 0077 duration: this.fadeInTime, 0078 type: Effect.Opacity, 0079 to: 1.0, 0080 from: 0.0 0081 }); 0082 } 0083 0084 onWindowClosed(window) { 0085 if (effects.hasActiveFullScreenEffect) { 0086 return; 0087 } 0088 if (window.skipsCloseAnimation || !FadeEffect.isFadeWindow(window)) { 0089 return; 0090 } 0091 window.fadeOutAnimation = animate({ 0092 window, 0093 duration: this.fadeOutTime, 0094 animations: [{ 0095 type: Effect.Opacity, 0096 curve: QEasingCurve.OutQuart, 0097 to: 0.0 0098 }] 0099 }); 0100 } 0101 0102 onWindowDataChanged(window, role) { 0103 if (role == Effect.WindowAddedGrabRole) { 0104 if (effect.isGrabbed(window, Effect.WindowAddedGrabRole)) { 0105 if (window.fadeInAnimation) { 0106 cancel(window.fadeInAnimation); 0107 delete window.fadeInAnimation; 0108 } 0109 } 0110 } else if (role == Effect.WindowClosedGrabRole) { 0111 if (effect.isGrabbed(window, Effect.WindowClosedGrabRole)) { 0112 if (window.fadeOutAnimation) { 0113 cancel(window.fadeOutAnimation); 0114 delete window.fadeOutAnimation; 0115 } 0116 } 0117 } 0118 } 0119 } 0120 0121 new FadeEffect();