Debian Codegraph @

src/plugins/fadingpopups/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: 2018 Vlad Zahorodnii <[email protected]>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 "use strict";
11
12 var blacklist = [
13 // ignore black background behind lockscreen
14 "ksmserver ksmserver",
15 // The logout screen has to be animated only by the logout effect.
16 "ksmserver-logout-greeter ksmserver-logout-greeter",
17 // The lockscreen isn't a popup window
18 "kscreenlocker_greet kscreenlocker_greet",
19 // KDE Plasma splash screen has to be animated only by the login effect.
20 "ksplashqml ksplashqml",
21 // Spectacle can trigger a screenshot from a popup menu
22 "spectacle org.kde.spectacle",
23 "spectacle spectacle",
24 ];
25
26 function isPopupWindow(window) {
27 // If the window is blacklisted, don't animate it.
28 if (blacklist.indexOf(window.windowClass) != -1) {
29 return false;
30 }
31
32 // Animate combo box popups, tooltips, popup menus, etc.
33 if (window.popupWindow) {
34 return true;
35 }
36
37 // Maybe the outline deserves its own effect.
38 if (window.outline) {
39 return true;
40 }
41
42 // Override-redirect windows are usually used for user interface
43 // concepts that are expected to be animated by this effect, e.g.
44 // popups that contain window thumbnails on X11, etc.
45 if (!window.managed) {
46 // Some utility windows can look like popup windows (e.g. the
47 // address bar dropdown in Firefox), but we don't want to fade
48 // them because the fade effect didn't do that.
49 if (window.utility) {
50 return false;
51 }
52
53 return true;
54 }
55
56 // Previously, there was a "monolithic" fade effect, which tried to
57 // animate almost every window that was shown or hidden. Then it was
58 // split into two effects: one that animates toplevel windows and
59 // this one. In addition to popups, this effect also animates some
60 // special windows(e.g. notifications) because the monolithic version
61 // was doing that.
62 if (window.splash || window.toolbar
63 || window.notification || window.onScreenDisplay
64 || window.criticalNotification
65 || window.appletPopup) {
66 return true;
67 }
68
69 return false;
70 }
71
72 var fadingPopupsEffect = {
73 loadConfig: function () {
74 fadingPopupsEffect.fadeInDuration = animationTime(150);
75 fadingPopupsEffect.fadeOutDuration = animationTime(150) * 4;
76 },
77 slotWindowAdded: function (window) {
78 if (effects.hasActiveFullScreenEffect) {
79 return;
80 }
81 if (!isPopupWindow(window)) {
82 return;
83 }
84 if (!window.visible) {
85 return;
86 }
87 if (!effect.grab(window, Effect.WindowAddedGrabRole)) {
88 return;
89 }
90 window.fadeInAnimation = animate({
91 window: window,
92 curve: QEasingCurve.Linear,
93 duration: fadingPopupsEffect.fadeInDuration,
94 type: Effect.Opacity,
95 from: 0.0,
96 to: 1.0
97 });
98 },
99 slotWindowClosed: function (window) {
100 if (effects.hasActiveFullScreenEffect) {
101 return;
102 }
103 if (!isPopupWindow(window)) {
104 return;
105 }
106 if (!window.visible || window.skipsCloseAnimation) {
107 return;
108 }
109 if (!effect.grab(window, Effect.WindowClosedGrabRole)) {
110 return;
111 }
112 window.fadeOutAnimation = animate({
113 window: window,
114 curve: QEasingCurve.OutQuart,
115 duration: fadingPopupsEffect.fadeOutDuration,
116 type: Effect.Opacity,
117 from: 1.0,
118 to: 0.0
119 });
120 },
121 slotWindowDataChanged: function (window, role) {
122 if (role == Effect.WindowAddedGrabRole) {
123 if (window.fadeInAnimation && effect.isGrabbed(window, role)) {
124 cancel(window.fadeInAnimation);
125 delete window.fadeInAnimation;
126 }
127 } else if (role == Effect.WindowClosedGrabRole) {
128 if (window.fadeOutAnimation && effect.isGrabbed(window, role)) {
129 cancel(window.fadeOutAnimation);
130 delete window.fadeOutAnimation;
131 }
132 }
133 },
134 init: function () {
135 fadingPopupsEffect.loadConfig();
136
137 effect.configChanged.connect(fadingPopupsEffect.loadConfig);
138 effects.windowAdded.connect(fadingPopupsEffect.slotWindowAdded);
139 effects.windowClosed.connect(fadingPopupsEffect.slotWindowClosed);
140 effects.windowDataChanged.connect(fadingPopupsEffect.slotWindowDataChanged);
141 }
142 };
143
144 fadingPopupsEffect.init();