File indexing completed on 2024-11-10 04:56:58
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 "use strict"; 0010 0011 class FullScreenEffect { 0012 constructor() { 0013 effect.configChanged.connect(this.loadConfig.bind(this)); 0014 effect.animationEnded.connect(this.restoreForceBlurState.bind(this)); 0015 0016 effects.windowAdded.connect(this.manage.bind(this)); 0017 for (const window of effects.stackingOrder) { 0018 this.manage(window); 0019 } 0020 0021 this.loadConfig(); 0022 } 0023 0024 loadConfig() { 0025 this.duration = animationTime(250); 0026 } 0027 0028 manage(window) { 0029 window.windowFrameGeometryChanged.connect( 0030 this.onWindowFrameGeometryChanged.bind(this)); 0031 window.windowFullScreenChanged.connect( 0032 this.onWindowFullScreenChanged.bind(this)); 0033 } 0034 0035 onWindowFullScreenChanged(window) { 0036 if (!window.visible || !window.oldGeometry) { 0037 return; 0038 } 0039 window.setData(Effect.WindowForceBlurRole, true); 0040 let oldGeometry = window.oldGeometry; 0041 const newGeometry = window.geometry; 0042 if (oldGeometry.width == newGeometry.width && oldGeometry.height == newGeometry.height) 0043 oldGeometry = window.olderGeometry; 0044 window.olderGeometry = Object.assign({}, window.oldGeometry); 0045 window.oldGeometry = Object.assign({}, newGeometry); 0046 0047 let couldRetarget = false; 0048 if (window.fullScreenAnimation1) { 0049 if (window.fullScreenAnimation1[0]) { 0050 couldRetarget = retarget(window.fullScreenAnimation1[0], { 0051 value1: newGeometry.width, 0052 value2: newGeometry.height 0053 }, this.duration); 0054 } 0055 if (window.fullScreenAnimation1[1]) { 0056 couldRetarget = retarget(window.fullScreenAnimation1[1], { 0057 value1: newGeometry.x + newGeometry.width / 2, 0058 value2: newGeometry.y + newGeometry.height / 2 0059 }, this.duration); 0060 } 0061 } 0062 if (!couldRetarget) { 0063 if (window.fullScreenAnimation1) { 0064 cancel(window.fullScreenAnimation1); 0065 delete window.fullScreenAnimation1; 0066 } 0067 window.fullScreenAnimation1 = animate({ 0068 window: window, 0069 duration: this.duration, 0070 animations: [{ 0071 type: Effect.Size, 0072 to: { 0073 value1: newGeometry.width, 0074 value2: newGeometry.height 0075 }, 0076 from: { 0077 value1: oldGeometry.width, 0078 value2: oldGeometry.height 0079 }, 0080 curve: QEasingCurve.OutCubic 0081 }, { 0082 type: Effect.Position, 0083 to: { 0084 value1: newGeometry.x + newGeometry.width / 2, 0085 value2: newGeometry.y + newGeometry.height / 2 0086 }, 0087 from: { 0088 value1: oldGeometry.x + oldGeometry.width / 2, 0089 value2: oldGeometry.y + oldGeometry.height / 2 0090 }, 0091 curve: QEasingCurve.OutCubic 0092 }] 0093 }); 0094 } 0095 if (!window.resize) { 0096 window.fullScreenAnimation2 =animate({ 0097 window: window, 0098 duration: this.duration, 0099 animations: [{ 0100 type: Effect.CrossFadePrevious, 0101 to: 1.0, 0102 from: 0.0, 0103 curve: QEasingCurve.OutCubic 0104 }] 0105 }); 0106 } 0107 } 0108 0109 restoreForceBlurState(window) { 0110 window.setData(Effect.WindowForceBlurRole, null); 0111 } 0112 0113 onWindowFrameGeometryChanged(window, oldGeometry) { 0114 if (window.fullScreenAnimation1) { 0115 if (window.geometry.width != window.oldGeometry.width || 0116 window.geometry.height != window.oldGeometry.height) { 0117 if (window.fullScreenAnimation2) { 0118 cancel(window.fullScreenAnimation2); 0119 delete window.fullScreenAnimation2; 0120 } 0121 } 0122 } 0123 window.oldGeometry = Object.assign({}, window.geometry); 0124 window.olderGeometry = Object.assign({}, oldGeometry); 0125 } 0126 } 0127 0128 new FullScreenEffect();