BlueGit

timfa kwin-marble

Marble Magic Lamp: centre scale anchors + compensate expanded-geometry offset so the marble ends on the icon

timfa Tim Falken · pushed by timfa

Authored 2026-11-02 · 2 weeks ago

Hash
23d86a02704891f3bf980f3a93a2c56ac6930868
Parent
cc41ded6
1 file changed +16 −6
kwin6_effect_marble_minimize/contents/code/main.js +16 −6
@@ -209,7 +209,12 @@ class BurnMyWindowsMarbleMinimizeEffect {
209 209 const vertical = k < 2; // taskbar at top/bottom
210 210 const along = Math.max(30, Math.abs(vertical ? dy : dx));
211 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};
212 // KWin scales around the centre of the expanded geometry (incl. shadow), not the window
213 // centre; when the marble shrinks to ~0 it would drift there. Offset to compensate.
214 let ox = 0, oy = 0;
215 try { const eg = window.expandedGeometry;
216 ox = (wr.x + wr.width / 2) - (eg.x + eg.width / 2); oy = (wr.y + wr.height / 2) - (eg.y + eg.height / 2); } catch (e) {}
217 return {dx: dx, dy: dy, T: Math.max(1, T), vertical: vertical, ox: ox, oy: oy};
213 218 }
214 219
215 220 // dir: 1 = minimize (towards the icon), -1 = restore (time-reversed)
@@ -227,12 +232,17 @@ class BurnMyWindowsMarbleMinimizeEffect {
227 232 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: ay[0]}, to: {value1: 0.0, value2: ay[1]} }] });
228 233 // scale 100% -> 10% essentially in the last part (InExpo stays ~1 until late); reverse = OutExpo
229 234 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},
235 animations: [{ type: Effect.Scale, sourceAnchor: Effect.Horizontal | Effect.Vertical, targetAnchor: Effect.Horizontal | Effect.Vertical, from: {value1: fwd ? 1.0 : 0.1, value2: fwd ? 1.0 : 0.1},
231 236 to: {value1: fwd ? 0.1 : 1.0, value2: fwd ? 0.1 : 1.0} }] });
237 // anchor compensation that grows with the shrink (same late curve), so the marble stays on
238 // the path and ends exactly on the icon centre
239 window.bmwCompAnimation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
240 animations: [{ type: Effect.Translation, from: {value1: fwd ? 0 : f.ox, value2: fwd ? 0 : f.oy},
241 to: {value1: fwd ? f.ox : 0, value2: fwd ? f.oy : 0} }] });
232 242 // second, multiplying scale: ~1 until the very end, then to ~0 (combined ~10% at 95%,
233 243 // ~0 at 100%), so the last frames are effectively invisible. 0.001 instead of 0 (no /0).
234 244 window.bmwScale2Animation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
235 animations: [{ type: Effect.Scale, from: {value1: fwd ? 1.0 : 0.001, value2: fwd ? 1.0 : 0.001},
245 animations: [{ type: Effect.Scale, sourceAnchor: Effect.Horizontal | Effect.Vertical, targetAnchor: Effect.Horizontal | Effect.Vertical, from: {value1: fwd ? 1.0 : 0.001, value2: fwd ? 1.0 : 0.001},
236 246 to: {value1: fwd ? 0.001 : 1.0, value2: fwd ? 0.001 : 1.0} }] });
237 247 }
238 248
@@ -284,7 +294,7 @@ class BurnMyWindowsMarbleMinimizeEffect {
284 294
285 295 stopAll(window) {
286 296 window.bmwMode = null;
287 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation", "bmwScale2Animation",
297 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation", "bmwScale2Animation", "bmwCompAnimation",
288 298 "bmwTailAnimation", "bmwUnminAnimation", "bmwFadeInAnimation"]) {
289 299 if (window[k]) { cancel(window[k]); delete window[k]; }
290 300 }
@@ -304,8 +314,8 @@ class BurnMyWindowsMarbleMinimizeEffect {
304 314 } else if (window.bmwMode == "fall") { // arrived: invisible hold at the icon
305 315 window.bmwTailAnimation = animate({
306 316 window: window, curve: QEasingCurve.Linear, duration: 250,
307 animations: [{ type: Effect.Translation, from: {value1: f.dx, value2: f.dy}, to: {value1: f.dx, value2: f.dy} },
308 { type: Effect.Scale, from: {value1: 0.001, value2: 0.001}, to: {value1: 0.001, value2: 0.001} },
317 animations: [{ type: Effect.Translation, from: {value1: f.dx + f.ox, value2: f.dy + f.oy}, to: {value1: f.dx + f.ox, value2: f.dy + f.oy} },
318 { type: Effect.Scale, sourceAnchor: Effect.Horizontal | Effect.Vertical, targetAnchor: Effect.Horizontal | Effect.Vertical, from: {value1: 0.001, value2: 0.001}, to: {value1: 0.001, value2: 0.001} },
309 319 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
310 320 });
311 321 window.bmwMode = "tail"; window.bmwSegEnd = Date.now() + 250 - 8;
@@ -209,7 +209,12 @@ class BurnMyWindowsMarbleMinimizeEffect {
209 const vertical = k < 2; // taskbar at top/bottom
209 const vertical = k < 2; // taskbar at top/bottom
210 const along = Math.max(30, Math.abs(vertical ? dy : dx));
210 const along = Math.max(30, Math.abs(vertical ? dy : dx));
211 const T = animationTime(Math.round(1000 * Math.sqrt(2 * along / this.gravity)));
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};
212 // KWin scales around the centre of the expanded geometry (incl. shadow), not the window
213 // centre; when the marble shrinks to ~0 it would drift there. Offset to compensate.
214 let ox = 0, oy = 0;
215 try { const eg = window.expandedGeometry;
216 ox = (wr.x + wr.width / 2) - (eg.x + eg.width / 2); oy = (wr.y + wr.height / 2) - (eg.y + eg.height / 2); } catch (e) {}
217 return {dx: dx, dy: dy, T: Math.max(1, T), vertical: vertical, ox: ox, oy: oy};
213 }
218 }
214
219
215 // dir: 1 = minimize (towards the icon), -1 = restore (time-reversed)
220 // dir: 1 = minimize (towards the icon), -1 = restore (time-reversed)
@@ -227,12 +232,17 @@ class BurnMyWindowsMarbleMinimizeEffect {
227 animations: [{ type: Effect.Translation, from: {value1: 0.0, value2: ay[0]}, to: {value1: 0.0, value2: ay[1]} }] });
232 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
233 // 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,
234 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},
235 animations: [{ type: Effect.Scale, sourceAnchor: Effect.Horizontal | Effect.Vertical, targetAnchor: Effect.Horizontal | Effect.Vertical, 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} }] });
236 to: {value1: fwd ? 0.1 : 1.0, value2: fwd ? 0.1 : 1.0} }] });
237 // anchor compensation that grows with the shrink (same late curve), so the marble stays on
238 // the path and ends exactly on the icon centre
239 window.bmwCompAnimation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
240 animations: [{ type: Effect.Translation, from: {value1: fwd ? 0 : f.ox, value2: fwd ? 0 : f.oy},
241 to: {value1: fwd ? f.ox : 0, value2: fwd ? f.oy : 0} }] });
232 // second, multiplying scale: ~1 until the very end, then to ~0 (combined ~10% at 95%,
242 // second, multiplying scale: ~1 until the very end, then to ~0 (combined ~10% at 95%,
233 // ~0 at 100%), so the last frames are effectively invisible. 0.001 instead of 0 (no /0).
243 // ~0 at 100%), so the last frames are effectively invisible. 0.001 instead of 0 (no /0).
234 window.bmwScale2Animation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
244 window.bmwScale2Animation = animate({ window: window, curve: fwd ? QEasingCurve.InExpo : QEasingCurve.OutExpo, duration: f.T,
235 animations: [{ type: Effect.Scale, from: {value1: fwd ? 1.0 : 0.001, value2: fwd ? 1.0 : 0.001},
245 animations: [{ type: Effect.Scale, sourceAnchor: Effect.Horizontal | Effect.Vertical, targetAnchor: Effect.Horizontal | Effect.Vertical, from: {value1: fwd ? 1.0 : 0.001, value2: fwd ? 1.0 : 0.001},
236 to: {value1: fwd ? 0.001 : 1.0, value2: fwd ? 0.001 : 1.0} }] });
246 to: {value1: fwd ? 0.001 : 1.0, value2: fwd ? 0.001 : 1.0} }] });
237 }
247 }
238
248
@@ -284,7 +294,7 @@ class BurnMyWindowsMarbleMinimizeEffect {
284
294
285 stopAll(window) {
295 stopAll(window) {
286 window.bmwMode = null;
296 window.bmwMode = null;
287 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation", "bmwScale2Animation",
297 for (const k of ["bmwMinAnimation", "bmwMarbleDone", "bmwXAnimation", "bmwYAnimation", "bmwScaleAnimation", "bmwScale2Animation", "bmwCompAnimation",
288 "bmwTailAnimation", "bmwUnminAnimation", "bmwFadeInAnimation"]) {
298 "bmwTailAnimation", "bmwUnminAnimation", "bmwFadeInAnimation"]) {
289 if (window[k]) { cancel(window[k]); delete window[k]; }
299 if (window[k]) { cancel(window[k]); delete window[k]; }
290 }
300 }
@@ -304,8 +314,8 @@ class BurnMyWindowsMarbleMinimizeEffect {
304 } else if (window.bmwMode == "fall") { // arrived: invisible hold at the icon
314 } else if (window.bmwMode == "fall") { // arrived: invisible hold at the icon
305 window.bmwTailAnimation = animate({
315 window.bmwTailAnimation = animate({
306 window: window, curve: QEasingCurve.Linear, duration: 250,
316 window: window, curve: QEasingCurve.Linear, duration: 250,
307 animations: [{ type: Effect.Translation, from: {value1: f.dx, value2: f.dy}, to: {value1: f.dx, value2: f.dy} },
317 animations: [{ type: Effect.Translation, from: {value1: f.dx + f.ox, value2: f.dy + f.oy}, to: {value1: f.dx + f.ox, value2: f.dy + f.oy} },
308 { type: Effect.Scale, from: {value1: 0.001, value2: 0.001}, to: {value1: 0.001, value2: 0.001} },
318 { type: Effect.Scale, sourceAnchor: Effect.Horizontal | Effect.Vertical, targetAnchor: Effect.Horizontal | Effect.Vertical, from: {value1: 0.001, value2: 0.001}, to: {value1: 0.001, value2: 0.001} },
309 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
319 { type: Effect.Opacity, from: 0.0, to: 0.0 }]
310 });
320 });
311 window.bmwMode = "tail"; window.bmwSegEnd = Date.now() + 250 - 8;
321 window.bmwMode = "tail"; window.bmwSegEnd = Date.now() + 250 - 8;