BlueGit

timfa kwin-marble

Marble Magic Lamp: smooth S-path from two parallel eased translations (no segment chain)

timfa Tim Falken · pushed by timfa

Authored 2026-11-02 · 2 weeks ago

Hash
e7b1df9f3e5fc704d0125410501ccc92df580a22
Parent
a865999d
2 files changed +57 −132
README.md +4 −4
@@ -13,13 +13,13 @@ acceleration from rest) for 1.5 screen heights.
13 13 ## Marble Magic Lamp (minimize)
14 14
15 15 **NL** – `kwin6_effect_marble_minimize`: bij minimaliseren vormt het venster zich net zo om tot
16 een knikker, pauzeert, en valt dan met zwaartekracht (vanuit stilstand) langs een S-vormige Bezier-curve
17 (loodrecht uit het venster, loodrecht de taakbalk in) naar zijn taakbalkknop; in de laatste 10% krimpt
16 een knikker, pauzeert, en valt dan met zwaartekracht (vanuit stilstand) langs een vloeiend S-pad
17 (twee parallelle bewegingen: zwaartekracht richting taakbalk, InOutSine opzij) naar zijn taakbalkknop; in de laatste 10% krimpt
18 18 hij naar 10%. Herstellen speelt de omgekeerde animatie (knikker stijgt op van de taakbalkknop, pauze, vouwt open). Zelfde instellingen en defaults.
19 19
20 20 **EN** – `kwin6_effect_marble_minimize`: on minimize the window becomes the same marble, pauses,
21 then falls under gravity (from rest) along an S-shaped Bezier path (perpendicular to the
22 taskbar edge at both ends) to its taskbar entry, shrinking to 10% over the last 10% of the path. Restore plays it in
21 then falls under gravity (from rest) along a smooth S-path (two parallel moves: gravity towards
22 the taskbar, InOutSine sideways) to its taskbar entry, shrinking to 10% over the last 10% of the path. Restore plays it in
23 23 reverse (marble rises from the taskbar entry, pauses, unfolds into the window). Same settings and defaults. It replaces the active minimize animation (e.g. Magic Lamp).
24 24
25 25 ## Installatie / Installation
@@ -13,13 +13,13 @@ acceleration from rest) for 1.5 screen heights.
13## Marble Magic Lamp (minimize)
13## Marble Magic Lamp (minimize)
14
14
15**NL** – `kwin6_effect_marble_minimize`: bij minimaliseren vormt het venster zich net zo om tot
15**NL** – `kwin6_effect_marble_minimize`: bij minimaliseren vormt het venster zich net zo om tot
16een knikker, pauzeert, en valt dan met zwaartekracht (vanuit stilstand) langs een S-vormige Bezier-curve
16een knikker, pauzeert, en valt dan met zwaartekracht (vanuit stilstand) langs een vloeiend S-pad
17(loodrecht uit het venster, loodrecht de taakbalk in) naar zijn taakbalkknop; in de laatste 10% krimpt
17(twee parallelle bewegingen: zwaartekracht richting taakbalk, InOutSine opzij) naar zijn taakbalkknop; in de laatste 10% krimpt
18hij naar 10%. Herstellen speelt de omgekeerde animatie (knikker stijgt op van de taakbalkknop, pauze, vouwt open). Zelfde instellingen en defaults.
18hij naar 10%. Herstellen speelt de omgekeerde animatie (knikker stijgt op van de taakbalkknop, pauze, vouwt open). Zelfde instellingen en defaults.
19
19
20**EN** – `kwin6_effect_marble_minimize`: on minimize the window becomes the same marble, pauses,
20**EN** – `kwin6_effect_marble_minimize`: on minimize the window becomes the same marble, pauses,
21then falls under gravity (from rest) along an S-shaped Bezier path (perpendicular to the
21then falls under gravity (from rest) along a smooth S-path (two parallel moves: gravity towards
22taskbar edge at both ends) to its taskbar entry, shrinking to 10% over the last 10% of the path. Restore plays it in
22the taskbar, InOutSine sideways) to its taskbar entry, shrinking to 10% over the last 10% of the path. Restore plays it in
23reverse (marble rises from the taskbar entry, pauses, unfolds into the window). Same settings and defaults. It replaces the active minimize animation (e.g. Magic Lamp).
23reverse (marble rises from the taskbar entry, pauses, unfolds into the window). Same settings and defaults. It replaces the active minimize animation (e.g. Magic Lamp).
24
24
25## Installatie / Installation
25## Installatie / Installation
kwin6_effect_marble_minimize/contents/code/main.js +53 −128
@@ -192,61 +192,43 @@ class BurnMyWindowsMarbleMinimizeEffect {
192 192 });
193 193 }
194 194
195 // ---- S-shaped cubic Bezier path from the marble (window centre) to the taskbar entry ----
196 // Start and end tangents are perpendicular to the taskbar edge (derived from where the
197 // icon sits on the screen). Returns N segments of equal arc length with gravity timing:
198 // s = 0.5 g t^2 from rest -> t(s) = sqrt(2 s / g).
199 buildPath(window, ir) {
195 // ---- Smooth S-path: two parallel translations with different easing curves ----
196 // Along the taskbar normal the marble falls with gravity (InQuad = 0.5 g t^2 from rest);
197 // sideways it moves with InOutSine (slow, fast in the middle, slow). Together this gives an
198 // S-shaped path that leaves straight down and enters the taskbar perpendicular. Duration
199 // from the distance along the normal: t = sqrt(2 d / g). No chains, no per-frame calls.
200 fallPlan(window, ir) {
200 201 const wr = window.geometry;
201 202 const dx = (ir.x + ir.width / 2) - (wr.x + wr.width / 2);
202 203 const dy = (ir.y + ir.height / 2) - (wr.y + wr.height / 2);
203 204 let vs = {x: 0, y: 0, width: 1920, height: 1080};
204 205 try { const g = effects.virtualScreenGeometry; if (g && g.width) vs = g; } catch (e) {}
205 206 const cx = ir.x + ir.width / 2, cy = ir.y + ir.height / 2;
206 const dist = [cy - vs.y, vs.y + vs.height - cy, cx - vs.x, vs.x + vs.width - cx]; // top,bottom,left,right
207 const normals = [[0, -1], [0, 1], [-1, 0], [1, 0]];
208 let k = 1; for (let i = 0; i < 4; i++) if (dist[i] < dist[k]) k = i; // bottom is default
209 const n = normals[k];
210 const along = Math.max(60, Math.abs(dx * n[0] + dy * n[1]));
211 const h = 0.55 * along; // tangent handle length
212 const P = [[0, 0], [n[0] * h, n[1] * h], [dx - n[0] * h, dy - n[1] * h], [dx, dy]];
213 const bez = (t) => {
214 const u = 1 - t, a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
215 return [a * P[0][0] + b * P[1][0] + c * P[2][0] + d * P[3][0], a * P[0][1] + b * P[1][1] + c * P[2][1] + d * P[3][1]];
216 };
217 // numeric arc length
218 const M = 200, pts = [], cum = [0];
219 for (let i = 0; i <= M; i++) pts.push(bez(i / M));
220 for (let i = 1; i <= M; i++) cum.push(cum[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
221 const L = Math.max(1, cum[M]);
222 const N = 20, nodes = [];
223 let j = 0;
224 for (let i = 0; i <= N; i++) {
225 const s = L * i / N;
226 while (j < M && cum[j + 1] < s) j++;
227 const f = j < M ? (s - cum[j]) / Math.max(1e-6, cum[j + 1] - cum[j]) : 0;
228 const q = j < M ? [pts[j][0] + (pts[j + 1][0] - pts[j][0]) * f, pts[j][1] + (pts[j + 1][1] - pts[j][1]) * f] : pts[M];
229 nodes.push({x: q[0], y: q[1], t: animationTime(Math.round(1000 * Math.sqrt(2 * s / this.gravity)))});
230 }
231 // continuous position at path time t (ms, already scaled by the animation factor)
232 const fac = Math.max(0.001, animationTime(1000) / 1000), g = this.gravity;
233 const posAt = (tms) => {
234 const ts = Math.max(0, tms) / 1000 / fac;
235 const sa = Math.min(L, 0.5 * g * ts * ts);
236 let lo = 0, hi = M;
237 while (hi - lo > 1) { const mid = (lo + hi) >> 1; if (cum[mid] <= sa) lo = mid; else hi = mid; }
238 const f = (sa - cum[lo]) / Math.max(1e-6, cum[hi] - cum[lo]);
239 return {x: pts[lo][0] + (pts[hi][0] - pts[lo][0]) * f, y: pts[lo][1] + (pts[hi][1] - pts[lo][1]) * f};
240 };
241 return {nodes: nodes, length: L, total: nodes[N].t, posAt: posAt, tScale: nodes[N - 2].t};
207 const d = [cy - vs.y, vs.y + vs.height - cy, cx - vs.x, vs.x + vs.width - cx]; // top,bottom,left,right
208 let k = 1; for (let i = 0; i < 4; i++) if (d[i] < d[k]) k = i; // bottom is default
209 const vertical = k < 2; // taskbar at top/bottom
210 const along = Math.max(30, Math.abs(vertical ? dy : dx));
211 const T = animationTime(Math.round(1000 * Math.sqrt(2 * along / this.gravity)));
212 return {dx: dx, dy: dy, T: Math.max(1, T), vertical: vertical};
242 213 }
243 214
244 segAnim(window, a, b, dur, extra) {
245 const anims = [{ type: Effect.Translation, from: {value1: a.x, value2: a.y}, to: {value1: b.x, value2: b.y} },
246 { type: Effect.Opacity, from: 1.0, to: 1.0 }];
247 if (extra) anims.push(extra);
248 window.bmwSegEnd = Date.now() + Math.max(1, dur) - 8;
249 return animate({ window: window, curve: QEasingCurve.Linear, duration: Math.max(1, dur), animations: anims });
215 // dir: 1 = minimize (towards the icon), -1 = restore (time-reversed)
216 fallAnims(window, f, dir) {
217 const fwd = dir > 0;
218 const gravityCurve = fwd ? QEasingCurve.InQuad : QEasingCurve.OutQuad; // OutQuad = reversed InQuad
219 const sideCurve = QEasingCurve.InOutSine; // symmetric
220 const xCurve = f.vertical ? sideCurve : gravityCurve;
221 const yCurve = f.vertical ? gravityCurve : sideCurve;
222 const ax = fwd ? [0, f.dx] : [f.dx, 0], ay = fwd ? [0, f.dy] : [f.dy, 0];
223 window.bmwXAnimation = animate({ window: window, curve: xCurve, duration: f.T,
224 animations: [{ type: Effect.Translation, from: {value1: ax[0], value2: 0.0}, to: {value1: ax[1], value2: 0.0} },
225 { type: Effect.Opacity, from: 1.0, to: 1.0 }] });
226 window.bmwYAnimation = animate({ window: window, curve: yCurve, duration: f.T,
227 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: ay[0]}, to: {value1: 0.0, value2: ay[1]} }] });
228 // scale 100% -> 10% essentially in the last part (InExpo stays ~1 until late); reverse = OutExpo
229 window.bmwScaleAnimation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
230 animations: [{ type: Effect.Scale, from: {value1: fwd ? 1.0 : 0.1, value2: fwd ? 1.0 : 0.1},
231 to: {value1: fwd ? 0.1 : 1.0, value2: fwd ? 0.1 : 1.0} }] });
250 232 }
251 233
252 234 slotWindowMinimized(window) {
@@ -254,30 +236,24 @@ class BurnMyWindowsMarbleMinimizeEffect {
254 236 const ir = window.iconGeometry;
255 237 if (!ir || ir.width == 0 || ir.height == 0) return; // no taskbar entry
256 238 this.stopAll(window);
257 const path = this.buildPath(window, ir);
239 const f = this.fallPlan(window, ir);
258 240 const morph = this.duration + this.pause;
259 const total = morph + path.total;
241 const total = morph + f.T;
260 242 effect.setUniform(this.shader, "uForOpening", 0.0);
261 243 effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0);
262 244 effect.setUniform(this.shader, "uDuration", total * 0.001);
263 245 effect.setUniform(this.shader, "uCrumpleEnd", this.duration / Math.max(1, total));
264 // ONE shader animation over the whole minimize (same setup as restore, which renders fine);
265 // a little longer than the path so the marble is drawn until the window is hidden.
246 // one shader animation, deliberately longer; cancelled after the invisible tail (flash fix)
266 247 window.bmwMinAnimation = animate({
267 // runs far past the path on purpose (uProgress just goes beyond 1 = marble); it is
268 // cancelled explicitly after the invisible tail, so a late chain can never expose
269 // the unshaded window.
270 248 window: window, curve: QEasingCurve.Linear, duration: total + 3000,
271 249 animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: 0.0, to: (total + 3000) / Math.max(1, total) },
272 250 { type: Effect.Opacity, from: 1.0, to: 1.0 }]
273 251 });
274 // marker for the end of morph + pause; when it ends the path traversal starts
275 252 window.bmwMarbleDone = animate({
276 253 window: window, curve: QEasingCurve.Linear, duration: morph,
277 254 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: 0.0}, to: {value1: 0.0, value2: 0.0} }]
278 255 });
279 window.bmwPath = path; window.bmwSeg = -1; window.bmwMode = "min";
280 window.bmwSegEnd = Date.now() + morph - 8;
256 window.bmwFall = f; window.bmwMode = "morph"; window.bmwSegEnd = Date.now() + morph - 8;
281 257 }
282 258
283 259 slotWindowUnminimized(window) {
@@ -285,10 +261,9 @@ class BurnMyWindowsMarbleMinimizeEffect {
285 261 const ir = window.iconGeometry;
286 262 this.stopAll(window);
287 263 if (!ir || ir.width == 0 || ir.height == 0) return;
288 // exact reverse: marble comes up the same S-path (reverse gravity timing), growing from
289 // 10% to 100% over the first 10% of the path, rests, then unfolds into the window.
290 const path = this.buildPath(window, ir);
291 const total = this.duration + this.pause + path.total;
264 // reverse: rise from the icon (same curves reversed), rest, unfold
265 const f = this.fallPlan(window, ir);
266 const total = this.duration + this.pause + f.T;
292 267 effect.setUniform(this.shader, "uForOpening", 0.0);
293 268 effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0);
294 269 effect.setUniform(this.shader, "uDuration", total * 0.001);
@@ -297,87 +272,37 @@ class BurnMyWindowsMarbleMinimizeEffect {
297 272 window: window, curve: QEasingCurve.Linear, duration: total,
298 273 animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: 1.0, to: 0.0 }]
299 274 });
300 const T = path.total, nd = path.nodes, N = nd.length - 1;
301 // reversed timing: going from node N to node N-1 takes (t_N - t_{N-1}) etc.
302 window.bmwScaleAnimation = animate({
303 window: window, curve: QEasingCurve.InOutSine, duration: Math.max(1, T - nd[N - 2].t),
304 animations: [{ type: Effect.Scale, from: {value1: 0.1, value2: 0.1}, to: {value1: 1.0, value2: 1.0} }]
305 });
306 window.bmwPath = path; window.bmwMode = "rise";
307 window.bmwT0 = Date.now(); window.bmwCur = {x: nd[N].x, y: nd[N].y};
308 this.step(window);
275 this.fallAnims(window, f, -1);
309 276 }
310 277
311 278 stopAll(window) {
312 window.bmwMode = null; window.bmwScaling = false;
313 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwSegAnimation", "bmwScaleAnimation",
279 window.bmwMode = null;
280 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation",
314 281 "bmwTailAnimation", "bmwUnminAnimation"]) {
315 282 if (window[k]) { cancel(window[k]); delete window[k]; }
316 283 }
317 284 }
318 285
319 // Chain the path segments. KWin reports ids as 0 here, so we use our own state.
286 // KWin reports ids as 0 here, so we use our own state + end times.
320 287 slotAnimationEnded(window, id) {
321 288 if (!window || !window.bmwMode) return;
322 289 if (window.bmwSegEnd && Date.now() < window.bmwSegEnd) return; // another animation ended
323 const nd = window.bmwPath.nodes, N = nd.length - 1;
324 if (window.bmwMode == "tail") {
325 // invisible tail done: now stop the shader too; the window is hidden from here on
290 const f = window.bmwFall;
291 if (window.bmwMode == "morph") { // morph + pause done -> fall (one shot)
292 this.fallAnims(window, f, 1);
293 window.bmwMode = "fall"; window.bmwSegEnd = Date.now() + f.T - 8;
294 } else if (window.bmwMode == "fall") { // arrived: invisible hold at the icon
295 window.bmwTailAnimation = animate({
296 window: window, curve: QEasingCurve.Linear, duration: 250,
297 animations: [{ type: Effect.Translation, from: {value1: f.dx, value2: f.dy}, to: {value1: f.dx, value2: f.dy} },
298 { type: Effect.Scale, from: {value1: 0.1, value2: 0.1}, to: {value1: 0.1, value2: 0.1} },
299 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
300 });
301 window.bmwMode = "tail"; window.bmwSegEnd = Date.now() + 250 - 8;
302 } else if (window.bmwMode == "tail") { // now stop the shader; window is hidden
326 303 window.bmwMode = null;
327 304 if (window.bmwMinAnimation) { cancel(window.bmwMinAnimation); delete window.bmwMinAnimation; }
328 305 try { effects.addRepaintFull(); } catch (e) {}
329 return;
330 }
331 if (window.bmwMode == "min" && window.bmwSeg < 0) { // morph + pause done
332 window.bmwSeg = 0; window.bmwT0 = Date.now(); window.bmwCur = {x: 0, y: 0};
333 }
334 this.step(window);
335 }
336
337 // Clock-driven path: every short segment aims at the path position for (now + STEP), measured
338 // from the real start time, so callback latency never accumulates (no drift, no stretch).
339 step(window) {
340 const STEP = 33; // ~2 frames per segment
341 const path = window.bmwPath, T = path.total, N = path.nodes.length - 1;
342 const now = Date.now() - window.bmwT0;
343 const end = path.nodes[N];
344 if (window.bmwMode == "min") {
345 if (now >= T - 4) {
346 // arrived: invisible hold at the icon (scale 10%) until the shader animation is cancelled
347 window.bmwTailAnimation = animate({
348 window: window, curve: QEasingCurve.Linear, duration: 250,
349 animations: [{ type: Effect.Translation, from: {value1: end.x, value2: end.y}, to: {value1: end.x, value2: end.y} },
350 { type: Effect.Scale, from: {value1: 0.1, value2: 0.1}, to: {value1: 0.1, value2: 0.1} },
351 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
352 });
353 window.bmwSegEnd = Date.now() + 250 - 8;
354 window.bmwMode = "tail";
355 return;
356 }
357 const tgt = Math.min(T, now + STEP);
358 const p = tgt >= T ? {x: end.x, y: end.y} : path.posAt(tgt);
359 if (!window.bmwScaling && tgt >= path.tScale) { // last 10% of arc length: 100% -> 10%
360 window.bmwScaling = true;
361 window.bmwScaleAnimation = animate({
362 window: window, curve: QEasingCurve.InOutSine, duration: Math.max(1, T - now),
363 animations: [{ type: Effect.Scale, from: {value1: 1.0, value2: 1.0}, to: {value1: 0.1, value2: 0.1} }]
364 });
365 }
366 window.bmwSegAnimation = this.segAnim(window, window.bmwCur, p, tgt - now);
367 window.bmwCur = p;
368 } else if (window.bmwMode == "rise") {
369 if (now >= T - 4) {
370 if (window.bmwCur.x != 0 || window.bmwCur.y != 0) {
371 window.bmwSegAnimation = this.segAnim(window, window.bmwCur, {x: 0, y: 0}, 1);
372 window.bmwCur = {x: 0, y: 0};
373 }
374 window.bmwMode = null;
375 return;
376 }
377 const tgt = Math.min(T, now + STEP);
378 const p = tgt >= T ? {x: 0, y: 0} : path.posAt(T - tgt);
379 window.bmwSegAnimation = this.segAnim(window, window.bmwCur, p, tgt - now);
380 window.bmwCur = p;
381 306 }
382 307 }
383 308
@@ -192,61 +192,43 @@ class BurnMyWindowsMarbleMinimizeEffect {
192 });
192 });
193 }
193 }
194
194
195 // ---- S-shaped cubic Bezier path from the marble (window centre) to the taskbar entry ----
195 // ---- Smooth S-path: two parallel translations with different easing curves ----
196 // Start and end tangents are perpendicular to the taskbar edge (derived from where the
196 // Along the taskbar normal the marble falls with gravity (InQuad = 0.5 g t^2 from rest);
197 // icon sits on the screen). Returns N segments of equal arc length with gravity timing:
197 // sideways it moves with InOutSine (slow, fast in the middle, slow). Together this gives an
198 // s = 0.5 g t^2 from rest -> t(s) = sqrt(2 s / g).
198 // S-shaped path that leaves straight down and enters the taskbar perpendicular. Duration
199 buildPath(window, ir) {
199 // from the distance along the normal: t = sqrt(2 d / g). No chains, no per-frame calls.
200 fallPlan(window, ir) {
200 const wr = window.geometry;
201 const wr = window.geometry;
201 const dx = (ir.x + ir.width / 2) - (wr.x + wr.width / 2);
202 const dx = (ir.x + ir.width / 2) - (wr.x + wr.width / 2);
202 const dy = (ir.y + ir.height / 2) - (wr.y + wr.height / 2);
203 const dy = (ir.y + ir.height / 2) - (wr.y + wr.height / 2);
203 let vs = {x: 0, y: 0, width: 1920, height: 1080};
204 let vs = {x: 0, y: 0, width: 1920, height: 1080};
204 try { const g = effects.virtualScreenGeometry; if (g && g.width) vs = g; } catch (e) {}
205 try { const g = effects.virtualScreenGeometry; if (g && g.width) vs = g; } catch (e) {}
205 const cx = ir.x + ir.width / 2, cy = ir.y + ir.height / 2;
206 const cx = ir.x + ir.width / 2, cy = ir.y + ir.height / 2;
206 const dist = [cy - vs.y, vs.y + vs.height - cy, cx - vs.x, vs.x + vs.width - cx]; // top,bottom,left,right
207 const d = [cy - vs.y, vs.y + vs.height - cy, cx - vs.x, vs.x + vs.width - cx]; // top,bottom,left,right
207 const normals = [[0, -1], [0, 1], [-1, 0], [1, 0]];
208 let k = 1; for (let i = 0; i < 4; i++) if (d[i] < d[k]) k = i; // bottom is default
208 let k = 1; for (let i = 0; i < 4; i++) if (dist[i] < dist[k]) k = i; // bottom is default
209 const vertical = k < 2; // taskbar at top/bottom
209 const n = normals[k];
210 const along = Math.max(30, Math.abs(vertical ? dy : dx));
210 const along = Math.max(60, Math.abs(dx * n[0] + dy * n[1]));
211 const T = animationTime(Math.round(1000 * Math.sqrt(2 * along / this.gravity)));
211 const h = 0.55 * along; // tangent handle length
212 return {dx: dx, dy: dy, T: Math.max(1, T), vertical: vertical};
212 const P = [[0, 0], [n[0] * h, n[1] * h], [dx - n[0] * h, dy - n[1] * h], [dx, dy]];
213 const bez = (t) => {
214 const u = 1 - t, a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
215 return [a * P[0][0] + b * P[1][0] + c * P[2][0] + d * P[3][0], a * P[0][1] + b * P[1][1] + c * P[2][1] + d * P[3][1]];
216 };
217 // numeric arc length
218 const M = 200, pts = [], cum = [0];
219 for (let i = 0; i <= M; i++) pts.push(bez(i / M));
220 for (let i = 1; i <= M; i++) cum.push(cum[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
221 const L = Math.max(1, cum[M]);
222 const N = 20, nodes = [];
223 let j = 0;
224 for (let i = 0; i <= N; i++) {
225 const s = L * i / N;
226 while (j < M && cum[j + 1] < s) j++;
227 const f = j < M ? (s - cum[j]) / Math.max(1e-6, cum[j + 1] - cum[j]) : 0;
228 const q = j < M ? [pts[j][0] + (pts[j + 1][0] - pts[j][0]) * f, pts[j][1] + (pts[j + 1][1] - pts[j][1]) * f] : pts[M];
229 nodes.push({x: q[0], y: q[1], t: animationTime(Math.round(1000 * Math.sqrt(2 * s / this.gravity)))});
230 }
231 // continuous position at path time t (ms, already scaled by the animation factor)
232 const fac = Math.max(0.001, animationTime(1000) / 1000), g = this.gravity;
233 const posAt = (tms) => {
234 const ts = Math.max(0, tms) / 1000 / fac;
235 const sa = Math.min(L, 0.5 * g * ts * ts);
236 let lo = 0, hi = M;
237 while (hi - lo > 1) { const mid = (lo + hi) >> 1; if (cum[mid] <= sa) lo = mid; else hi = mid; }
238 const f = (sa - cum[lo]) / Math.max(1e-6, cum[hi] - cum[lo]);
239 return {x: pts[lo][0] + (pts[hi][0] - pts[lo][0]) * f, y: pts[lo][1] + (pts[hi][1] - pts[lo][1]) * f};
240 };
241 return {nodes: nodes, length: L, total: nodes[N].t, posAt: posAt, tScale: nodes[N - 2].t};
242 }
213 }
243
214
244 segAnim(window, a, b, dur, extra) {
215 // dir: 1 = minimize (towards the icon), -1 = restore (time-reversed)
245 const anims = [{ type: Effect.Translation, from: {value1: a.x, value2: a.y}, to: {value1: b.x, value2: b.y} },
216 fallAnims(window, f, dir) {
246 { type: Effect.Opacity, from: 1.0, to: 1.0 }];
217 const fwd = dir > 0;
247 if (extra) anims.push(extra);
218 const gravityCurve = fwd ? QEasingCurve.InQuad : QEasingCurve.OutQuad; // OutQuad = reversed InQuad
248 window.bmwSegEnd = Date.now() + Math.max(1, dur) - 8;
219 const sideCurve = QEasingCurve.InOutSine; // symmetric
249 return animate({ window: window, curve: QEasingCurve.Linear, duration: Math.max(1, dur), animations: anims });
220 const xCurve = f.vertical ? sideCurve : gravityCurve;
221 const yCurve = f.vertical ? gravityCurve : sideCurve;
222 const ax = fwd ? [0, f.dx] : [f.dx, 0], ay = fwd ? [0, f.dy] : [f.dy, 0];
223 window.bmwXAnimation = animate({ window: window, curve: xCurve, duration: f.T,
224 animations: [{ type: Effect.Translation, from: {value1: ax[0], value2: 0.0}, to: {value1: ax[1], value2: 0.0} },
225 { type: Effect.Opacity, from: 1.0, to: 1.0 }] });
226 window.bmwYAnimation = animate({ window: window, curve: yCurve, duration: f.T,
227 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: ay[0]}, to: {value1: 0.0, value2: ay[1]} }] });
228 // scale 100% -> 10% essentially in the last part (InExpo stays ~1 until late); reverse = OutExpo
229 window.bmwScaleAnimation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
230 animations: [{ type: Effect.Scale, from: {value1: fwd ? 1.0 : 0.1, value2: fwd ? 1.0 : 0.1},
231 to: {value1: fwd ? 0.1 : 1.0, value2: fwd ? 0.1 : 1.0} }] });
250 }
232 }
251
233
252 slotWindowMinimized(window) {
234 slotWindowMinimized(window) {
@@ -254,30 +236,24 @@ class BurnMyWindowsMarbleMinimizeEffect {
254 const ir = window.iconGeometry;
236 const ir = window.iconGeometry;
255 if (!ir || ir.width == 0 || ir.height == 0) return; // no taskbar entry
237 if (!ir || ir.width == 0 || ir.height == 0) return; // no taskbar entry
256 this.stopAll(window);
238 this.stopAll(window);
257 const path = this.buildPath(window, ir);
239 const f = this.fallPlan(window, ir);
258 const morph = this.duration + this.pause;
240 const morph = this.duration + this.pause;
259 const total = morph + path.total;
241 const total = morph + f.T;
260 effect.setUniform(this.shader, "uForOpening", 0.0);
242 effect.setUniform(this.shader, "uForOpening", 0.0);
261 effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0);
243 effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0);
262 effect.setUniform(this.shader, "uDuration", total * 0.001);
244 effect.setUniform(this.shader, "uDuration", total * 0.001);
263 effect.setUniform(this.shader, "uCrumpleEnd", this.duration / Math.max(1, total));
245 effect.setUniform(this.shader, "uCrumpleEnd", this.duration / Math.max(1, total));
264 // ONE shader animation over the whole minimize (same setup as restore, which renders fine);
246 // one shader animation, deliberately longer; cancelled after the invisible tail (flash fix)
265 // a little longer than the path so the marble is drawn until the window is hidden.
266 window.bmwMinAnimation = animate({
247 window.bmwMinAnimation = animate({
267 // runs far past the path on purpose (uProgress just goes beyond 1 = marble); it is
268 // cancelled explicitly after the invisible tail, so a late chain can never expose
269 // the unshaded window.
270 window: window, curve: QEasingCurve.Linear, duration: total + 3000,
248 window: window, curve: QEasingCurve.Linear, duration: total + 3000,
271 animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: 0.0, to: (total + 3000) / Math.max(1, total) },
249 animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: 0.0, to: (total + 3000) / Math.max(1, total) },
272 { type: Effect.Opacity, from: 1.0, to: 1.0 }]
250 { type: Effect.Opacity, from: 1.0, to: 1.0 }]
273 });
251 });
274 // marker for the end of morph + pause; when it ends the path traversal starts
275 window.bmwMarbleDone = animate({
252 window.bmwMarbleDone = animate({
276 window: window, curve: QEasingCurve.Linear, duration: morph,
253 window: window, curve: QEasingCurve.Linear, duration: morph,
277 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: 0.0}, to: {value1: 0.0, value2: 0.0} }]
254 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: 0.0}, to: {value1: 0.0, value2: 0.0} }]
278 });
255 });
279 window.bmwPath = path; window.bmwSeg = -1; window.bmwMode = "min";
256 window.bmwFall = f; window.bmwMode = "morph"; window.bmwSegEnd = Date.now() + morph - 8;
280 window.bmwSegEnd = Date.now() + morph - 8;
281 }
257 }
282
258
283 slotWindowUnminimized(window) {
259 slotWindowUnminimized(window) {
@@ -285,10 +261,9 @@ class BurnMyWindowsMarbleMinimizeEffect {
285 const ir = window.iconGeometry;
261 const ir = window.iconGeometry;
286 this.stopAll(window);
262 this.stopAll(window);
287 if (!ir || ir.width == 0 || ir.height == 0) return;
263 if (!ir || ir.width == 0 || ir.height == 0) return;
288 // exact reverse: marble comes up the same S-path (reverse gravity timing), growing from
264 // reverse: rise from the icon (same curves reversed), rest, unfold
289 // 10% to 100% over the first 10% of the path, rests, then unfolds into the window.
265 const f = this.fallPlan(window, ir);
290 const path = this.buildPath(window, ir);
266 const total = this.duration + this.pause + f.T;
291 const total = this.duration + this.pause + path.total;
292 effect.setUniform(this.shader, "uForOpening", 0.0);
267 effect.setUniform(this.shader, "uForOpening", 0.0);
293 effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0);
268 effect.setUniform(this.shader, "uIsFullscreen", window.fullScreen ? 1.0 : 0.0);
294 effect.setUniform(this.shader, "uDuration", total * 0.001);
269 effect.setUniform(this.shader, "uDuration", total * 0.001);
@@ -297,87 +272,37 @@ class BurnMyWindowsMarbleMinimizeEffect {
297 window: window, curve: QEasingCurve.Linear, duration: total,
272 window: window, curve: QEasingCurve.Linear, duration: total,
298 animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: 1.0, to: 0.0 }]
273 animations: [{ type: Effect.ShaderUniform, fragmentShader: this.shader, uniform: "uProgress", from: 1.0, to: 0.0 }]
299 });
274 });
300 const T = path.total, nd = path.nodes, N = nd.length - 1;
275 this.fallAnims(window, f, -1);
301 // reversed timing: going from node N to node N-1 takes (t_N - t_{N-1}) etc.
302 window.bmwScaleAnimation = animate({
303 window: window, curve: QEasingCurve.InOutSine, duration: Math.max(1, T - nd[N - 2].t),
304 animations: [{ type: Effect.Scale, from: {value1: 0.1, value2: 0.1}, to: {value1: 1.0, value2: 1.0} }]
305 });
306 window.bmwPath = path; window.bmwMode = "rise";
307 window.bmwT0 = Date.now(); window.bmwCur = {x: nd[N].x, y: nd[N].y};
308 this.step(window);
309 }
276 }
310
277
311 stopAll(window) {
278 stopAll(window) {
312 window.bmwMode = null; window.bmwScaling = false;
279 window.bmwMode = null;
313 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwSegAnimation", "bmwScaleAnimation",
280 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation",
314 "bmwTailAnimation", "bmwUnminAnimation"]) {
281 "bmwTailAnimation", "bmwUnminAnimation"]) {
315 if (window[k]) { cancel(window[k]); delete window[k]; }
282 if (window[k]) { cancel(window[k]); delete window[k]; }
316 }
283 }
317 }
284 }
318
285
319 // Chain the path segments. KWin reports ids as 0 here, so we use our own state.
286 // KWin reports ids as 0 here, so we use our own state + end times.
320 slotAnimationEnded(window, id) {
287 slotAnimationEnded(window, id) {
321 if (!window || !window.bmwMode) return;
288 if (!window || !window.bmwMode) return;
322 if (window.bmwSegEnd && Date.now() < window.bmwSegEnd) return; // another animation ended
289 if (window.bmwSegEnd && Date.now() < window.bmwSegEnd) return; // another animation ended
323 const nd = window.bmwPath.nodes, N = nd.length - 1;
290 const f = window.bmwFall;
324 if (window.bmwMode == "tail") {
291 if (window.bmwMode == "morph") { // morph + pause done -> fall (one shot)
325 // invisible tail done: now stop the shader too; the window is hidden from here on
292 this.fallAnims(window, f, 1);
293 window.bmwMode = "fall"; window.bmwSegEnd = Date.now() + f.T - 8;
294 } else if (window.bmwMode == "fall") { // arrived: invisible hold at the icon
295 window.bmwTailAnimation = animate({
296 window: window, curve: QEasingCurve.Linear, duration: 250,
297 animations: [{ type: Effect.Translation, from: {value1: f.dx, value2: f.dy}, to: {value1: f.dx, value2: f.dy} },
298 { type: Effect.Scale, from: {value1: 0.1, value2: 0.1}, to: {value1: 0.1, value2: 0.1} },
299 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
300 });
301 window.bmwMode = "tail"; window.bmwSegEnd = Date.now() + 250 - 8;
302 } else if (window.bmwMode == "tail") { // now stop the shader; window is hidden
326 window.bmwMode = null;
303 window.bmwMode = null;
327 if (window.bmwMinAnimation) { cancel(window.bmwMinAnimation); delete window.bmwMinAnimation; }
304 if (window.bmwMinAnimation) { cancel(window.bmwMinAnimation); delete window.bmwMinAnimation; }
328 try { effects.addRepaintFull(); } catch (e) {}
305 try { effects.addRepaintFull(); } catch (e) {}
329 return;
330 }
331 if (window.bmwMode == "min" && window.bmwSeg < 0) { // morph + pause done
332 window.bmwSeg = 0; window.bmwT0 = Date.now(); window.bmwCur = {x: 0, y: 0};
333 }
334 this.step(window);
335 }
336
337 // Clock-driven path: every short segment aims at the path position for (now + STEP), measured
338 // from the real start time, so callback latency never accumulates (no drift, no stretch).
339 step(window) {
340 const STEP = 33; // ~2 frames per segment
341 const path = window.bmwPath, T = path.total, N = path.nodes.length - 1;
342 const now = Date.now() - window.bmwT0;
343 const end = path.nodes[N];
344 if (window.bmwMode == "min") {
345 if (now >= T - 4) {
346 // arrived: invisible hold at the icon (scale 10%) until the shader animation is cancelled
347 window.bmwTailAnimation = animate({
348 window: window, curve: QEasingCurve.Linear, duration: 250,
349 animations: [{ type: Effect.Translation, from: {value1: end.x, value2: end.y}, to: {value1: end.x, value2: end.y} },
350 { type: Effect.Scale, from: {value1: 0.1, value2: 0.1}, to: {value1: 0.1, value2: 0.1} },
351 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
352 });
353 window.bmwSegEnd = Date.now() + 250 - 8;
354 window.bmwMode = "tail";
355 return;
356 }
357 const tgt = Math.min(T, now + STEP);
358 const p = tgt >= T ? {x: end.x, y: end.y} : path.posAt(tgt);
359 if (!window.bmwScaling && tgt >= path.tScale) { // last 10% of arc length: 100% -> 10%
360 window.bmwScaling = true;
361 window.bmwScaleAnimation = animate({
362 window: window, curve: QEasingCurve.InOutSine, duration: Math.max(1, T - now),
363 animations: [{ type: Effect.Scale, from: {value1: 1.0, value2: 1.0}, to: {value1: 0.1, value2: 0.1} }]
364 });
365 }
366 window.bmwSegAnimation = this.segAnim(window, window.bmwCur, p, tgt - now);
367 window.bmwCur = p;
368 } else if (window.bmwMode == "rise") {
369 if (now >= T - 4) {
370 if (window.bmwCur.x != 0 || window.bmwCur.y != 0) {
371 window.bmwSegAnimation = this.segAnim(window, window.bmwCur, {x: 0, y: 0}, 1);
372 window.bmwCur = {x: 0, y: 0};
373 }
374 window.bmwMode = null;
375 return;
376 }
377 const tgt = Math.min(T, now + STEP);
378 const p = tgt >= T ? {x: 0, y: 0} : path.posAt(T - tgt);
379 window.bmwSegAnimation = this.segAnim(window, window.bmwCur, p, tgt - now);
380 window.bmwCur = p;
381 }
306 }
382 }
307 }
383
308