Changeset View
Standalone View
effects/fadedesktop/package/contents/code/main.js
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com> | 5 | Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com> | ||
6 | Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org> | 6 | Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org> | ||
7 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
7 | 8 | | |||
8 | This program is free software; you can redistribute it and/or modify | 9 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | 10 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | 11 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | 12 | (at your option) any later version. | ||
12 | 13 | | |||
13 | This program is distributed in the hope that it will be useful, | 14 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | 17 | GNU General Public License for more details. | ||
17 | 18 | | |||
18 | You should have received a copy of the GNU General Public License | 19 | You should have received a copy of the GNU General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | *********************************************************************/ | 21 | *********************************************************************/ | ||
21 | var duration; | 22 | | ||
22 | function loadConfig() { | 23 | "use strict"; | ||
23 | duration = animationTime(250); | 24 | | ||
24 | } | 25 | var fadeDesktopEffect = { | ||
davidedmundson: In QJSEngine, we can just write "use strict" once at the top of the file and it will apply for… | |||||
25 | loadConfig(); | 26 | duration: animationTime(250), | ||
26 | effect.configChanged.connect(function() { | 27 | loadConfig: function () { | ||
27 | loadConfig(); | 28 | fadeDesktopEffect.duration = animationTime(250); | ||
One of the reasons we said redirect should have an absolute direction rather than "reverse" was so that we can squash this code into something more like: fadeWindow(window, direction) { if (window.animation) { redirect(window.animation, direction); } else { window.animation = animate(....); redirect(window, direction); } } which IMHO would be a lot easier to read compared to two functions which have to handle 3 possible states of existing animations. davidedmundson: One of the reasons we said redirect should have an absolute direction rather than "reverse" was… | |||||
We don't delete window.animation, so we can't just simply redirect the animation. Also, from the API standpoint, redirect() can return false, which means it couldn't redirect the animation and some further actions have to be taken (e.g. cancel the animation). In order to delete window.animation, I assume we need some inspection mechanism to figure out whether all animations has finished. zzag: We don't delete `window.animation`, so we can't just simply redirect the animation.
Also, from… | |||||
effect.animationEnded.connect(function(window) { delete window.animation; }); (And if we were doing multiple animations in an array then we change the above code to remove the array entry and delete the property if it's empty) davidedmundson: >In order to delete window.animation
effect.animationEnded.connect(function(window) {… | |||||
zzag: Oh, I forgot that there's the second parameter. | |||||
Well, we still need if (window.animation) { if (redirect(window.animation, Effect.SomewhereIBelong) { return; } cancel(window.animation); } window.animation = animate({ ... }); because redirect can fail. It most likely won't happen, but we still need to handle such cases. zzag: Well, we still need
```lang=cpp
if (window.animation) {
if (redirect(window.animation… | |||||
AFAIK it can only fail if you call redirect inside a slot directly connected to animationEnded but sure, we can have that check. davidedmundson: AFAIK it can only fail if you call redirect inside a slot directly connected to animationEnded… | |||||
29 | }, | ||||
30 | fadeInWindow: function (window) { | ||||
31 | if (window.fadeOutAnimation) { | ||||
32 | if (redirect(window.fadeOutAnimation, Effect.Backward)) { | ||||
33 | return; | ||||
34 | } | ||||
35 | cancel(window.fadeOutAnimation); | ||||
36 | delete window.fadeOutAnimation; | ||||
37 | } | ||||
38 | if (window.fadeInAnimation) { | ||||
39 | if (redirect(window.fadeInAnimation, Effect.Forward)) { | ||||
40 | return; | ||||
41 | } | ||||
42 | cancel(window.fadeInAnimation); | ||||
43 | } | ||||
44 | window.fadeInAnimation = animate({ | ||||
45 | window: window, | ||||
46 | curve: QEasingCurve.Linear, | ||||
47 | duration: fadeDesktopEffect.duration, | ||||
48 | fullScreen: true, | ||||
49 | keepAlive: false, | ||||
50 | type: Effect.Opacity, | ||||
51 | from: 0.0, | ||||
52 | to: 1.0 | ||||
28 | }); | 53 | }); | ||
29 | effects['desktopChanged(int,int,KWin::EffectWindow*)'].connect(function(oldDesktop, newDesktop, movingWindow) { | 54 | }, | ||
55 | fadeOutWindow: function (window) { | ||||
56 | if (window.fadeInAnimation) { | ||||
57 | if (redirect(window.fadeInAnimation, Effect.Backward)) { | ||||
58 | return; | ||||
59 | } | ||||
60 | cancel(window.fadeInAnimation); | ||||
61 | delete window.fadeInAnimation; | ||||
62 | } | ||||
63 | if (window.fadeOutAnimation) { | ||||
64 | if (redirect(window.fadeOutAnimation, Effect.Forward)) { | ||||
65 | return; | ||||
66 | } | ||||
67 | cancel(window.fadeOutAnimation); | ||||
68 | } | ||||
69 | window.fadeOutAnimation = animate({ | ||||
70 | window: window, | ||||
71 | curve: QEasingCurve.Linear, | ||||
72 | duration: fadeDesktopEffect.duration, | ||||
73 | fullScreen: true, | ||||
74 | keepAlive: false, | ||||
75 | type: Effect.Opacity, | ||||
76 | from: 1.0, | ||||
77 | to: 0.0 | ||||
78 | }); | ||||
79 | }, | ||||
80 | slotDesktopChanged: function (oldDesktop, newDesktop, movingWindow) { | ||||
30 | if (effects.hasActiveFullScreenEffect && !effect.isActiveFullScreenEffect) { | 81 | if (effects.hasActiveFullScreenEffect && !effect.isActiveFullScreenEffect) { | ||
31 | return; | 82 | return; | ||
32 | } | 83 | } | ||
84 | | ||||
33 | var stackingOrder = effects.stackingOrder; | 85 | var stackingOrder = effects.stackingOrder; | ||
34 | for (var i = 0; i < stackingOrder.length; i++) { | 86 | for (var i = 0; i < stackingOrder.length; ++i) { | ||
35 | var w = stackingOrder[i]; | 87 | var w = stackingOrder[i]; | ||
36 | 88 | | |||
37 | // Don't animate windows that have been moved to the current | 89 | // Don't animate windows that have been moved to the current | ||
38 | // desktop, i.e. newDesktop. | 90 | // desktop, i.e. newDesktop. | ||
39 | if (w == movingWindow) { | 91 | if (w == movingWindow) { | ||
40 | continue; | 92 | continue; | ||
41 | } | 93 | } | ||
42 | 94 | | |||
Show All 9 Lines | 103 | if (w.minimized) { | |||
52 | continue; | 104 | continue; | ||
53 | } | 105 | } | ||
54 | 106 | | |||
55 | if (!w.isOnActivity(effects.currentActivity)){ | 107 | if (!w.isOnActivity(effects.currentActivity)){ | ||
56 | continue; | 108 | continue; | ||
57 | } | 109 | } | ||
58 | 110 | | |||
59 | if (onOldDesktop) { | 111 | if (onOldDesktop) { | ||
60 | animate({ | 112 | fadeDesktopEffect.fadeOutWindow(w); | ||
61 | window: w, | | |||
62 | duration: duration, | | |||
63 | animations: [{ | | |||
64 | type: Effect.Opacity, | | |||
65 | to: 0.0, | | |||
66 | fullScreen: true | | |||
67 | }] | | |||
68 | }); | | |||
69 | } else { | 113 | } else { | ||
70 | animate({ | 114 | fadeDesktopEffect.fadeInWindow(w); | ||
71 | window: w, | | |||
72 | duration: duration, | | |||
73 | animations: [{ | | |||
74 | type: Effect.Opacity, | | |||
75 | to: 1.0, | | |||
76 | from: 0.0, | | |||
77 | fullScreen: true | | |||
78 | }] | | |||
79 | }); | | |||
80 | } | 115 | } | ||
81 | } | 116 | } | ||
82 | }); | 117 | }, | ||
83 | 118 | slotIsActiveFullScreenEffectChanged: function () { | |||
84 | effect.isActiveFullScreenEffectChanged.connect(function() { | | |||
85 | var isActiveFullScreen = effect.isActiveFullScreenEffect; | 119 | var isActiveFullScreen = effect.isActiveFullScreenEffect; | ||
86 | var stackingOrder = effects.stackingOrder; | 120 | var stackingOrder = effects.stackingOrder; | ||
87 | for (var i = 0; i < stackingOrder.length; i++) { | 121 | for (var i = 0; i < stackingOrder.length; ++i) { | ||
88 | var w = stackingOrder[i]; | 122 | var w = stackingOrder[i]; | ||
89 | w.setData(Effect.WindowForceBlurRole, isActiveFullScreen); | 123 | w.setData(Effect.WindowForceBlurRole, isActiveFullScreen); | ||
90 | w.setData(Effect.WindowForceBackgroundContrastRole, isActiveFullScreen); | 124 | w.setData(Effect.WindowForceBackgroundContrastRole, isActiveFullScreen); | ||
91 | } | 125 | } | ||
92 | }); | 126 | }, | ||
127 | init: function () { | ||||
128 | effect.configChanged.connect(fadeDesktopEffect.loadConfig); | ||||
129 | effect.isActiveFullScreenEffectChanged.connect( | ||||
130 | fadeDesktopEffect.slotIsActiveFullScreenEffectChanged); | ||||
131 | effects['desktopChanged(int,int,KWin::EffectWindow*)'].connect( | ||||
132 | fadeDesktopEffect.slotDesktopChanged); | ||||
133 | } | ||||
134 | }; | ||||
135 | | ||||
136 | fadeDesktopEffect.init(); |
In QJSEngine, we can just write "use strict" once at the top of the file and it will apply for all functions.
I haven't tested QtScript, but I would be surprised if it's different.