File indexing completed on 2024-11-10 04:57:10
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 "use strict"; 0010 0011 var squashEffect = { 0012 duration: animationTime(250), 0013 loadConfig: function () { 0014 squashEffect.duration = animationTime(250); 0015 }, 0016 slotWindowMinimized: function (window) { 0017 if (effects.hasActiveFullScreenEffect) { 0018 return; 0019 } 0020 0021 // If the window doesn't have an icon in the task manager, 0022 // don't animate it. 0023 var iconRect = window.iconGeometry; 0024 if (iconRect.width == 0 || iconRect.height == 0) { 0025 return; 0026 } 0027 0028 if (window.unminimizeAnimation) { 0029 if (redirect(window.unminimizeAnimation, Effect.Backward)) { 0030 return; 0031 } 0032 cancel(window.unminimizeAnimation); 0033 delete window.unminimizeAnimation; 0034 } 0035 0036 if (window.minimizeAnimation) { 0037 if (redirect(window.minimizeAnimation, Effect.Forward)) { 0038 return; 0039 } 0040 cancel(window.minimizeAnimation); 0041 } 0042 0043 var windowRect = window.geometry; 0044 0045 window.minimizeAnimation = animate({ 0046 window: window, 0047 curve: QEasingCurve.InCubic, 0048 duration: squashEffect.duration, 0049 animations: [ 0050 { 0051 type: Effect.Size, 0052 from: { 0053 value1: windowRect.width, 0054 value2: windowRect.height 0055 }, 0056 to: { 0057 value1: iconRect.width, 0058 value2: iconRect.height 0059 } 0060 }, 0061 { 0062 type: Effect.Translation, 0063 from: { 0064 value1: 0.0, 0065 value2: 0.0 0066 }, 0067 to: { 0068 value1: iconRect.x - windowRect.x - 0069 (windowRect.width - iconRect.width) / 2, 0070 value2: iconRect.y - windowRect.y - 0071 (windowRect.height - iconRect.height) / 2, 0072 } 0073 }, 0074 { 0075 type: Effect.Opacity, 0076 from: 1.0, 0077 to: 0.0 0078 } 0079 ] 0080 }); 0081 }, 0082 slotWindowUnminimized: function (window) { 0083 if (effects.hasActiveFullScreenEffect) { 0084 return; 0085 } 0086 0087 // If the window doesn't have an icon in the task manager, 0088 // don't animate it. 0089 var iconRect = window.iconGeometry; 0090 if (iconRect.width == 0 || iconRect.height == 0) { 0091 return; 0092 } 0093 0094 if (window.minimizeAnimation) { 0095 if (redirect(window.minimizeAnimation, Effect.Backward)) { 0096 return; 0097 } 0098 cancel(window.minimizeAnimation); 0099 delete window.minimizeAnimation; 0100 } 0101 0102 if (window.unminimizeAnimation) { 0103 if (redirect(window.unminimizeAnimation, Effect.Forward)) { 0104 return; 0105 } 0106 cancel(window.unminimizeAnimation); 0107 } 0108 0109 var windowRect = window.geometry; 0110 0111 window.unminimizeAnimation = animate({ 0112 window: window, 0113 curve: QEasingCurve.OutCubic, 0114 duration: squashEffect.duration, 0115 animations: [ 0116 { 0117 type: Effect.Size, 0118 from: { 0119 value1: iconRect.width, 0120 value2: iconRect.height 0121 }, 0122 to: { 0123 value1: windowRect.width, 0124 value2: windowRect.height 0125 } 0126 }, 0127 { 0128 type: Effect.Translation, 0129 from: { 0130 value1: iconRect.x - windowRect.x - 0131 (windowRect.width - iconRect.width) / 2, 0132 value2: iconRect.y - windowRect.y - 0133 (windowRect.height - iconRect.height) / 2, 0134 }, 0135 to: { 0136 value1: 0.0, 0137 value2: 0.0 0138 } 0139 }, 0140 { 0141 type: Effect.Opacity, 0142 from: 0.0, 0143 to: 1.0 0144 } 0145 ] 0146 }); 0147 }, 0148 slotWindowAdded: function (window) { 0149 window.minimizedChanged.connect(() => { 0150 if (window.minimized) { 0151 squashEffect.slotWindowMinimized(window); 0152 } else { 0153 squashEffect.slotWindowUnminimized(window); 0154 } 0155 }); 0156 }, 0157 init: function () { 0158 effect.configChanged.connect(squashEffect.loadConfig); 0159 0160 effects.windowAdded.connect(squashEffect.slotWindowAdded); 0161 for (const window of effects.stackingOrder) { 0162 squashEffect.slotWindowAdded(window); 0163 } 0164 } 0165 }; 0166 0167 squashEffect.init();