Compiz wobbly windows and cube

I wanted to see if I could rebuild Compiz Fusion's 2006 spring-mesh wobbly windows and translucent 4-face 3D desktop cube on live HTML windows inside one WebGL 2 canvas. Grab the orange titlebar (or press Fling / Shake) to stretch the 4 by 4 Bezier grid, then switch to the 3D desktop cube and drag to spin between four live workspaces while clicking straight into whichever face is in front.

~> compiz@beryl-2006: ~/wobbly
0 pings
Workspace 1: Notes front +Z
0 stamps
Workspace 2: Mixer right +X
ALSA live
Workspace 3: Checklist back -Z
4/4 ready
Workspace 4: Desktop left -X
00:00:00
Beryl indigo
Drag the orange titlebar or press Fling / Shake to test the 4 by 4 spring mesh.
Show the code 4x4 Bezier springs, 20x20 WebGL mesh, affine hit box, 3D cube and projective geometry
  1. Five live HTML windows in one drawable canvas. One wobbly desktop window and four cube workspace panels sit as drawable children inside one <canvas layoutsubtree>, with inactive panels kept inert.
  2. 4 by 4 Bezier spring-mass grid. Uses Compiz's vectorial rest-offset springs with 240 Hz symplectic substeps so grabbing any corner shears and ripples the window without folding inside out.
  3. 20 by 20 Bezier triangle mesh shader. Evaluates cubic Bernstein polynomials on the GPU from the 16 spring control points, with drop shadow, subtle stretch sheen and optional wireframe overlay.
  4. Affine hit-box tracking during wobble. Fits a least-squares sheared DOMMatrix to the four deformed spring corners, scales it by geometryUnit() and toggles dataset.hitTick when the transform moves.
  5. Translucent 4-face cube and floor reflection. Sorts the six convex faces (four live HTML workspaces plus two Compiz caps) back-to-front in camera space for both the floor reflection and the hovering cube.
  6. Projective updateElementGeometry() on the front face. Composes the same view-projection matrix used in GLSL into a 4 by 4 DOMMatrix for the frontmost workspace while leaving the other three faces inert.

How it works

Both modes share one WebGL 2 context created through new ElementGL(canvas, ...) from /lib/element-gl.js. Inside the canvas's paint handler, I upload the active drawable HTML elements with stage.upload() (which calls gl.texElementSubImage2D()), save ElementGL's current program and vertex array object, run the desktop backdrop, spring mesh or 3D cube shaders on stage.gl, and restore the bindings. If a browser lacks texElementSubImage2D(), the page drops to a 2D canvas using 5-argument drawElementImage(); if the WebGL context is lost or HTML-in-canvas isn't available, the five live elements move into plain HTML without losing your typed text or slider values.

In wobbly mode, the window sits on a 4 by 4 grid of 16 mass points linked by 24 springs, the same layout Compiz used in 2006. Each spring stores a vectorial rest offset ((stepX, 0) horizontally and (0, stepY) vertically) rather than a scalar distance, so the window always recovers upright instead of spinning or collapsing. When you grab the titlebar, the nearest grid vertex locks to your pointer while the remaining 15 nodes lag and overshoot through 240 Hz substeps. On the GPU, a static 20 by 20 triangle mesh evaluates the bicubic Bezier surface directly from those 16 control points.

canvas.updateElementGeometry() takes a linear 4 by 4 DOMMatrix, so it can't curve a hit box along a cubic Bezier patch. Instead, I fit a least-squares affine matrix to the four moving corners, scale it by geometryUnit() from /lib/surface.js, and flip dataset.hitTick whenever the quantized transform changes so Chromium clears its cached hit result. At rest the linear box matches the window to 0.0 px, and while wobbling it follows the window's live translation, stretch and shear so the inputs and buttons stay clickable.

Switching to the 3D desktop cube marks the wobbly window inert and uploads all four live workspaces on every paint. Because a cube is convex, sorting its four live side panels and two procedural caps back-to-front in view space gives clean premultiplied alpha translucency without depth-buffer artefacts, both for the cube and for its mirrored reflection on the dark glossy floor. Only the workspace facing the camera receives a projective DOMMatrix via updateElementGeometry(); the three faces behind it stay inert so clicks and Tab focus never fall through to a hidden side.

Live checks

These checks build isolated fixtures on testStage() and wait for a tap so opening the page never opens extra WebGL contexts or steals focus.

StatusCheckResult

Findings