| 1 |
/* |
| 2 |
This file is part of the KDE project. |
| 3 |
|
| 4 |
SPDX-FileCopyrightText: 2013 Martin Gräßlin <[email protected]> |
| 5 |
|
| 6 |
SPDX-License-Identifier: GPL-2.0-or-later |
| 7 |
*/ |
| 8 |
/*global effect, effects, animate, cancel, set, animationTime, Effect, QEasingCurve */ |
| 9 |
|
| 10 |
"use strict"; |
| 11 |
|
| 12 |
var translucencyEffect = { |
| 13 |
activeWindow: effects.activeWindow, |
| 14 |
settings: { |
| 15 |
duration: animationTime(250), |
| 16 |
moveresize: 100, |
| 17 |
dialogs: 100, |
| 18 |
inactive: 100, |
| 19 |
comboboxpopups: 100, |
| 20 |
menus: 100, |
| 21 |
dropdownmenus: 100, |
| 22 |
popupmenus: 100, |
| 23 |
tornoffmenus: 100 |
| 24 |
}, |
| 25 |
loadConfig: function () { |
| 26 |
var i, individualMenu, windows; |
| 27 |
// TODO: add animation duration |
| 28 |
translucencyEffect.settings.moveresize = effect.readConfig("MoveResize", 80); |
| 29 |
translucencyEffect.settings.dialogs = effect.readConfig("Dialogs", 100); |
| 30 |
translucencyEffect.settings.inactive = effect.readConfig("Inactive", 100); |
| 31 |
translucencyEffect.settings.comboboxpopups = effect.readConfig("ComboboxPopups", 100); |
| 32 |
translucencyEffect.settings.menus = effect.readConfig("Menus", 100); |
| 33 |
individualMenu = effect.readConfig("IndividualMenuConfig", false); |
| 34 |
if (individualMenu === true) { |
| 35 |
translucencyEffect.settings.dropdownmenus = effect.readConfig("DropdownMenus", 100); |
| 36 |
translucencyEffect.settings.popupmenus = effect.readConfig("PopupMenus", 100); |
| 37 |
translucencyEffect.settings.tornoffmenus = effect.readConfig("TornOffMenus", 100); |
| 38 |
} else { |
| 39 |
translucencyEffect.settings.dropdownmenus = translucencyEffect.settings.menus; |
| 40 |
translucencyEffect.settings.popupmenus = translucencyEffect.settings.menus; |
| 41 |
translucencyEffect.settings.tornoffmenus = translucencyEffect.settings.menus; |
| 42 |
} |
| 43 |
|
| 44 |
windows = effects.stackingOrder; |
| 45 |
for (i = 0; i < windows.length; i += 1) { |
| 46 |
// stop all existing animations |
| 47 |
translucencyEffect.cancelAnimations(windows[i]); |
| 48 |
// schedule new animations based on new settings |
| 49 |
translucencyEffect.startAnimation(windows[i]); |
| 50 |
if (windows[i] !== effects.activeWindow) { |
| 51 |
translucencyEffect.inactive.animate(windows[i]); |
| 52 |
} |
| 53 |
} |
| 54 |
}, |
| 55 |
/** |
| 56 |
* @brief Starts the set animations depending on window type |
| 57 |
* |
| 58 |
*/ |
| 59 |
startAnimation: function (window) { |
| 60 |
var checkWindow = function (window, value) { |
| 61 |
if (value !== 100) { |
| 62 |
var ids = set({ |
| 63 |
window: window, |
| 64 |
duration: 1, |
| 65 |
animations: [{ |
| 66 |
type: Effect.Opacity, |
| 67 |
from: value / 100.0, |
| 68 |
to: value / 100.0 |
| 69 |
}] |
| 70 |
}); |
| 71 |
if (window.translucencyWindowTypeAnimation !== undefined) { |
| 72 |
cancel(window.translucencyWindowTypeAnimation); |
| 73 |
} |
| 74 |
window.translucencyWindowTypeAnimation = ids; |
| 75 |
} |
| 76 |
}; |
| 77 |
if (window.desktopWindow === true || window.dock === true || window.visible === false) { |
| 78 |
return; |
| 79 |
} |
| 80 |
if (window.dialog === true) { |
| 81 |
checkWindow(window, translucencyEffect.settings.dialogs); |
| 82 |
} else if (window.dropdownMenu === true) { |
| 83 |
checkWindow(window, translucencyEffect.settings.dropdownmenus); |
| 84 |
} else if (window.popupMenu === true) { |
| 85 |
checkWindow(window, translucencyEffect.settings.popupmenus); |
| 86 |
} else if (window.comboBox === true) { |
| 87 |
checkWindow(window, translucencyEffect.settings.comboboxpopups); |
| 88 |
} else if (window.menu === true) { |
| 89 |
checkWindow(window, translucencyEffect.settings.tornoffmenus); |
| 90 |
} |
| 91 |
}, |
| 92 |
/** |
| 93 |
* @brief Cancels all animations for window type and inactive window |
| 94 |
* |
| 95 |
*/ |
| 96 |
cancelAnimations: function (window) { |
| 97 |
if (window.translucencyWindowTypeAnimation !== undefined) { |
| 98 |
cancel(window.translucencyWindowTypeAnimation); |
| 99 |
window.translucencyWindowTypeAnimation = undefined; |
| 100 |
} |
| 101 |
if (window.translucencyInactiveAnimation !== undefined) { |
| 102 |
cancel(window.translucencyInactiveAnimation); |
| 103 |
window.translucencyInactiveAnimation = undefined; |
| 104 |
} |
| 105 |
if (window.translucencyMoveResizeAnimations !== undefined) { |
| 106 |
cancel(window.translucencyMoveResizeAnimations); |
| 107 |
window.translucencyMoveResizeAnimations = undefined; |
| 108 |
} |
| 109 |
}, |
| 110 |
moveResize: { |
| 111 |
start: function (window) { |
| 112 |
var ids; |
| 113 |
if (translucencyEffect.settings.moveresize === 100) { |
| 114 |
return; |
| 115 |
} |
| 116 |
ids = set({ |
| 117 |
window: window, |
| 118 |
duration: translucencyEffect.settings.duration, |
| 119 |
animations: [{ |
| 120 |
type: Effect.Opacity, |
| 121 |
to: translucencyEffect.settings.moveresize / 100.0 |
| 122 |
}] |
| 123 |
}); |
| 124 |
window.translucencyMoveResizeAnimations = ids; |
| 125 |
}, |
| 126 |
finish: function (window) { |
| 127 |
if (window.translucencyMoveResizeAnimations !== undefined) { |
| 128 |
// start revert animation |
| 129 |
animate({ |
| 130 |
window: window, |
| 131 |
duration: translucencyEffect.settings.duration, |
| 132 |
animations: [{ |
| 133 |
type: Effect.Opacity, |
| 134 |
from: translucencyEffect.settings.moveresize / 100.0 |
| 135 |
}] |
| 136 |
}); |
| 137 |
// and cancel previous animation |
| 138 |
cancel(window.translucencyMoveResizeAnimations); |
| 139 |
window.translucencyMoveResizeAnimations = undefined; |
| 140 |
} |
| 141 |
} |
| 142 |
}, |
| 143 |
inactive: { |
| 144 |
activated: function (window) { |
| 145 |
if (translucencyEffect.settings.inactive === 100) { |
| 146 |
return; |
| 147 |
} |
| 148 |
translucencyEffect.inactive.animate(translucencyEffect.activeWindow); |
| 149 |
translucencyEffect.activeWindow = window; |
| 150 |
if (window === null) { |
| 151 |
return; |
| 152 |
} |
| 153 |
if (window.translucencyInactiveAnimation !== undefined) { |
| 154 |
// start revert animation |
| 155 |
animate({ |
| 156 |
window: window, |
| 157 |
duration: translucencyEffect.settings.duration, |
| 158 |
animations: [{ |
| 159 |
type: Effect.Opacity, |
| 160 |
from: translucencyEffect.settings.inactive / 100.0 |
| 161 |
}] |
| 162 |
}); |
| 163 |
// and cancel previous animation |
| 164 |
cancel(window.translucencyInactiveAnimation); |
| 165 |
window.translucencyInactiveAnimation = undefined; |
| 166 |
} |
| 167 |
}, |
| 168 |
animate: function (window) { |
| 169 |
var ids; |
| 170 |
if (translucencyEffect.settings.inactive === 100) { |
| 171 |
return; |
| 172 |
} |
| 173 |
if (window === null) { |
| 174 |
return; |
| 175 |
} |
| 176 |
if (window === effects.activeWindow || |
| 177 |
window.popup === true || |
| 178 |
window.managed === false || |
| 179 |
window.desktopWindow === true || |
| 180 |
window.dock === true || |
| 181 |
window.visible === false || |
| 182 |
window.deleted === true) { |
| 183 |
return; |
| 184 |
} |
| 185 |
ids = set({ |
| 186 |
window: window, |
| 187 |
duration: translucencyEffect.settings.duration, |
| 188 |
animations: [{ |
| 189 |
type: Effect.Opacity, |
| 190 |
to: translucencyEffect.settings.inactive / 100.0 |
| 191 |
}] |
| 192 |
}); |
| 193 |
window.translucencyInactiveAnimation = ids; |
| 194 |
} |
| 195 |
}, |
| 196 |
desktopChanged: function () { |
| 197 |
var i, windows; |
| 198 |
windows = effects.stackingOrder; |
| 199 |
for (i = 0; i < windows.length; i += 1) { |
| 200 |
translucencyEffect.cancelAnimations(windows[i]); |
| 201 |
translucencyEffect.startAnimation(windows[i]); |
| 202 |
if (windows[i] !== effects.activeWindow) { |
| 203 |
translucencyEffect.inactive.animate(windows[i]); |
| 204 |
} |
| 205 |
} |
| 206 |
}, |
| 207 |
manage: function (window) { |
| 208 |
window.windowDesktopsChanged.connect(translucencyEffect.cancelAnimations); |
| 209 |
window.windowDesktopsChanged.connect(translucencyEffect.startAnimation); |
| 210 |
window.windowStartUserMovedResized.connect(translucencyEffect.moveResize.start); |
| 211 |
window.windowFinishUserMovedResized.connect(translucencyEffect.moveResize.finish); |
| 212 |
|
| 213 |
window.minimizedChanged.connect(() => { |
| 214 |
if (window.minimized) { |
| 215 |
translucencyEffect.cancelAnimations(); |
| 216 |
} else { |
| 217 |
translucencyEffect.startAnimation(window); |
| 218 |
translucencyEffect.inactive.animate(window); |
| 219 |
} |
| 220 |
}); |
| 221 |
}, |
| 222 |
init: function () { |
| 223 |
effect.configChanged.connect(translucencyEffect.loadConfig); |
| 224 |
effects.windowAdded.connect(translucencyEffect.manage); |
| 225 |
effects.windowAdded.connect(translucencyEffect.startAnimation); |
| 226 |
effects.windowClosed.connect(translucencyEffect.cancelAnimations); |
| 227 |
effects.windowActivated.connect(translucencyEffect.inactive.activated); |
| 228 |
effects.desktopChanged.connect(translucencyEffect.desktopChanged); |
| 229 |
|
| 230 |
for (const window of effects.stackingOrder) { |
| 231 |
translucencyEffect.manage(window); |
| 232 |
} |
| 233 |
|
| 234 |
translucencyEffect.loadConfig(); |
| 235 |
} |
| 236 |
}; |
| 237 |
translucencyEffect.init(); |