| 1 |
/* |
| 2 |
KWin - the KDE window manager |
| 3 |
This file is part of the KDE project. |
| 4 |
|
| 5 |
SPDX-FileCopyrightText: 2009 Lucas Murray <[email protected]> |
| 6 |
SPDX-FileCopyrightText: 2012 Martin Gräßlin <[email protected]> |
| 7 |
SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <[email protected]> |
| 8 |
|
| 9 |
SPDX-License-Identifier: GPL-2.0-or-later |
| 10 |
*/ |
| 11 |
|
| 12 |
"use strict"; |
| 13 |
|
| 14 |
var fadeDesktopEffect = { |
| 15 |
duration: animationTime(250), |
| 16 |
loadConfig: function () { |
| 17 |
fadeDesktopEffect.duration = animationTime(250); |
| 18 |
}, |
| 19 |
fadeInWindow: function (window) { |
| 20 |
if (window.fadeOutAnimation) { |
| 21 |
if (redirect(window.fadeOutAnimation, Effect.Backward)) { |
| 22 |
return; |
| 23 |
} |
| 24 |
cancel(window.fadeOutAnimation); |
| 25 |
delete window.fadeOutAnimation; |
| 26 |
} |
| 27 |
if (window.fadeInAnimation) { |
| 28 |
if (redirect(window.fadeInAnimation, Effect.Forward)) { |
| 29 |
return; |
| 30 |
} |
| 31 |
cancel(window.fadeInAnimation); |
| 32 |
} |
| 33 |
window.fadeInAnimation = animate({ |
| 34 |
window: window, |
| 35 |
curve: QEasingCurve.Linear, |
| 36 |
duration: fadeDesktopEffect.duration, |
| 37 |
fullScreen: true, |
| 38 |
keepAlive: false, |
| 39 |
type: Effect.Opacity, |
| 40 |
from: 0.0, |
| 41 |
to: 1.0 |
| 42 |
}); |
| 43 |
}, |
| 44 |
fadeOutWindow: function (window) { |
| 45 |
if (window.fadeInAnimation) { |
| 46 |
if (redirect(window.fadeInAnimation, Effect.Backward)) { |
| 47 |
return; |
| 48 |
} |
| 49 |
cancel(window.fadeInAnimation); |
| 50 |
delete window.fadeInAnimation; |
| 51 |
} |
| 52 |
if (window.fadeOutAnimation) { |
| 53 |
if (redirect(window.fadeOutAnimation, Effect.Forward)) { |
| 54 |
return; |
| 55 |
} |
| 56 |
cancel(window.fadeOutAnimation); |
| 57 |
} |
| 58 |
window.fadeOutAnimation = animate({ |
| 59 |
window: window, |
| 60 |
curve: QEasingCurve.Linear, |
| 61 |
duration: fadeDesktopEffect.duration, |
| 62 |
fullScreen: true, |
| 63 |
keepAlive: false, |
| 64 |
type: Effect.Opacity, |
| 65 |
from: 1.0, |
| 66 |
to: 0.0 |
| 67 |
}); |
| 68 |
}, |
| 69 |
slotDesktopChanged: function (oldDesktop, newDesktop, movingWindow) { |
| 70 |
if (effects.hasActiveFullScreenEffect && !effect.isActiveFullScreenEffect) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
var stackingOrder = effects.stackingOrder; |
| 75 |
for (var i = 0; i < stackingOrder.length; ++i) { |
| 76 |
var w = stackingOrder[i]; |
| 77 |
|
| 78 |
// Don't animate windows that have been moved to the current |
| 79 |
// desktop, i.e. newDesktop. |
| 80 |
if (w == movingWindow) { |
| 81 |
continue; |
| 82 |
} |
| 83 |
|
| 84 |
// If the window is not on the old and the new desktop or it's |
| 85 |
// on both of them, then don't animate it. |
| 86 |
var onOldDesktop = w.isOnDesktop(oldDesktop); |
| 87 |
var onNewDesktop = w.isOnDesktop(newDesktop); |
| 88 |
if (onOldDesktop == onNewDesktop) { |
| 89 |
continue; |
| 90 |
} |
| 91 |
|
| 92 |
if (w.minimized) { |
| 93 |
continue; |
| 94 |
} |
| 95 |
|
| 96 |
if (!w.isOnActivity(effects.currentActivity)){ |
| 97 |
continue; |
| 98 |
} |
| 99 |
|
| 100 |
if (onOldDesktop) { |
| 101 |
fadeDesktopEffect.fadeOutWindow(w); |
| 102 |
} else { |
| 103 |
fadeDesktopEffect.fadeInWindow(w); |
| 104 |
} |
| 105 |
} |
| 106 |
}, |
| 107 |
slotIsActiveFullScreenEffectChanged: function () { |
| 108 |
var isActiveFullScreen = effect.isActiveFullScreenEffect; |
| 109 |
var stackingOrder = effects.stackingOrder; |
| 110 |
for (var i = 0; i < stackingOrder.length; ++i) { |
| 111 |
var w = stackingOrder[i]; |
| 112 |
w.setData(Effect.WindowForceBlurRole, isActiveFullScreen); |
| 113 |
w.setData(Effect.WindowForceBackgroundContrastRole, isActiveFullScreen); |
| 114 |
} |
| 115 |
}, |
| 116 |
init: function () { |
| 117 |
effect.configChanged.connect(fadeDesktopEffect.loadConfig); |
| 118 |
effect.isActiveFullScreenEffectChanged.connect( |
| 119 |
fadeDesktopEffect.slotIsActiveFullScreenEffectChanged); |
| 120 |
effects.desktopChanged.connect(fadeDesktopEffect.slotDesktopChanged); |
| 121 |
} |
| 122 |
}; |
| 123 |
|
| 124 |
fadeDesktopEffect.init(); |