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.
Show the code 4x4 Bezier springs, 20x20 WebGL mesh, affine hit box, 3D cube and projective geometry
- Five live HTML windows in one drawable canvas. One wobbly desktop window and four cube workspace panels sit as
drawablechildren inside one<canvas layoutsubtree>, with inactive panels keptinert. - 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.
- 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.
- Affine hit-box tracking during wobble. Fits a least-squares sheared
DOMMatrixto the four deformed spring corners, scales it bygeometryUnit()and togglesdataset.hitTickwhen the transform moves. - 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.
- Projective
updateElementGeometry()on the front face. Composes the same view-projection matrix used in GLSL into a 4 by 4DOMMatrixfor the frontmost workspace while leaving the other three facesinert.
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.
| Status | Check | Result |
|---|
Findings
- Static checks passed on 2026-11-27 (
node --check public/compiz/compiz.js,node tools/gfx/check.mjswith 0 problems, andnode tools/writing/check.mjs --strict /compiz/with 0 errors and 0 warnings). Live browser runs on headless Chromium 157 and Chrome 159 for Android are not verified yet. - Using vectorial rest-offset springs on the 4 by 4 Bezier grid keeps the deformed HTML window upright across large drags and shakes, whereas scalar distance springs allow the grid to buckle or invert under fast impulses.
- Putting the bicubic Bernstein evaluation in the WebGL 2 vertex shader means the 20 by 20 triangle mesh (441 vertices, 800 triangles) uploads to the GPU once, and each physics frame sends only 16
vec2control points. - Because
updateElementGeometry()accepts a 4 by 4DOMMatrix, the flat 3D cube faces get an exact perspective hit box while the curved Bezier window uses a 4-corner affine approximation that converges back to0.0 pxerror as the springs settle. - Keeping inactive mode windows and the three non-front cube faces
inertstops hiddendrawablechildren inside<canvas layoutsubtree>from trapping keyboard Tab focus or stealing clicks through translucent faces.