2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2013-06-03 13:05:22 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2013-06-03 13:05:22 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-06-03 13:05:22 +00:00
|
|
|
/*global effect, effects, animate, cancel, set, animationTime, Effect, QEasingCurve */
|
|
|
|
/*jslint continue: true */
|
|
|
|
var dialogParentEffect = {
|
|
|
|
duration: animationTime(300),
|
|
|
|
windowAdded: function (window) {
|
|
|
|
"use strict";
|
2018-10-25 16:59:22 +00:00
|
|
|
if (window.modal) {
|
|
|
|
dialogParentEffect.dialogGotModality(window);
|
2013-06-03 13:05:22 +00:00
|
|
|
}
|
2013-06-19 14:26:55 +00:00
|
|
|
},
|
|
|
|
dialogGotModality: function (window) {
|
|
|
|
"use strict";
|
2018-09-10 19:12:21 +00:00
|
|
|
var mainWindows = window.mainWindows();
|
2018-10-25 16:59:22 +00:00
|
|
|
for (var i = 0; i < mainWindows.length; ++i) {
|
|
|
|
dialogParentEffect.startAnimation(mainWindows[i]);
|
2013-06-03 13:05:22 +00:00
|
|
|
}
|
|
|
|
},
|
2018-10-25 16:59:22 +00:00
|
|
|
startAnimation: function (window) {
|
2013-06-03 13:05:22 +00:00
|
|
|
"use strict";
|
|
|
|
if (window.visible === false) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 16:59:22 +00:00
|
|
|
if (window.dialogParentAnimation) {
|
|
|
|
if (redirect(window.dialogParentAnimation, Effect.Forward)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cancel(window.dialogParentAnimation);
|
|
|
|
}
|
2013-06-03 13:05:22 +00:00
|
|
|
window.dialogParentAnimation = set({
|
|
|
|
window: window,
|
2018-10-25 16:59:22 +00:00
|
|
|
duration: dialogParentEffect.duration,
|
|
|
|
keepAlive: false,
|
2013-06-03 13:05:22 +00:00
|
|
|
animations: [{
|
|
|
|
type: Effect.Saturation,
|
|
|
|
to: 0.4
|
|
|
|
}, {
|
|
|
|
type: Effect.Brightness,
|
|
|
|
to: 0.6
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
},
|
|
|
|
windowClosed: function (window) {
|
|
|
|
"use strict";
|
2018-10-25 16:59:22 +00:00
|
|
|
if (window.modal) {
|
|
|
|
dialogParentEffect.dialogLostModality(window);
|
2013-06-03 13:05:22 +00:00
|
|
|
}
|
2013-06-19 14:26:55 +00:00
|
|
|
},
|
|
|
|
dialogLostModality: function (window) {
|
|
|
|
"use strict";
|
2018-09-10 19:12:21 +00:00
|
|
|
var mainWindows = window.mainWindows();
|
2018-10-25 16:59:22 +00:00
|
|
|
for (var i = 0; i < mainWindows.length; ++i) {
|
|
|
|
dialogParentEffect.cancelAnimationSmooth(mainWindows[i]);
|
2013-06-03 13:05:22 +00:00
|
|
|
}
|
|
|
|
},
|
2018-10-25 16:59:22 +00:00
|
|
|
cancelAnimationInstant: function (window) {
|
2013-06-03 13:05:22 +00:00
|
|
|
"use strict";
|
2018-10-25 16:59:22 +00:00
|
|
|
if (window.dialogParentAnimation) {
|
2013-06-03 13:05:22 +00:00
|
|
|
cancel(window.dialogParentAnimation);
|
2018-10-25 16:59:22 +00:00
|
|
|
delete window.dialogParentAnimation;
|
2013-06-03 13:05:22 +00:00
|
|
|
}
|
|
|
|
},
|
2018-10-25 16:59:22 +00:00
|
|
|
cancelAnimationSmooth: function (window) {
|
|
|
|
"use strict";
|
|
|
|
if (!window.dialogParentAnimation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (redirect(window.dialogParentAnimation, Effect.Backward)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cancel(window.dialogParentAnimation);
|
|
|
|
delete window.dialogParentEffect;
|
|
|
|
},
|
2013-06-03 13:05:22 +00:00
|
|
|
desktopChanged: function () {
|
|
|
|
"use strict";
|
2018-10-25 16:59:22 +00:00
|
|
|
// If there is an active full screen effect, then try smoothly dim/brighten
|
|
|
|
// the main windows. Keep in mind that in order for this to work properly, this
|
|
|
|
// effect has to come after the full screen effect in the effect chain,
|
|
|
|
// otherwise this slot will be invoked before the full screen effect can mark
|
|
|
|
// itself as a full screen effect.
|
|
|
|
if (effects.hasActiveFullScreenEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var windows = effects.stackingOrder;
|
|
|
|
for (var i = 0; i < windows.length; ++i) {
|
|
|
|
var window = windows[i];
|
|
|
|
dialogParentEffect.cancelAnimationInstant(window);
|
2013-06-03 13:05:22 +00:00
|
|
|
dialogParentEffect.restartAnimation(window);
|
|
|
|
}
|
|
|
|
},
|
2013-06-19 14:26:55 +00:00
|
|
|
modalDialogChanged: function(dialog) {
|
|
|
|
"use strict";
|
|
|
|
if (dialog.modal === false)
|
|
|
|
dialogParentEffect.dialogLostModality(dialog);
|
|
|
|
else if (dialog.modal === true)
|
|
|
|
dialogParentEffect.dialogGotModality(dialog);
|
|
|
|
},
|
2013-06-03 13:05:22 +00:00
|
|
|
restartAnimation: function (window) {
|
|
|
|
"use strict";
|
|
|
|
if (window === null || window.findModal() === null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-25 16:59:22 +00:00
|
|
|
dialogParentEffect.startAnimation(window);
|
|
|
|
if (window.dialogParentAnimation) {
|
|
|
|
complete(window.dialogParentAnimation);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
activeFullScreenEffectChanged: function () {
|
|
|
|
"use strict";
|
|
|
|
var windows = effects.stackingOrder;
|
|
|
|
for (var i = 0; i < windows.length; ++i) {
|
|
|
|
var dialog = windows[i];
|
|
|
|
if (!dialog.modal) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (effects.hasActiveFullScreenEffect) {
|
|
|
|
dialogParentEffect.dialogLostModality(dialog);
|
|
|
|
} else {
|
|
|
|
dialogParentEffect.dialogGotModality(dialog);
|
|
|
|
}
|
|
|
|
}
|
2013-06-03 13:05:22 +00:00
|
|
|
},
|
|
|
|
init: function () {
|
|
|
|
"use strict";
|
|
|
|
var i, windows;
|
2013-06-19 14:26:55 +00:00
|
|
|
effects.windowAdded.connect(dialogParentEffect.windowAdded);
|
2013-06-03 13:05:22 +00:00
|
|
|
effects.windowClosed.connect(dialogParentEffect.windowClosed);
|
2018-10-25 16:59:22 +00:00
|
|
|
effects.windowMinimized.connect(dialogParentEffect.cancelAnimationInstant);
|
2013-06-03 13:05:22 +00:00
|
|
|
effects.windowUnminimized.connect(dialogParentEffect.restartAnimation);
|
2013-06-19 14:26:55 +00:00
|
|
|
effects.windowModalityChanged.connect(dialogParentEffect.modalDialogChanged)
|
2013-06-03 13:05:22 +00:00
|
|
|
effects['desktopChanged(int,int)'].connect(dialogParentEffect.desktopChanged);
|
2018-10-25 16:59:22 +00:00
|
|
|
effects.desktopPresenceChanged.connect(dialogParentEffect.cancelAnimationInstant);
|
2013-11-17 20:43:38 +00:00
|
|
|
effects.desktopPresenceChanged.connect(dialogParentEffect.restartAnimation);
|
2018-10-25 16:59:22 +00:00
|
|
|
effects.activeFullScreenEffectChanged.connect(
|
|
|
|
dialogParentEffect.activeFullScreenEffectChanged);
|
2013-06-03 13:05:22 +00:00
|
|
|
|
|
|
|
// start animation
|
|
|
|
windows = effects.stackingOrder;
|
|
|
|
for (i = 0; i < windows.length; i += 1) {
|
|
|
|
dialogParentEffect.restartAnimation(windows[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
dialogParentEffect.init();
|