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: 2009 Lucas Murray <lmurray@undefinedfire.com>
0006     SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
0007     SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 "use strict";
0013 
0014 var fadeDesktopEffect = {
0015     duration: animationTime(250),
0016     loadConfig: function () {
0017         fadeDesktopEffect.duration = animationTime(250);
0018     },
0019     fadeInWindow: function (window) {
0020         if (window.fadeOutAnimation) {
0021             if (redirect(window.fadeOutAnimation, Effect.Backward)) {
0022                 return;
0023             }
0024             cancel(window.fadeOutAnimation);
0025             delete window.fadeOutAnimation;
0026         }
0027         if (window.fadeInAnimation) {
0028             if (redirect(window.fadeInAnimation, Effect.Forward)) {
0029                 return;
0030             }
0031             cancel(window.fadeInAnimation);
0032         }
0033         window.fadeInAnimation = animate({
0034             window: window,
0035             curve: QEasingCurve.Linear,
0036             duration: fadeDesktopEffect.duration,
0037             fullScreen: true,
0038             keepAlive: false,
0039             type: Effect.Opacity,
0040             from: 0.0,
0041             to: 1.0
0042         });
0043     },
0044     fadeOutWindow: function (window) {
0045         if (window.fadeInAnimation) {
0046             if (redirect(window.fadeInAnimation, Effect.Backward)) {
0047                 return;
0048             }
0049             cancel(window.fadeInAnimation);
0050             delete window.fadeInAnimation;
0051         }
0052         if (window.fadeOutAnimation) {
0053             if (redirect(window.fadeOutAnimation, Effect.Forward)) {
0054                 return;
0055             }
0056             cancel(window.fadeOutAnimation);
0057         }
0058         window.fadeOutAnimation = animate({
0059             window: window,
0060             curve: QEasingCurve.Linear,
0061             duration: fadeDesktopEffect.duration,
0062             fullScreen: true,
0063             keepAlive: false,
0064             type: Effect.Opacity,
0065             from: 1.0,
0066             to: 0.0
0067         });
0068     },
0069     slotDesktopChanged: function (oldDesktop, newDesktop, movingWindow) {
0070         if (effects.hasActiveFullScreenEffect && !effect.isActiveFullScreenEffect) {
0071             return;
0072         }
0073 
0074         var stackingOrder = effects.stackingOrder;
0075         for (var i = 0; i < stackingOrder.length; ++i) {
0076             var w = stackingOrder[i];
0077 
0078             // Don't animate windows that have been moved to the current
0079             // desktop, i.e. newDesktop.
0080             if (w == movingWindow) {
0081                 continue;
0082             }
0083 
0084             // If the window is not on the old and the new desktop or it's
0085             // on both of them, then don't animate it.
0086             var onOldDesktop = w.isOnDesktop(oldDesktop);
0087             var onNewDesktop = w.isOnDesktop(newDesktop);
0088             if (onOldDesktop == onNewDesktop) {
0089                 continue;
0090             }
0091 
0092             if (w.minimized) {
0093                 continue;
0094             }
0095 
0096             if (!w.isOnActivity(effects.currentActivity)){
0097                 continue;
0098             }
0099 
0100             if (onOldDesktop) {
0101                 fadeDesktopEffect.fadeOutWindow(w);
0102             } else {
0103                 fadeDesktopEffect.fadeInWindow(w);
0104             }
0105         }
0106     },
0107     slotIsActiveFullScreenEffectChanged: function () {
0108         var isActiveFullScreen = effect.isActiveFullScreenEffect;
0109         var stackingOrder = effects.stackingOrder;
0110         for (var i = 0; i < stackingOrder.length; ++i) {
0111             var w = stackingOrder[i];
0112             w.setData(Effect.WindowForceBlurRole, isActiveFullScreen);
0113             w.setData(Effect.WindowForceBackgroundContrastRole, isActiveFullScreen);
0114         }
0115     },
0116     init: function () {
0117         effect.configChanged.connect(fadeDesktopEffect.loadConfig);
0118         effect.isActiveFullScreenEffectChanged.connect(
0119             fadeDesktopEffect.slotIsActiveFullScreenEffectChanged);
0120         effects.desktopChanged.connect(fadeDesktopEffect.slotDesktopChanged);
0121     }
0122 };
0123 
0124 fadeDesktopEffect.init();