AWESOME-OS ENGINEERING BLOG

04 — Beyond CSS: Flat-Array O(N) Layout & Pluggable Window Managers for Millions of Users

04 — Beyond CSS: Flat-Array O(N) Layout & Pluggable Window Managers for Millions of Users

2026-11-19 · Awesome-OS Development History

If you ask why desktop apps feel sluggish at 120 Hz, why Electron eats gigabytes of RAM just to draw three panes, and why millions of users are forced to choose one rigid desktop paradigm (floating windows on Windows/macOS, or recompiling a Linux compositor to try tiling), the answer traces back to the same 1990s mistake: pointer-chasing layout trees coupled to a single hardcoded window manager.

Awesome-OS replaces both layers with one small, portable, zero-dependency engine: @awesome-os/b8g-layout.


1. Why Chrome / CSS / DOM Failed as an OS UI Substrate

The browser DOM was designed to flow static hypertext documents in 1994, not to compose live operating-system workspaces at 120 FPS:


2. Two-Sweep O(N) Flat-Array Layout -> 48B/Quad SabGpuQuadSlab

In packages/@awesome-os/b8g-layout/src/flat-layout.mts, there is no DOM tree, no CSS cascade, and no heap-allocated layout nodes.

Every UI frame lives in a contiguous, cache-friendly flat array (pre-order parent-before-child index order) using just four sizing primitives inspired by Clay / Morphorm:

Sizing Mode Semantics Typical Use
FIXED Exact pixel extent (value) Toolbars, icons, status pills, fixed dividers
FIT Intrinsic minimum bounding box of children + padding/gaps Buttons, badges, auto-sized headers
GROW Absorbs remaining parent axis space proportionally (weight) Main workspace panes, flexible editor columns
PERCENT Deterministic fraction of parent inner extent (0..1) Split ratios, responsive sidebars

The Deterministic Two-Sweep Pass

flowchart LR
    FLAT["Contiguous Flat Layout Array<br/>(Pre-order parent-before-child)"] --> UP["Sweep 1: Bottom-Up (i = N-1 -> 0)<br/>Compute FIT intrinsic sizes + padding/gaps"]
    UP --> DOWN["Sweep 2: Top-Down (i = 0 -> N-1)<br/>Distribute FIXED, PERCENT & GROW extents<br/>Write final (x, y, w, h) rects"]
    DOWN --> SLAB["SabGpuQuadSlab (48 B / quad)<br/>Zero-copy GPU upload -> b8g_render_v1"]

3. Four Pluggable Array-Intersection Window Managers (1 Click, Zero App Rewrites)

Because every Awesome-OS surface (a V8 isolate, a WASI .b8e cell, a terminal, or a CoW branched app frame) is just a flat array descriptor (SurfaceDescriptor with id, preferred bounds, min dimensions, and focus state), the Window Manager is no longer a monolithic daemon.

It is a pure O(N) projection function over the surface array in packages/@awesome-os/b8g-layout/src/window-managers.mts:

Mode (WindowManagerMode) Inspiration Geometry & User Guarantee
infinite-canvas Figma / spatial desktop 2D pan/zoom spatial projection (sx = (x - cameraX) * zoom + vp.x) with automatic viewport frustum culling (visible).
scroll-strip (default in WindowLayoutSection) Niri scrolling WM Infinite horizontal strip of full-height columns (clamp(preferredW, minW, vp.width - 2*gap)), offset by scrollX. Windows never get squished, no matter how many apps you open.
tile-bsp Hyprland / i3 Recursive binary space partitioning alternating longest-axis splits with uniform gap — zero wasted pixels, zero overlaps.
floating Classic desktop Cascaded overlapping windows with the focused surface automatically elevated to the highest zIndex.

Switching between all four paradigms is a single call: nextWindowManagerMode(current) (infinite-canvas -> scroll-strip -> tile-bsp -> floating) fed into computeWindowManagerLayout(mode, surfaces, viewport).

Zero app rewrites. Zero process restarts. Zero lost state. Every running Section and CoW frame keeps its exact memory slice and capability token while its projected screen geometry snaps instantaneously to the user's preferred mental model.


4. Live Integration: sections/canvas-branch & sections/window-layout

We wired @awesome-os/b8g-layout directly into both the portable schema layer and our live native wgpu canvas:

WindowLayoutSection (s.sqlite) now stores wmMode (default 'scroll-strip') alongside setWmMode and updateLayout ops — strictly zero node:* imports and erasableSyntaxOnly: true. Any Intersection composed with WindowLayoutSection automatically persists the user's chosen Window Manager across restarts.

In branch-runtime.host.mts and cli.host.mts, the native wgpu + winit + glyphon Infinite CoW Canvas toolbar now exposes a live [WM: canvas|strip|bsp|float] button (toolbar:wm-cycle).


5. Try It Yourself

# Launch the native wgpu Infinite CoW Canvas and click [WM: canvas] in the top toolbar
& "e:\awesome-os\packages\@awesome-os\bin-shim\bin\node.ps1" --experimental-strip-types `
  e:\awesome-os\sections\canvas-branch\cli.host.mts --window

# Inspect or switch persisted WM mode via dev-catalog
bin\dev-catalog.ps1 invoke section.window-layout setWmMode '{"wmMode":"tile-bsp"}'

Related anchors: packages/@awesome-os/b8g-layout/src/index.mts · flat-layout.mts · window-managers.mts · sections/window-layout/index.mts · sections/canvas-branch/branch-runtime.host.mts

← Back to all 27 engineering posts