Changeset View
Changeset View
Standalone View
Standalone View
effects/frozenapp/package/contents/code/main.js
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
6 | | ||||
7 | 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 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | 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 | *********************************************************************/ | ||||
20 | /*global effect, effects, animate, animationTime, Effect*/ | ||||
21 | var frozenAppEffect = { | ||||
22 | inDuration: animationTime(1500), | ||||
23 | outDuration: animationTime(250), | ||||
24 | loadConfig: function () { | ||||
25 | "use strict"; | ||||
26 | frozenAppEffect.inDuration = animationTime(1500); | ||||
27 | frozenAppEffect.outDuration = animationTime(250); | ||||
28 | }, | ||||
29 | windowAdded: function (window) { | ||||
30 | "use strict"; | ||||
31 | if (!window || !window.unresponsive) { | ||||
32 | return; | ||||
33 | } | ||||
34 | frozenAppEffect.windowBecameUnresponsive(window); | ||||
35 | }, | ||||
36 | windowBecameUnresponsive: function (window) { | ||||
37 | "use strict"; | ||||
38 | if (window.unresponsiveAnimation) { | ||||
39 | return; | ||||
40 | } | ||||
41 | frozenAppEffect.startAnimation(window, frozenAppEffect.inDuration); | ||||
42 | }, | ||||
43 | startAnimation: function (window, duration) { | ||||
44 | "use strict"; | ||||
45 | if (!window.visible) { | ||||
46 | return; | ||||
47 | } | ||||
48 | window.unresponsiveAnimation = set({ | ||||
49 | window: window, | ||||
50 | duration: duration, | ||||
51 | animations: [{ | ||||
52 | type: Effect.Saturation, | ||||
53 | to: 0.1 | ||||
54 | }, { | ||||
55 | type: Effect.Brightness, | ||||
56 | to: 1.5 | ||||
57 | }] | ||||
58 | }); | ||||
59 | }, | ||||
60 | windowClosed: function (window) { | ||||
61 | "use strict"; | ||||
62 | frozenAppEffect.cancelAnimation(window); | ||||
63 | if (!window.unresponsive) { | ||||
64 | return; | ||||
65 | } | ||||
66 | frozenAppEffect.windowBecameResponsive(window); | ||||
67 | }, | ||||
68 | windowBecameResponsive: function (window) { | ||||
69 | "use strict"; | ||||
70 | if (!window.unresponsiveAnimation) { | ||||
71 | return; | ||||
72 | } | ||||
73 | cancel(window.unresponsiveAnimation); | ||||
74 | window.unresponsiveAnimation = undefined; | ||||
75 | | ||||
76 | animate({ | ||||
77 | window: window, | ||||
78 | duration: frozenAppEffect.outDuration, | ||||
79 | animations: [{ | ||||
80 | type: Effect.Saturation, | ||||
81 | from: 0.1, | ||||
82 | to: 1.0 | ||||
83 | }, { | ||||
84 | type: Effect.Brightness, | ||||
85 | from: 1.5, | ||||
86 | to: 1.0 | ||||
87 | }] | ||||
88 | }); | ||||
89 | }, | ||||
90 | cancelAnimation: function (window) { | ||||
91 | "use strict"; | ||||
92 | if (window.unresponsiveAnimation) { | ||||
93 | print(window); | ||||
94 | cancel(window.unresponsiveAnimation); | ||||
95 | window.unresponsiveAnimation = undefined; | ||||
96 | } | ||||
97 | }, | ||||
98 | desktopChanged: function () { | ||||
99 | "use strict"; | ||||
100 | | ||||
101 | var windows = effects.stackingOrder; | ||||
102 | for (var i = 0, length = windows.length; i < length; ++i) { | ||||
103 | print(i); | ||||
104 | var window = windows[i]; | ||||
105 | frozenAppEffect.cancelAnimation(window); | ||||
106 | frozenAppEffect.restartAnimation(window); | ||||
107 | } | ||||
108 | }, | ||||
109 | unresponsiveChanged: function (window) { | ||||
110 | "use strict"; | ||||
111 | if (window.unresponsive) { | ||||
112 | frozenAppEffect.windowBecameUnresponsive(window); | ||||
113 | } else { | ||||
114 | frozenAppEffect.windowBecameResponsive(window); | ||||
115 | } | ||||
116 | }, | ||||
117 | restartAnimation: function (window) { | ||||
118 | "use strict"; | ||||
119 | if (!window || !window.unresponsive) { | ||||
120 | return; | ||||
121 | } | ||||
122 | frozenAppEffect.startAnimation(window, 1); | ||||
123 | }, | ||||
124 | init: function () { | ||||
125 | "use strict"; | ||||
126 | | ||||
127 | effects.windowAdded.connect(frozenAppEffect.windowAdded); | ||||
128 | effects.windowClosed.connect(frozenAppEffect.windowClosed); | ||||
129 | effects.windowMinimized.connect(frozenAppEffect.cancelAnimation); | ||||
130 | effects.windowUnminimized.connect(frozenAppEffect.restartAnimation); | ||||
131 | effects.windowUnresponsiveChanged.connect(frozenAppEffect.unresponsiveChanged); | ||||
132 | effects['desktopChanged(int,int)'].connect(frozenAppEffect.desktopChanged); | ||||
133 | effects.desktopPresenceChanged.connect(frozenAppEffect.cancelAnimation); | ||||
134 | effects.desktopPresenceChanged.connect(frozenAppEffect.restartAnimation); | ||||
135 | | ||||
136 | var windows = effects.stackingOrder; | ||||
137 | for (var i = 0, length = windows.length; i < length; ++i) { | ||||
138 | frozenAppEffect.restartAnimation(windows[i]); | ||||
139 | } | ||||
140 | } | ||||
141 | }; | ||||
142 | frozenAppEffect.init(); |