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: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 "use strict";
0011 
0012 var frozenAppEffect = {
0013     inDuration: animationTime(1500),
0014     outDuration: animationTime(250),
0015     loadConfig: function () {
0016         frozenAppEffect.inDuration = animationTime(1500);
0017         frozenAppEffect.outDuration = animationTime(250);
0018     },
0019     windowAdded: function (window) {
0020         window.minimizedChanged.connect(() => {
0021             if (window.minimized) {
0022                 frozenAppEffect.cancelAnimation(window);
0023             } else {
0024                 frozenAppEffect.restartAnimation(window);
0025             }
0026         });
0027         window.windowUnresponsiveChanged.connect(frozenAppEffect.unresponsiveChanged);
0028         window.windowDesktopsChanged.connect(frozenAppEffect.cancelAnimation);
0029         window.windowDesktopsChanged.connect(frozenAppEffect.restartAnimation);
0030 
0031         if (window.unresponsive) {
0032             frozenAppEffect.startAnimation(window, 1);
0033         }
0034     },
0035     windowBecameUnresponsive: function (window) {
0036         if (window.unresponsiveAnimation) {
0037             return;
0038         }
0039         frozenAppEffect.startAnimation(window, frozenAppEffect.inDuration);
0040     },
0041     startAnimation: function (window, duration) {
0042         if (!window.visible) {
0043             return;
0044         }
0045         window.unresponsiveAnimation = set({
0046             window: window,
0047             duration: duration,
0048             animations: [{
0049                 type: Effect.Saturation,
0050                 to: 0.1
0051             }, {
0052                 type: Effect.Brightness,
0053                 to: 1.5
0054             }]
0055         });
0056     },
0057     windowClosed: function (window) {
0058         frozenAppEffect.cancelAnimation(window);
0059         if (!window.unresponsive) {
0060             return;
0061         }
0062         frozenAppEffect.windowBecameResponsive(window);
0063     },
0064     windowBecameResponsive: function (window) {
0065         if (!window.unresponsiveAnimation) {
0066             return;
0067         }
0068         cancel(window.unresponsiveAnimation);
0069         window.unresponsiveAnimation = undefined;
0070 
0071         animate({
0072             window: window,
0073             duration: frozenAppEffect.outDuration,
0074             animations: [{
0075                 type: Effect.Saturation,
0076                 from: 0.1,
0077                 to: 1.0
0078             }, {
0079                 type: Effect.Brightness,
0080                 from: 1.5,
0081                 to: 1.0
0082             }]
0083         });
0084     },
0085     cancelAnimation: function (window) {
0086         if (window.unresponsiveAnimation) {
0087             cancel(window.unresponsiveAnimation);
0088             window.unresponsiveAnimation = undefined;
0089         }
0090     },
0091     desktopChanged: function () {
0092         var windows = effects.stackingOrder;
0093         for (var i = 0, length = windows.length; i < length; ++i) {
0094             var window = windows[i];
0095             frozenAppEffect.cancelAnimation(window);
0096             frozenAppEffect.restartAnimation(window);
0097         }
0098     },
0099     unresponsiveChanged: function (window) {
0100         if (window.unresponsive) {
0101             frozenAppEffect.windowBecameUnresponsive(window);
0102         } else {
0103             frozenAppEffect.windowBecameResponsive(window);
0104         }
0105     },
0106     restartAnimation: function (window) {
0107         if (!window || !window.unresponsive) {
0108             return;
0109         }
0110         frozenAppEffect.startAnimation(window, 1);
0111     },
0112     init: function () {
0113         effects.windowAdded.connect(frozenAppEffect.windowAdded);
0114         effects.windowClosed.connect(frozenAppEffect.windowClosed);
0115         effects.desktopChanged.connect(frozenAppEffect.desktopChanged);
0116 
0117         var windows = effects.stackingOrder;
0118         for (var i = 0, length = windows.length; i < length; ++i) {
0119             frozenAppEffect.windowAdded(windows[i]);
0120         }
0121     }
0122 };
0123 frozenAppEffect.init();