Changeset View
Changeset View
Standalone View
Standalone View
effects/dialogparent/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) 2013 Martin Gräßlin <mgraesslin@kde.org> | 5 | Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> | ||
6 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | 7 | | |||
7 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | 11 | (at your option) any later version. | ||
11 | 12 | | |||
12 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 16 | GNU General Public License for more details. | ||
16 | 17 | | |||
17 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 20 | *********************************************************************/ | ||
20 | /*global effect, effects, animate, cancel, set, animationTime, Effect, QEasingCurve */ | 21 | /*global effect, effects, animate, cancel, set, animationTime, Effect, QEasingCurve */ | ||
21 | /*jslint continue: true */ | 22 | /*jslint continue: true */ | ||
22 | var dialogParentEffect = { | 23 | var dialogParentEffect = { | ||
23 | duration: animationTime(300), | 24 | duration: animationTime(300), | ||
24 | windowAdded: function (window) { | 25 | windowAdded: function (window) { | ||
25 | "use strict"; | 26 | "use strict"; | ||
26 | if (window === null || window.modal === false) { | 27 | if (window.modal) { | ||
27 | return; | 28 | dialogParentEffect.dialogGotModality(window); | ||
28 | } | 29 | } | ||
29 | dialogParentEffect.dialogGotModality(window) | | |||
30 | }, | 30 | }, | ||
31 | dialogGotModality: function (window) { | 31 | dialogGotModality: function (window) { | ||
32 | "use strict"; | 32 | "use strict"; | ||
33 | var mainWindows = window.mainWindows(); | 33 | var mainWindows = window.mainWindows(); | ||
34 | for (var i = 0; i < mainWindows.length; i += 1) { | 34 | for (var i = 0; i < mainWindows.length; ++i) { | ||
35 | var w = mainWindows[i]; | 35 | dialogParentEffect.startAnimation(mainWindows[i]); | ||
36 | if (w.dialogParentAnimation !== undefined) { | | |||
37 | continue; | | |||
38 | } | | |||
39 | dialogParentEffect.startAnimation(w, dialogParentEffect.duration); | | |||
40 | } | 36 | } | ||
41 | }, | 37 | }, | ||
42 | startAnimation: function (window, duration) { | 38 | startAnimation: function (window) { | ||
43 | "use strict"; | 39 | "use strict"; | ||
44 | if (window.visible === false) { | 40 | if (window.visible === false) { | ||
45 | return; | 41 | return; | ||
46 | } | 42 | } | ||
43 | if (window.dialogParentAnimation) { | ||||
44 | if (redirect(window.dialogParentAnimation, Effect.Forward)) { | ||||
45 | return; | ||||
46 | } | ||||
47 | cancel(window.dialogParentAnimation); | ||||
48 | } | ||||
47 | window.dialogParentAnimation = set({ | 49 | window.dialogParentAnimation = set({ | ||
48 | window: window, | 50 | window: window, | ||
49 | duration: duration, | 51 | duration: dialogParentEffect.duration, | ||
52 | keepAlive: false, | ||||
50 | animations: [{ | 53 | animations: [{ | ||
51 | type: Effect.Saturation, | 54 | type: Effect.Saturation, | ||
52 | to: 0.4 | 55 | to: 0.4 | ||
53 | }, { | 56 | }, { | ||
54 | type: Effect.Brightness, | 57 | type: Effect.Brightness, | ||
55 | to: 0.6 | 58 | to: 0.6 | ||
56 | }] | 59 | }] | ||
57 | }); | 60 | }); | ||
58 | }, | 61 | }, | ||
59 | windowClosed: function (window) { | 62 | windowClosed: function (window) { | ||
60 | "use strict"; | 63 | "use strict"; | ||
61 | dialogParentEffect.cancelAnimation(window); | 64 | if (window.modal) { | ||
62 | if (window.modal === false) { | | |||
63 | return; | | |||
64 | } | | |||
65 | dialogParentEffect.dialogLostModality(window); | 65 | dialogParentEffect.dialogLostModality(window); | ||
66 | } | ||||
66 | }, | 67 | }, | ||
67 | dialogLostModality: function (window) { | 68 | dialogLostModality: function (window) { | ||
68 | "use strict"; | 69 | "use strict"; | ||
69 | var mainWindows = window.mainWindows(); | 70 | var mainWindows = window.mainWindows(); | ||
70 | for (var i = 0; i < mainWindows.length; i += 1) { | 71 | for (var i = 0; i < mainWindows.length; ++i) { | ||
71 | var w = mainWindows[i]; | 72 | dialogParentEffect.cancelAnimationSmooth(mainWindows[i]); | ||
72 | if (w.dialogParentAnimation === undefined) { | | |||
73 | continue; | | |||
74 | } | | |||
75 | cancel(w.dialogParentAnimation); | | |||
76 | w.dialogParentAnimation = undefined; | | |||
77 | animate({ | | |||
78 | window: w, | | |||
79 | duration: dialogParentEffect.duration, | | |||
80 | keepAlive: false, | | |||
81 | animations: [{ | | |||
82 | type: Effect.Saturation, | | |||
83 | from: 0.4, | | |||
84 | to: 1.0 | | |||
85 | }, { | | |||
86 | type: Effect.Brightness, | | |||
87 | from: 0.6, | | |||
88 | to: 1.0 | | |||
89 | }] | | |||
90 | }); | | |||
91 | } | 73 | } | ||
92 | }, | 74 | }, | ||
93 | cancelAnimation: function (window) { | 75 | cancelAnimationInstant: function (window) { | ||
94 | "use strict"; | 76 | "use strict"; | ||
95 | if (window.dialogParentAnimation !== undefined) { | 77 | if (window.dialogParentAnimation) { | ||
96 | cancel(window.dialogParentAnimation); | 78 | cancel(window.dialogParentAnimation); | ||
97 | window.dialogParentAnimation = undefined; | 79 | delete window.dialogParentAnimation; | ||
98 | } | 80 | } | ||
99 | }, | 81 | }, | ||
82 | cancelAnimationSmooth: function (window) { | ||||
83 | "use strict"; | ||||
84 | if (!window.dialogParentAnimation) { | ||||
85 | return; | ||||
86 | } | ||||
87 | if (redirect(window.dialogParentAnimation, Effect.Backward)) { | ||||
88 | return; | ||||
89 | } | ||||
90 | cancel(window.dialogParentAnimation); | ||||
91 | delete window.dialogParentEffect; | ||||
92 | }, | ||||
100 | desktopChanged: function () { | 93 | desktopChanged: function () { | ||
101 | "use strict"; | 94 | "use strict"; | ||
102 | var i, windows, window; | 95 | // If there is an active full screen effect, then try smoothly dim/brighten | ||
103 | windows = effects.stackingOrder; | 96 | // the main windows. Keep in mind that in order for this to work properly, this | ||
104 | for (i = 0; i < windows.length; i += 1) { | 97 | // effect has to come after the full screen effect in the effect chain, | ||
105 | window = windows[i]; | 98 | // otherwise this slot will be invoked before the full screen effect can mark | ||
106 | dialogParentEffect.cancelAnimation(window); | 99 | // itself as a full screen effect. | ||
100 | if (effects.hasActiveFullScreenEffect) { | ||||
101 | return; | ||||
102 | } | ||||
103 | | ||||
104 | var windows = effects.stackingOrder; | ||||
105 | for (var i = 0; i < windows.length; ++i) { | ||||
106 | var window = windows[i]; | ||||
107 | dialogParentEffect.cancelAnimationInstant(window); | ||||
107 | dialogParentEffect.restartAnimation(window); | 108 | dialogParentEffect.restartAnimation(window); | ||
108 | } | 109 | } | ||
109 | }, | 110 | }, | ||
110 | modalDialogChanged: function(dialog) { | 111 | modalDialogChanged: function(dialog) { | ||
111 | "use strict"; | 112 | "use strict"; | ||
112 | if (dialog.modal === false) | 113 | if (dialog.modal === false) | ||
113 | dialogParentEffect.dialogLostModality(dialog); | 114 | dialogParentEffect.dialogLostModality(dialog); | ||
114 | else if (dialog.modal === true) | 115 | else if (dialog.modal === true) | ||
115 | dialogParentEffect.dialogGotModality(dialog); | 116 | dialogParentEffect.dialogGotModality(dialog); | ||
116 | }, | 117 | }, | ||
117 | restartAnimation: function (window) { | 118 | restartAnimation: function (window) { | ||
118 | "use strict"; | 119 | "use strict"; | ||
119 | if (window === null || window.findModal() === null) { | 120 | if (window === null || window.findModal() === null) { | ||
120 | return; | 121 | return; | ||
121 | } | 122 | } | ||
122 | dialogParentEffect.startAnimation(window, 1); | 123 | dialogParentEffect.startAnimation(window); | ||
124 | if (window.dialogParentAnimation) { | ||||
125 | complete(window.dialogParentAnimation); | ||||
126 | } | ||||
127 | }, | ||||
128 | activeFullScreenEffectChanged: function () { | ||||
129 | "use strict"; | ||||
130 | var windows = effects.stackingOrder; | ||||
131 | for (var i = 0; i < windows.length; ++i) { | ||||
132 | var dialog = windows[i]; | ||||
133 | if (!dialog.modal) { | ||||
134 | continue; | ||||
135 | } | ||||
136 | if (effects.hasActiveFullScreenEffect) { | ||||
137 | dialogParentEffect.dialogLostModality(dialog); | ||||
138 | } else { | ||||
139 | dialogParentEffect.dialogGotModality(dialog); | ||||
140 | } | ||||
141 | } | ||||
123 | }, | 142 | }, | ||
124 | init: function () { | 143 | init: function () { | ||
125 | "use strict"; | 144 | "use strict"; | ||
126 | var i, windows; | 145 | var i, windows; | ||
127 | effects.windowAdded.connect(dialogParentEffect.windowAdded); | 146 | effects.windowAdded.connect(dialogParentEffect.windowAdded); | ||
128 | effects.windowClosed.connect(dialogParentEffect.windowClosed); | 147 | effects.windowClosed.connect(dialogParentEffect.windowClosed); | ||
129 | effects.windowMinimized.connect(dialogParentEffect.cancelAnimation); | 148 | effects.windowMinimized.connect(dialogParentEffect.cancelAnimationInstant); | ||
130 | effects.windowUnminimized.connect(dialogParentEffect.restartAnimation); | 149 | effects.windowUnminimized.connect(dialogParentEffect.restartAnimation); | ||
131 | effects.windowModalityChanged.connect(dialogParentEffect.modalDialogChanged) | 150 | effects.windowModalityChanged.connect(dialogParentEffect.modalDialogChanged) | ||
132 | effects['desktopChanged(int,int)'].connect(dialogParentEffect.desktopChanged); | 151 | effects['desktopChanged(int,int)'].connect(dialogParentEffect.desktopChanged); | ||
133 | effects.desktopPresenceChanged.connect(dialogParentEffect.cancelAnimation); | 152 | effects.desktopPresenceChanged.connect(dialogParentEffect.cancelAnimationInstant); | ||
134 | effects.desktopPresenceChanged.connect(dialogParentEffect.restartAnimation); | 153 | effects.desktopPresenceChanged.connect(dialogParentEffect.restartAnimation); | ||
154 | effects.activeFullScreenEffectChanged.connect( | ||||
155 | dialogParentEffect.activeFullScreenEffectChanged); | ||||
135 | 156 | | |||
136 | // start animation | 157 | // start animation | ||
137 | windows = effects.stackingOrder; | 158 | windows = effects.stackingOrder; | ||
138 | for (i = 0; i < windows.length; i += 1) { | 159 | for (i = 0; i < windows.length; i += 1) { | ||
139 | dialogParentEffect.restartAnimation(windows[i]); | 160 | dialogParentEffect.restartAnimation(windows[i]); | ||
140 | } | 161 | } | ||
141 | } | 162 | } | ||
142 | }; | 163 | }; | ||
143 | dialogParentEffect.init(); | 164 | dialogParentEffect.init(); |