| 1 | // SPDX-FileCopyrightText: Vlad Zahorodnii <vlad.zahorodnii@kde.org>, Martin Flöser |
| 2 | // <mgraesslin@kde.org>, Simon Schneegans <code@simonschneegans.de> |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | 'use strict'; |
| 6 | |
| 7 | const classBlacklist = [ |
| 8 | // The logout screen has to be animated only by the logout effect. |
| 9 | 'ksmserver ksmserver', 'ksmserver-logout-greeter ksmserver-logout-greeter', |
| 10 | |
| 11 | // KDE Plasma splash screen has to be animated only by the login effect. |
| 12 | 'ksplashqml ksplashqml', |
| 13 | |
| 14 | // All the tooltips of IntelliJ IDEs use the same window class as their main window. |
| 15 | // This results in many awkward animations, so we have to blacklist them all. |
| 16 | // See https://github.com/Schneegans/Burn-My-Windows/issues/284 for details. |
| 17 | 'jetbrains-studio jetbrains-studio', 'jetbrains-aqua jetbrains-aqua', |
| 18 | 'jetbrains-clion jetbrains-clion', 'jetbrains-datagrip jetbrains-datagrip', |
| 19 | 'jetbrains-dataspell jetbrains-dataspell', 'jetbrains-goland jetbrains-goland', |
| 20 | 'jetbrains-idea jetbrains-idea', 'jetbrains-idea-ce jetbrains-idea-ce', |
| 21 | 'jetbrains-phpstorm jetbrains-phpstorm', 'jetbrains-pycharm jetbrains-pycharm', |
| 22 | 'jetbrains-pycharm-ce jetbrains-pycharm-ce', 'jetbrains-rider jetbrains-rider', |
| 23 | 'jetbrains-rubymine jetbrains-rubymine', 'jetbrains-webstorm jetbrains-webstorm', |
| 24 | |
| 25 | // Spectacle (KDE screenshot tool) should not be animated. |
| 26 | 'spectacle org.kde.spectacle' |
| 27 | ]; |
| 28 | |
| 29 | const nameBlacklist = [ |
| 30 | // Kando uses a normal window, but it should look like a popup menu. We do not |
| 31 | // blacklist it by class as this would also affect the settings window. |
| 32 | 'Kando Menu' |
| 33 | ]; |
| 34 | |
| 35 | class BurnMyWindowsMarbleMinimizeEffect { |
| 36 | constructor() { |
| 37 | effect.configChanged.connect(this.loadConfig.bind(this)); |
| 38 | effect.animationEnded.connect(this.cleanupForcedRoles.bind(this)); |
| 39 | effect.animationEnded.connect(this.slotAnimationEnded.bind(this)); |
| 40 | //effects.windowAdded.connect(this.slotWindowAdded.bind(this)); |
| 41 | const hook = (w) => { |
| 42 | w.minimizedChanged.connect(() => { |
| 43 | if (w.minimized) this.slotWindowMinimized(w); else this.slotWindowUnminimized(w); |
| 44 | }); |
| 45 | }; |
| 46 | effects.windowAdded.connect(hook); |
| 47 | for (const w of effects.stackingOrder) hook(w); |
| 48 | effects.windowDataChanged.connect(this.slotWindowDataChanged.bind(this)); |
| 49 | |
| 50 | this.shader = effect.addFragmentShader(Effect.MapTexture, 'marble.frag'); |
| 51 | |
| 52 | this.loadConfig(); |
| 53 | } |
| 54 | |
| 55 | // A small helper which can be used to read a hex color string (e.g. #ff3244) from the |
| 56 | // settings. This method will return an array of four floating point values |
| 57 | // [r, g, b, a]. If the settings key only refers to an rgb value, the alpha component |
| 58 | // will be set to 1.0. |
| 59 | readRGBAConfig(key) { |
| 60 | const raw = String(effect.readConfig(key, '#ffffff')); |
| 61 | const parts = raw.split(',').map(x => parseFloat(x.trim())); |
| 62 | if (parts.length >= 3 && parts.every(x => !isNaN(x))) { |
| 63 | const c = parts.map(x => x / 255); |
| 64 | return [c[0], c[1], c[2], c.length > 3 ? c[3] : 1.0]; |
| 65 | } |
| 66 | const color = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?([a-f\d]{2})?$/i |
| 67 | .exec(effect.readConfig(key, '#ffffff')) |
| 68 | .slice(1) |
| 69 | .filter(x => x !== undefined) |
| 70 | .map(x => parseInt(x, 16) / 255); |
| 71 | return color.length == 3 ? [color[0], color[1], color[2], 1.0] : |
| 72 | [color[1], color[2], color[3], color[0]]; |
| 73 | } |
| 74 | |
| 75 | // A small helper which can be used to read a hex color string (e.g. #ff3244) from the |
| 76 | // settings. This method will return an array of three floating point values [r, g, b] |
| 77 | // regardless of whether the settings key actually refers to an argb hex string. |
| 78 | readRGBConfig(key) { |
| 79 | const color = this.readRGBAConfig(key); |
| 80 | color.pop(); |
| 81 | return color; |
| 82 | } |
| 83 | |
| 84 | // This is called when the effect is loaded and whenever the settings of the effect |
| 85 | // are changed by the user. |
| 86 | loadConfig() { |
| 87 | this.duration = animationTime(effect.readConfig("Duration", 200)); |
| 88 | this.pause = animationTime(Number(effect.readConfig("Pause", 300))); |
| 89 | this.gravity = Math.max(100, Number(effect.readConfig('Gravity', 4500))); // px/s^2 |
| 90 | let sh = 1080; |
| 91 | try { sh = effects.virtualScreenGeometry.height || sh; } catch (e) {} |
| 92 | this.fallDistance = 1.5 * sh; |
| 93 | // free fall from rest: d = 0.5 g t^2 -> t = sqrt(2d/g); scaled by the global speed factor |
| 94 | this.fallDuration = animationTime(Math.round(1000 * Math.sqrt(2 * this.fallDistance / this.gravity))); |
| 95 | effect.setUniform(this.shader, 'uDuration', (this.duration + this.pause + this.fallDuration) * 0.001); |
| 96 | // 0..10 named colours, 11 = Willekeurig, 12 = Semiwillekeurig. Older >12 → 12. |
| 97 | let mc = Math.floor(Number(effect.readConfig('MixColor', 12))); |
| 98 | if (!(mc >= 0)) mc = 0; else if (mc > 12) mc = 12; |
| 99 | this.tintMode = mc; |
| 100 | // Drop per-class cache when settings reload (MixColor / speed etc. may change). |
| 101 | this.classHueCache = Object.create(null); |
| 102 | this.applyTint(null, false); |
| 103 | effect.setUniform(this.shader, 'uMarbleSize', Math.max(4, Number(effect.readConfig('MarbleSize', 42)))); |
| 104 | this.debug = Math.max(0, Number(effect.readConfig('DebugMarble', 0)) | 0); |
| 105 | effect.setUniform(this.shader, 'uDebug', this.debug); |
| 106 | effect.setUniform(this.shader, 'uMixOuter', Math.min(100, Math.max(0, Number(effect.readConfig('BlackMixOuter', 80)))) / 100); |
| 107 | effect.setUniform(this.shader, 'uMixCenter', Math.min(100, Math.max(0, Number(effect.readConfig('BlackMixCenter', 5)))) / 100); |
| 108 | effect.setUniform(this.shader, 'uCrumpleEnd', this.duration / Math.max(1, this.duration + this.pause + this.fallDuration)); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | // Mix target. tintMode 0..10 = named colours; 11 = Willekeurig (seq → hue); |
| 113 | // 12 = Semiwillekeurig (hash of window.windowClass → hue). Random modes use HSV |
| 114 | // with fixed S=1 and V=0.6667 (matches the named #aa… glass colours), not a palette. |
| 115 | // Final RGB is computed once in JS (and cached per windowClass for mode 12); the shader |
| 116 | // only indexes a precomputed hue→RGB table — never runs HSV per fragment. |
| 117 | // Single-channel pack: uProgress = tintId + morph01*0.999 (tintId 0..10 or 1000..1359). |
| 118 | // Callers may still pass overshoot m (m_to = 1/crumpleEnd); values m>=1 encode as morph=1. |
| 119 | // Shader restores timing with uCrumpleEnd: c = raw/(uCrumpleEnd*0.999). No second ShaderUniform. |
| 120 | prog(window, m) { |
| 121 | const tid = (window && window.bmwTintId >= 0) ? window.bmwTintId : (window ? (window.bmwBase || 0) : 0); |
| 122 | const morph = Math.min(1, Math.max(0, m)); |
| 123 | const v = tid + morph * 0.999; |
| 124 | if (this.debug) console.log('MARBLEDBG prog caption=' + window.caption + ' m=' + m + ' morph=' + morph + ' v=' + v + ' tintId=' + tid); |
| 125 | return v; |
| 126 | } |
| 127 | |
| 128 | hsvToRgb(h, s, v) { |
| 129 | const c = v * s, x = c * (1 - Math.abs((h / 60) % 2 - 1)), m = v - c; |
| 130 | let r = 0, g = 0, b = 0; |
| 131 | if (h < 60) { r = c; g = x; } |
| 132 | else if (h < 120) { r = x; g = c; } |
| 133 | else if (h < 180) { g = c; b = x; } |
| 134 | else if (h < 240) { g = x; b = c; } |
| 135 | else if (h < 300) { r = x; b = c; } |
| 136 | else { r = c; b = x; } |
| 137 | return [r + m, g + m, b + m]; |
| 138 | } |
| 139 | |
| 140 | hashHue(str) { |
| 141 | let h = 2166136261; |
| 142 | for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = Math.imul(h, 16777619); } |
| 143 | return (h >>> 0) % 360; |
| 144 | } |
| 145 | |
| 146 | applyTint(window, reuse) { |
| 147 | const FIXED = [[0.0000,0.0000,0.0000],[0.0000,0.0000,0.6667],[0.6667,0.0000,0.0000],[0.0000,0.6667,0.0000],[0.4000,0.0000,0.6667],[0.6667,0.6667,0.0000],[0.6667,0.3333,0.0000],[0.0000,0.6667,0.6667],[0.6667,0.0000,0.4000],[0.3333,0.3333,0.3333],[0.3333,0.2000,0.0000]]; |
| 148 | const HS = 1.0, HV = 0.6667; // same peak channel as #aa0000 / #0000aa / … |
| 149 | let c, hue = null; |
| 150 | if (this.tintMode < FIXED.length) { |
| 151 | c = FIXED[this.tintMode]; |
| 152 | if (window) { window.bmwTint = null; window.bmwHue = null; } |
| 153 | } else if (this.tintMode === 12 && window) { |
| 154 | // Semiwillekeurig: stable per application (windowClass); empty → black. |
| 155 | // RGB/hue computed once per class (cached); shader gets ready RGB via HUE_RGB[hue] (no per-fragment HSV). |
| 156 | const cls = String(window.windowClass || '').trim(); |
| 157 | if (!cls) { c = FIXED[0]; hue = null; } |
| 158 | else { |
| 159 | if (!this.classHueCache) this.classHueCache = Object.create(null); |
| 160 | let cached = this.classHueCache[cls]; |
| 161 | if (!cached) { |
| 162 | hue = this.hashHue(cls); |
| 163 | c = this.hsvToRgb(hue, HS, HV); |
| 164 | this.classHueCache[cls] = { hue: hue, rgb: c }; |
| 165 | } else { |
| 166 | hue = cached.hue; c = cached.rgb; |
| 167 | } |
| 168 | } |
| 169 | window.bmwTint = c; window.bmwHue = hue; |
| 170 | } else if (window && reuse && window.bmwTint) { |
| 171 | c = window.bmwTint; hue = (window.bmwHue == null ? null : window.bmwHue); |
| 172 | window.bmwTint = null; |
| 173 | } else if (window) { |
| 174 | // Willekeurig: next sequence number → hue spaced by ~golden angle |
| 175 | if (!(window.bmwSeq >= 1)) window.bmwSeq = (this.seq = (this.seq || 0) + 1); |
| 176 | hue = Math.floor((window.bmwSeq * 137.508) % 360); |
| 177 | c = this.hsvToRgb(hue, HS, HV); |
| 178 | window.bmwTint = c; window.bmwHue = hue; |
| 179 | } else { |
| 180 | c = FIXED[0]; |
| 181 | } |
| 182 | if (window) { |
| 183 | // Shader: tk < 11 → named table; tk >= 1000 → HUE_RGB[tk-1000]. |
| 184 | // Compact id in uProgress integer part (NOT *4096 — that destroyed float32 morph precision). |
| 185 | window.bmwTintId = (hue == null) |
| 186 | ? Math.max(0, FIXED.findIndex(x => x[0] == c[0] && x[1] == c[1] && x[2] == c[2])) |
| 187 | : (1000 + (hue | 0)); |
| 188 | window.bmwBase = window.bmwTintId; |
| 189 | } |
| 190 | if (this.debug && window) console.log('MARBLEDBG tint caption=' + window.caption + ' class=' + window.windowClass + ' seq=' + window.bmwSeq + ' hue=' + hue + ' reuse=' + reuse + ' mode=' + this.tintMode + ' tintId=' + window.bmwTintId); |
| 191 | effect.setUniform(this.shader, 'uTintR', c[0]); |
| 192 | effect.setUniform(this.shader, 'uTintG', c[1]); |
| 193 | effect.setUniform(this.shader, 'uTintB', c[2]); |
| 194 | } |
| 195 | |
| 196 | static shouldAnimateWindow(window) { |
| 197 | |
| 198 | // We don't want to animate most of plasmashell's windows, yet, some |
| 199 | // of them we want to, for example, Task Manager Settings window. |
| 200 | // The problem is that all those window share single window class. |
| 201 | // So, the only way to decide whether a window should be animated is |
| 202 | // to use a heuristic: if a window has decoration, then it's most |
| 203 | // likely a dialog or a settings window so we have to animate it. |
| 204 | if (window.windowClass == 'plasmashell plasmashell' || |
| 205 | window.windowClass == 'plasmashell org.kde.plasmashell') { |
| 206 | return window.hasDecoration; |
| 207 | } |
| 208 | |
| 209 | // This is primarily to avoid animating the AltTab popup. |
| 210 | // See https://github.com/Schneegans/Burn-My-Windows/issues/384 for details. |
| 211 | if (!window.hasDecoration && window.onAllDesktops) { |
| 212 | return false |
| 213 | } |
| 214 | |
| 215 | if (classBlacklist.indexOf(window.windowClass) != -1) { |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | if (nameBlacklist.indexOf(window.caption) != -1) { |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | if (window.hasDecoration) { |
| 224 | return true; |
| 225 | } |
| 226 | |
| 227 | // Don't animate combobox popups, tooltips, popup menus, etc. |
| 228 | if (window.popupWindow) { |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | // Dont't animate the outline and the screenlocker as it looks bad. |
| 233 | if (window.lockScreen || window.outline) { |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | // Override-redirect windows are usually used for user interface |
| 238 | // concepts that are not expected to be animated by this effect. |
| 239 | if (!window.managed) { |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | return window.normalWindow || window.dialog; |
| 244 | } |
| 245 | |
| 246 | setupForcedRoles(window) { |
| 247 | // marble: no forced blur/contrast (blurred window-sized rect + cost) |
| 248 | // window.setData(Effect.WindowForceBackgroundContrastRole, true); |
| 249 | // marble: no forced blur/contrast (blurred window-sized rect + cost) |
| 250 | // window.setData(Effect.WindowForceBlurRole, true); |
| 251 | } |
| 252 | |
| 253 | cleanupForcedRoles(window) { |
| 254 | window.setData(Effect.WindowForceBackgroundContrastRole, null); |
| 255 | window.setData(Effect.WindowForceBlurRole, null); |
| 256 | } |
| 257 | |
| 258 | slotWindowAdded(window) { |
| 259 | if (effects.hasActiveFullScreenEffect) { |
| 260 | return; |
| 261 | } |
| 262 | if (!BurnMyWindowsMarbleMinimizeEffect.shouldAnimateWindow(window)) { |
| 263 | return; |
| 264 | } |
| 265 | if (!window.visible) { |
| 266 | return; |
| 267 | } |
| 268 | if (effect.isGrabbed(window, Effect.WindowAddedGrabRole)) { |
| 269 | return; |
| 270 | } |
| 271 | this.setupForcedRoles(window); |
| 272 | |
| 273 | effect.setUniform(this.shader, 'uForOpening', 1.0); |
| 274 | effect.setUniform(this.shader, 'uIsFullscreen', window.fullScreen ? 1.0 : 0.0); |
| 275 | |
| 276 | |
| 277 | |
| 278 | window.bmwInAnimation = animate({ |
| 279 | window: window, |
| 280 | curve: QEasingCurve.Linear, |
| 281 | duration: this.duration, |
| 282 | animations: [{ |
| 283 | type: Effect.ShaderUniform, |
| 284 | fragmentShader: this.shader, |
| 285 | uniform: 'uProgress', |
| 286 | from: this.prog(window, 0.0), |
| 287 | to: this.prog(window, 1.0 / Math.max(1e-4, this.duration / Math.max(1, this.duration + this.pause + this.fallDuration))) |
| 288 | }] |
| 289 | }); |
| 290 | } |
| 291 | |
| 292 | // ---- Smooth S-path: two parallel translations with different easing curves ---- |
| 293 | // Along the taskbar normal the marble falls with gravity (InQuad = 0.5 g t^2 from rest); |
| 294 | // sideways it moves with InOutSine (slow, fast in the middle, slow). Together this gives an |
| 295 | // S-shaped path that leaves straight down and enters the taskbar perpendicular. Duration |
| 296 | // from the distance along the normal: t = sqrt(2 d / g). No chains, no per-frame calls. |
| 297 | fallPlan(window, ir) { |
| 298 | const wr = window.geometry; |
| 299 | const dx = (ir.x + ir.width / 2) - (wr.x + wr.width / 2); |
| 300 | const dy = (ir.y + ir.height / 2) - (wr.y + wr.height / 2); |
| 301 | let vs = {x: 0, y: 0, width: 1920, height: 1080}; |
| 302 | try { const g = effects.virtualScreenGeometry; if (g && g.width) vs = g; } catch (e) {} |
| 303 | const cx = ir.x + ir.width / 2, cy = ir.y + ir.height / 2; |
| 304 | const d = [cy - vs.y, vs.y + vs.height - cy, cx - vs.x, vs.x + vs.width - cx]; // top,bottom,left,right |
| 305 | let k = 1; for (let i = 0; i < 4; i++) if (d[i] < d[k]) k = i; // bottom is default |
| 306 | const vertical = k < 2; // taskbar at top/bottom |
| 307 | const along = Math.max(30, Math.abs(vertical ? dy : dx)); |
| 308 | const T = animationTime(Math.round(1000 * Math.sqrt(2 * along / this.gravity))); |
| 309 | // KWin scales around the centre of the expanded geometry (incl. shadow), not the window |
| 310 | // centre; when the marble shrinks to ~0 it would drift there. Offset to compensate. |
| 311 | let ox = 0, oy = 0; |
| 312 | try { const eg = window.expandedGeometry; |
| 313 | ox = (wr.x + wr.width / 2) - (eg.x + eg.width / 2); oy = (wr.y + wr.height / 2) - (eg.y + eg.height / 2); } catch (e) {} |
| 314 | return {dx: dx, dy: dy, T: Math.max(1, T), vertical: vertical, ox: ox, oy: oy}; |
| 315 | } |
| 316 | |
| 317 | // dir: 1 = minimize (towards the icon), -1 = restore (time-reversed) |
| 318 | fallAnims(window, f, dir) { |
| 319 | const fwd = dir > 0; |
| 320 | const gravityCurve = fwd ? QEasingCurve.InQuad : QEasingCurve.OutQuad; // OutQuad = reversed InQuad |
| 321 | const sideCurve = QEasingCurve.InOutSine; // symmetric |
| 322 | const xCurve = f.vertical ? sideCurve : gravityCurve; |
| 323 | const yCurve = f.vertical ? gravityCurve : sideCurve; |
| 324 | const ax = fwd ? [0, f.dx] : [f.dx, 0], ay = fwd ? [0, f.dy] : [f.dy, 0]; |
| 325 | window.bmwXAnimation = animate({ window: window, curve: xCurve, duration: f.T, |
| 326 | animations: [{ type: Effect.Translation, from: {value1: ax[0], value2: 0.0}, to: {value1: ax[1], value2: 0.0} }, |
| 327 | { type: Effect.Opacity, from: 1.0, to: 1.0 }] }); |
| 328 | window.bmwYAnimation = animate({ window: window, curve: yCurve, duration: f.T, |
| 329 | animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: ay[0]}, to: {value1: 0.0, value2: ay[1]} }] }); |
| 330 | // single scale 100% -> ~0 (0.001, never 0) essentially in the last part (InExpo stays ~1 until late); reverse = OutExpo |
| 331 | window.bmwScaleAnimation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T, |
| 332 | animations: [{ type: Effect.Scale, from: {value1: fwd ? 1.0 : 0.001, value2: fwd ? 1.0 : 0.001}, |
| 333 | to: {value1: fwd ? 0.001 : 1.0, value2: fwd ? 0.001 : 1.0} }] }); |
| 334 | |
| 335 | } |
| 336 | |
| 337 | slotWindowMinimized(window) { |
| 338 | if (effects.hasActiveFullScreenEffect) return; |
| 339 | const ir = window.iconGeometry; |
| 340 | if (!ir || ir.width == 0 || ir.height == 0) return; // no taskbar entry |
| 341 | const old = this.takeAll(window); |
| 342 | const f = this.fallPlan(window, ir); |
| 343 | this.applyTint(window, false); |
| 344 | const morph = this.duration + this.pause; |
| 345 | const total = morph + f.T; |
| 346 | effect.setUniform(this.shader, "uForOpening", 0.0); |
| 347 | effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0); |
| 348 | effect.setUniform(this.shader, "uDuration", total * 0.001); |
| 349 | effect.setUniform(this.shader, "uCrumpleEnd", this.duration / Math.max(1, total + 3000)); // match ShaderUniform duration (total+3000) |
| 350 | // one shader animation, deliberately longer; cancelled after the invisible tail (flash fix) |
| 351 | window.bmwMinAnimation = animate({ |
| 352 | window: window, curve: QEasingCurve.Linear, duration: total + 3000, |
| 353 | animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: this.prog(window, 0.0), to: this.prog(window, (total + 3000) / Math.max(1, this.duration)) }, |
| 354 | { type: Effect.Opacity, from: 1.0, to: 1.0 }] |
| 355 | }); |
| 356 | window.bmwMarbleDone = animate({ |
| 357 | window: window, curve: QEasingCurve.Linear, duration: morph, |
| 358 | animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: 0.0}, to: {value1: 0.0, value2: 0.0} }] |
| 359 | }); |
| 360 | window.bmwFall = f; window.bmwMode = "morph"; window.bmwSegEnd = Date.now() + morph - 8; |
| 361 | this.cancelIds(old); // after the new shader animation exists (keeps the snapshot) |
| 362 | } |
| 363 | |
| 364 | slotWindowUnminimized(window) { |
| 365 | if (effects.hasActiveFullScreenEffect) return; |
| 366 | const ir = window.iconGeometry; |
| 367 | const old = this.takeAll(window); |
| 368 | if (!ir || ir.width == 0 || ir.height == 0) { this.cancelIds(old); return; } |
| 369 | // reverse: rise from the icon (same curves reversed), rest, unfold |
| 370 | const f = this.fallPlan(window, ir); |
| 371 | this.applyTint(window, true); |
| 372 | const total = this.duration + this.pause + f.T; |
| 373 | effect.setUniform(this.shader, "uForOpening", 0.0); |
| 374 | effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0); |
| 375 | effect.setUniform(this.shader, "uDuration", total * 0.001); |
| 376 | effect.setUniform(this.shader, "uCrumpleEnd", this.duration / Math.max(1, total)); |
| 377 | window.bmwUnminAnimation = animate({ |
| 378 | window: window, curve: QEasingCurve.Linear, duration: total, |
| 379 | animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: this.prog(window, total / Math.max(1, this.duration)), to: this.prog(window, 0.0) }] |
| 380 | }); |
| 381 | this.fallAnims(window, f, -1); |
| 382 | window.bmwFadeInAnimation = animate({ window: window, curve: QEasingCurve.InExpo, duration: 80, |
| 383 | animations: [{ type: Effect.Opacity, from: 0.0, to: 1.0 }] }); |
| 384 | this.cancelIds(old); // after the new shader animation exists (keeps the snapshot) |
| 385 | } |
| 386 | |
| 387 | // Detach the running animations of this window without cancelling them yet. They are cancelled |
| 388 | // (cancelIds) only after the new animations exist: KWin's scripted shader animations draw a |
| 389 | // one-time snapshot of the window, and a snapshot taken while this effect is already active |
| 390 | // comes out empty (black/invisible marble). Keeping one shader animation alive makes KWin |
| 391 | // reuse the existing, valid snapshot for the new animation. |
| 392 | takeAll(window) { |
| 393 | window.bmwMode = null; |
| 394 | const ids = []; |
| 395 | for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation", "bmwScale2Animation", "bmwCompAnimation", |
| 396 | "bmwTailAnimation", "bmwUnminAnimation", "bmwFadeInAnimation"]) { |
| 397 | if (window[k]) { ids.push(window[k]); delete window[k]; } |
| 398 | } |
| 399 | return ids; |
| 400 | } |
| 401 | |
| 402 | cancelIds(ids) { |
| 403 | for (const id of ids) cancel(id); |
| 404 | this.repaintAll(); |
| 405 | } |
| 406 | |
| 407 | stopAll(window) { this.cancelIds(this.takeAll(window)); } |
| 408 | |
| 409 | // KWin reports ids as 0 here, so we use our own state + end times. |
| 410 | slotAnimationEnded(window, id) { |
| 411 | // marble is drawn outside the window's own damage region: repaint all on every end |
| 412 | this.repaintAll(); |
| 413 | if (!window || !window.bmwMode) return; |
| 414 | if (window.bmwSegEnd && Date.now() < window.bmwSegEnd) return; // another animation ended |
| 415 | const f = window.bmwFall; |
| 416 | if (window.bmwMode == "morph") { // morph + pause done -> fall (one shot) |
| 417 | this.fallAnims(window, f, 1); |
| 418 | window.bmwMode = "fall"; window.bmwSegEnd = Date.now() + f.T - 8; |
| 419 | } else if (window.bmwMode == "fall") { // arrived: invisible hold at the icon |
| 420 | window.bmwTailAnimation = animate({ |
| 421 | window: window, curve: QEasingCurve.Linear, duration: 250, |
| 422 | animations: [{ type: Effect.Translation, from: {value1: f.dx, value2: f.dy}, to: {value1: f.dx, value2: f.dy} }, |
| 423 | { type: Effect.Scale, from: {value1: 0.001, value2: 0.001}, to: {value1: 0.001, value2: 0.001} }, |
| 424 | { type: Effect.Opacity, from: 0.0, to: 0.0 }] |
| 425 | }); |
| 426 | window.bmwMode = "tail"; window.bmwSegEnd = Date.now() + 250 - 8; |
| 427 | this.repaintAll(); |
| 428 | } else if (window.bmwMode == "tail") { // now stop the shader; window is hidden |
| 429 | window.bmwMode = null; |
| 430 | if (window.bmwMinAnimation) { cancel(window.bmwMinAnimation); delete window.bmwMinAnimation; } |
| 431 | this.repaintAll(); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | repaintAll() { |
| 436 | try { effects.addRepaintFull(); } catch (e) { |
| 437 | if (!this.bmwWarned) { this.bmwWarned = true; console.warn("marble: addRepaintFull unavailable: " + e); } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | slotWindowDataChanged(window, role) { |
| 442 | if (role == Effect.WindowAddedGrabRole) { |
| 443 | if (window.bmwInAnimation && effect.isGrabbed(window, role)) { |
| 444 | cancel(window.bmwInAnimation); |
| 445 | delete window.bmwInAnimation; |
| 446 | this.cleanupForcedRoles(window); |
| 447 | } |
| 448 | } else if (role == Effect.WindowClosedGrabRole) { |
| 449 | if (window.bmwOutAnimation && effect.isGrabbed(window, role)) { |
| 450 | cancel(window.bmwOutAnimation); |
| 451 | delete window.bmwOutAnimation; |
| 452 | this.cleanupForcedRoles(window); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | new BurnMyWindowsMarbleMinimizeEffect(); |