Debian Codegraph @

src/plugins/dialogparent/package/contents/code/main.js

raw symbols SCIP
1 /*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2013 Martin Gräßlin <[email protected]g>
6 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <[email protected]>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 /*global effect, effects, animate, cancel, set, animationTime, Effect, QEasingCurve */
11 /*jslint continue: true */
12 var dialogParentEffect = {
13 duration: animationTime(300),
14 windowAdded: function (window) {
15 "use strict";
16 window.minimizedChanged.connect(() => {
17 if (window.minimized) {
18 dialogParentEffect.cancelAnimationInstant(window);
19 } else {
20 dialogParentEffect.restartAnimation(window);
21 }
22 });
23 window.windowModalityChanged.connect(dialogParentEffect.windowModalityChanged);
24 window.windowDesktopsChanged.connect(dialogParentEffect.cancelAnimationInstant);
25 window.windowDesktopsChanged.connect(dialogParentEffect.restartAnimation);
26
27 if (window.modal) {
28 dialogParentEffect.dialogGotModality(window);
29 }
30 },
31 dialogGotModality: function (window) {
32 "use strict";
33 var mainWindows = window.mainWindows();
34 for (var i = 0; i < mainWindows.length; ++i) {
35 dialogParentEffect.startAnimation(mainWindows[i]);
36 }
37 },
38 startAnimation: function (window) {
39 "use strict";
40 if (window.visible === false) {
41 return;
42 }
43 if (window.dialogParentAnimation) {
44 if (redirect(window.dialogParentAnimation, Effect.Forward)) {
45 return;
46 }
47 cancel(window.dialogParentAnimation);
48 }
49 window.dialogParentAnimation = set({
50 window: window,
51 duration: dialogParentEffect.duration,
52 keepAlive: false,
53 animations: [{
54 type: Effect.Saturation,
55 to: 0.4
56 }, {
57 type: Effect.Brightness,
58 to: 0.6
59 }]
60 });
61 },
62 windowClosed: function (window) {
63 "use strict";
64 if (window.modal) {
65 dialogParentEffect.dialogLostModality(window);
66 }
67 },
68 dialogLostModality: function (window) {
69 "use strict";
70 var mainWindows = window.mainWindows();
71 for (var i = 0; i < mainWindows.length; ++i) {
72 dialogParentEffect.cancelAnimationSmooth(mainWindows[i]);
73 }
74 },
75 cancelAnimationInstant: function (window) {
76 "use strict";
77 if (window.dialogParentAnimation) {
78 cancel(window.dialogParentAnimation);
79 delete window.dialogParentAnimation;
80 }
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 },
93 desktopChanged: function () {
94 "use strict";
95 // If there is an active full screen effect, then try smoothly dim/brighten
96 // the main windows. Keep in mind that in order for this to work properly, this
97 // effect has to come after the full screen effect in the effect chain,
98 // otherwise this slot will be invoked before the full screen effect can mark
99 // itself as a full screen effect.
100 if (dialogParentEffect.globallyInhibited()) {
101 return;
102 }
103
104 const windows = effects.stackingOrder;
105 for (const window of windows) {
106 dialogParentEffect.cancelAnimationInstant(window);
107 dialogParentEffect.restartAnimation(window);
108 }
109 },
110 windowModalityChanged: function (window) {
111 "use strict";
112 dialogParentEffect.refreshWindowEffect(window);
113 },
114 restartAnimation: function (window) {
115 "use strict";
116 if (window === null || window.findModal() === null) {
117 return;
118 }
119 dialogParentEffect.startAnimation(window);
120 if (window.dialogParentAnimation) {
121 complete(window.dialogParentAnimation);
122 }
123 },
124 activeFullScreenOrColorPickerChanged: function () {
125 "use strict";
126 const windows = effects.stackingOrder;
127 for (const window of windows) {
128 dialogParentEffect.refreshWindowEffect(window);
129 }
130 },
131 globallyInhibited: function () {
132 return effects.hasActiveFullScreenEffect || effects.colorPickerActive;
133 },
134 refreshWindowEffect: function (window) {
135 if (dialogParentEffect.globallyInhibited() || !window.modal) {
136 dialogParentEffect.dialogLostModality(window);
137 } else {
138 dialogParentEffect.dialogGotModality(window);
139 }
140 },
141 init: function () {
142 "use strict";
143 var i, windows;
144 effects.windowAdded.connect(dialogParentEffect.windowAdded);
145 effects.windowClosed.connect(dialogParentEffect.windowClosed);
146 effects.desktopChanged.connect(dialogParentEffect.desktopChanged);
147 effects.activeFullScreenEffectChanged.connect(
148 dialogParentEffect.activeFullScreenOrColorPickerChanged);
149 effects.colorPickerActiveChanged.connect(
150 dialogParentEffect.activeFullScreenOrColorPickerChanged);
151
152 windows = effects.stackingOrder;
153 for (i = 0; i < windows.length; i += 1) {
154 dialogParentEffect.windowAdded(windows[i]);
155 }
156 }
157 };
158 dialogParentEffect.init();