Metrix.Bar

Documentation / Render Surfaces

Render Surfaces

Contracts for every Metrix.Bar render target: menu bar tray, panels, windows, screen sidebars, system widgets, the notch, overlays, and selection popovers.

Overview

render(env) returns a plain object selecting any subset of supported output surfaces (omit render entirely for headless Workers):

js
export default {
  render(env) {
    return {
      tray: { title: "42" },
      panel: { type: "Column", props: { padding: 16 }, children: [/* ... */] },
      widget: { small: { type: "Text", props: { text: "42", fontSize: 28, bold: true } } },
      notch: { compact: { leading: /* ... */, trailing: /* ... */ }, minimal: /* ... */, expanded: /* ... */ },
      overlay: null,
      selectionPopover: null,
    };
  },
};

All entrances for one dashboard instance share a single Worker, state, and committed render() output. Use $metrix.outputs() or event("outputs", snapshot) to avoid building unused surface trees.


Return tray: null or tray.hidden: true (probe render.tray.hidden) to hide the menu bar item while keeping screen sidebar entries visible. Combine with <bar hide-when-empty="true"> (probe hide-when-empty) to auto-hide whenever title, content, iconAnimation, error, and non-cleared icon are all empty.

FieldDescription
titleShort string shown in the macOS menu bar, Windows tray tooltip, or Linux tray menu's first item.
iconSystem icon name, remote image URL (needs <network>), or data: URI. Pass icon: null on macOS (probe render.tray.icon.clear) to clear the icon and show title alone; omitting or "" keeps the current icon.
iconTemplatetrue forces macOS template image tinting for light/dark mode and menu highlights.
iconAnimationHost-driven frame animation on macOS (takes precedence over content and icon).
contentRestricted native display tree on macOS (takes precedence over icon/title).
tooltipHover tooltip string (sidebar tooltip falls back tray.title → tray.error → tray.tooltip → bar.title).
errorData-fetch failure reason (keep last useful value in title and explain details in panel). Status stays ok; macOS shows ! when title is empty.
hideDefaultRefreshtrue hides the host's default Refresh item in the tray context menu (probe render.tray.menu.hideDefaultRefresh).
menuRight-click MenuItem[] array; refreshes patch items in place by id and defer structural rebuilds while open to preserve focus and submenus.
dropFiles / onDrop / onDragOverAccept local file/folder drops on macOS menu bar items and macOS/Windows/Linux sidebar icons (see File drops).

Supported on native macOS once ready (probe await $metrix.caniuse("render.tray.content")); keep tray.title/tray.icon as fallbacks for other platforms and accessibility.

  • Root: Integer width 16..240 DIP and height: 22.
  • Nodes & budgets: Row, Column, Text, Spacer, Chart, and (when render.tray.content.icon is true) Icon with inline svg ≤ 2048 UTF-8 bytes and optional fontSize 8..22. Max 64 nodes, depth 12, 4096 bytes of text + inline SVG.
  • Props: Layout width/height/gap/padding/paddingX/paddingY (0..240), alignItems, justify; Text text, fontSize (8..22), fontWeight (100..900 in steps of 100); Chart type: "line" | "area", series: [{ name, points: [{ x, y }] }], strokeWidth (0.5..4), max 4 series per chart and 120 points across the tree (finite JS-safe numbers, no axes/legend/hover/animation). All elements draw in system template tint over transparent background; callbacks and external resources are rejected.
js
const tray = { title: "CPU 24%", icon: "ri:cpu-line" };
if (await $metrix.caniuse("render.tray.content")) {
  tray.content = {
    type: "Row",
    props: { width: 96, height: 22, alignItems: "center" },
    children: [{ type: "Text", props: { text: "CPU 24%", fontSize: 12 } }],
  };
}

Plays an inline SVG animation beside tray.title on macOS (probe await $metrix.caniuse("render.tray.iconAnimation")).

  • frames: Array of 1..8 self-contained inline SVG strings (≤ 2048 UTF-8 bytes each, consistent viewBox), rasterized at standard menu bar icon size with tray.iconTemplate.
  • intervalMS: Integer 80..1000 for looping playback, or 0 for a static first frame (macOS Reduce Motion also shows frame 0). Plays independently of Worker refreshes. Falls back to tray.content, then tray.icon/tray.title.

Shared by tray.menu, node contextMenu, popoverMenu, popoverMenuButton, and MenuButton / PopoverMenuButton:

FieldDescription
idOptional stable ID for in-place patching across refreshes (probe render.tray.menu.id).
label, onClick, disabledLabel text, click handler, disabled flag.
subtitle, badge, iconSecondary line, trailing badge text, or icon ref (probes render.tray.menu.subtitle/badge/icon).
separatortrue draws a divider and ignores all other fields.
checked, radio, dangerCheck/radio marks (script manages radio exclusivity; probe render.tray.menu.radio) and destructive styling.
keepOpenKeeps the system menu open after clicking where supported (probe render.tray.menu.keepOpen).
shortcut, tooltipDisplay accelerator (e.g. "Cmd+Shift+P", probe render.tray.menu.shortcut; use registerShortcut for global hotkeys) and macOS hover tooltip (render.tray.menu.tooltip).
itemsNested MenuItem[] submenu.

Panels, sidebars & windows (panel)

Opening modes & window styles

Users can independently enable and choose an opening mode for each trigger source (menubar, sidebar-left, sidebar-right, sidebar-bottom, shortcut, notch). <bar open-mode="…" window-style="…"> provides author defaults only:

  • flyout (default): Arrowless popover beside the clicked menu bar or sidebar icon. Retains rounded corners and shadow on macOS (removed under material="transparent").
  • dialog: Full-display translucent scrim (~12% black; ~40% in High Contrast) centering the panel card without entering a system fullscreen space. Content defaults to preferredWidth/preferredHeight → width/height → 320×480 DIP, capped at 80% of display bounds (≥ 10% margins) with internal scrolling. Click outside or press Esc to close (dismisses inner overlays first). Unavailable on Linux GNOME native Wayland.
  • window / fullscreen: Resizable native window (set resizable: false on the panel root to lock resizing) that stays open on blur and remembers size, maximized, and fullscreen states (open-mode="fullscreen", probe open-mode.fullscreen). Re-triggering focuses or restores the existing window; minimizing still counts as open and sends no collapse event.
  • Window appearance (window-style): standard (system title bar), immersive (content draws behind title bar from (0,0) with native controls), or frameless (no title bar or frame; probe window-style.frameless). Non-interactive regions drag immersive/frameless windows; combine window-style="frameless" + material="transparent" for transparent floating windows.

Panel material

Set host surface material via <bar material="glass" | "solid" | "transparent"> (changes take effect after reload and next panel open):

  • glass (default): Preserves system Vibrancy or tinted Glass fallback with translucent controls. Avoid setting an opaque background on the panel root if you want glass visible.
  • solid: Opaque theme Surface with regular controls.
  • transparent (probe render.panel.material.transparent): Removes host fill, border, and shadow so custom cards or shaped widgets float over the desktop (does not change the Dialog backdrop).

Responsive windows & safe areas

  • Set preferredWidth / preferredHeight on the panel root for initial window, flyout, and preview dimensions without locking layout. Without a height, flyouts and management previews size to content up to 640 DIP (put a Scroll inside for taller content).
  • Set safeArea: true on a root Box/Column/Row/Grid in immersive windows so backgrounds reach (0,0) while children, hit targets, and clipping stay below the native title bar (not allowed in state styles; nested safe areas do not double-inset). Keep Scroll inside with grow: 1, minHeight: 0.
  • Read env.viewport ({ width, height, titleBar: { height, left, right } }, in DIP) only for structural breakpoints (e.g. column count); let native flex/grid handle ordinary resizing.
js
const panel = {
  type: "Column",
  props: { preferredWidth: 420, preferredHeight: 560, fill: true, minHeight: 0, safeArea: true },
  children: [
    Header(),
    { type: "Scroll", props: { grow: 1, minHeight: 0, fillWidth: true }, children: [Body()] },
  ],
};

Screen sidebars

Screen sidebars expand one display/edge rail at a time (~100 ms hover on the middle 25%–75% of an outer screen edge, 2 DIP thick; 300 ms close delay after leaving rail/panel/menu). Icons fall back tray.icon → bar.icon → generic glyph. Hold Cmd (macOS) or Ctrl (Windows/Linux) and drag icons to reorder dashboards globally. Requires X11 or Wayland with libgtk-layer-shell.so.0 on Linux.

Programmatic panel control ($metrix.panel)

Requires panel="true" (default). When <bar panel="false"> is declared, clicking tray/sidebar icons opens the context menu directly, panel previews and panel-only settings are hidden, clicking a widget opens the dashboard in the main window, $metrix.panel.* rejects, and caniuse("panel") / caniuse("render.panel") return false.

All methods require no apis opt-in, target only the current dashboard, and return Promise<PanelState> ({ open, mode, source, alwaysOnTop, alwaysOnTopSupported, alwaysOnTopEffective, fullScreen }; mode is flyout|dialog|window|null, source is menubar|notch|sidebar-left|sidebar-right|sidebar-bottom|shortcut|desktop-app|programmatic|null):

  • $metrix.panel.open(), close(), toggle(), state() (plus $metrix.togglePanel()): Follow effective default open_mode (Dialog rejects if screen positioning is unavailable). Staging allows state() only.
  • await $metrix.panel.setAlwaysOnTop(boolean): Persists and applies the independent Window topmost preference (probe panel.setAlwaysOnTop; macOS/Windows report alwaysOnTopEffective, X11 reports null, Wayland rejects enabling while allowing clearing).
  • await $metrix.panel.setFullScreen(boolean) & await $metrix.panel.isFullScreen(): Toggle/query native fullscreen on the independent Window (probes panel.setFullScreen, panel.isFullScreen).

System widgets (widget)

Declare <bar widget="true"> and return widget: { small?, medium?, large? } from render(). Missing families fall back in small → medium → large order. Probe widget and render.widget. Requires macOS 14+, Windows 11 22H2+, KDE Plasma 6 (companion plasmoid), or Linux MetrixWidgetAdapters/ (Cinnamon Desklets, Eww, Quickshell).

Physical proportions differ by OS (macOS small is square and medium is wide; Windows small is wide and medium is roughly square; KDE Plasma starts at 180×180, switching to medium at 300×180 and large at 300×360). Branch on read-only $metrix.platform ("darwin" | "windows" | "linux" | "js") rather than env.viewport:

js
const isWin = $metrix.platform === "windows";
return {
  widget: {
    small: isWin ? horizontalSummary() : squareSummary(),
    medium: isWin ? squareDetails() : horizontalDetails(),
    large: fullDetails(),
  },
};

Supported widget subset

Use explicit properties only—tw classes, callbacks, interactive controls, and Markdown are unsupported (plain text is literal; clicking a card opens/focuses the dashboard window):

| Components | Supported properties | | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | | Column, Row, Box | gap, padding, alignItems (start/center/end), width, height, background, radius | | Grid | Column props + columns (1..12, equal-width) | | Text | text, fontSize (8..96), fontWeight (100..900), bold, italic, color/textColor, maxLines (1..10), textAlign, padding | | RichText | Text styles + spans (≤ 128 literal spans with text, size, weight, italic, underline, strikethrough, color; probe render.widget.richText) | | Badge | text, fontSize, fontWeight, bold, italic, color/textColor, background (probe render.widget.badge.background), padding | | Avatar | name, src, size (8..96, default 32), color/textColor, background, padding (probe render.widget.avatar) | | Icon | Inline svg (≤ 64 KiB, drawn as single-color mask), size (8..96, default 16), color/textColor, padding | | Image | src (permitted URL or metrix-image://), width, height, radius, padding | | Progress | value (0..1), color/textColor, padding | | Meter | value, min (0), max (1), levels: { warning?, critical? }, color/textColor, padding (probe render.widget.meter) | | Chart | type (line/area/bar/pie), height, width, series, data, innerRadius (0..0.95), yDomain, strokeWidth, padding (probe render.widget.chart) | | Spacer, Divider, text | Native spacing, separator (orientation: "horizontal" | "vertical", probe render.widget.divider.orientation), or literal text |

  • Colors: primary, secondary, accent, success, warning, error, or #RRGGBB / #RRGGBBAA.
  • Widget Chart: Glanceable PNG snapshot rendered at 2× density (max 1024×256 DIP) with no axes, legends, or hover (interactive props are rejected). line/area/bar accept ≤ 4 series of { color, points } (≤ 256 evenly spaced numbers or { y } each); pie accepts ≤ 16 data items of { value, color }.
  • Windows Adaptive Cards 1.6: Maps semantic backgrounds to card styles (ignores hex backgrounds and radius), maps custom hex text colors to primary text, reserves space for the system menu in the first row, and draws Progress via cached proportional bars.
  • Limits & lifecycle: Max 512 nodes, depth 24, 512 KiB catalog; images ≤ 2048 px/side, 1,048,576 px total, 8 MiB source / 4 MiB PNG, shared 64 MiB / 128-file cache. Secrets/inputs/errors never leave the host. Refresh failures preserve the last successful snapshot. Configured widget demand keeps the Worker active with a 1-minute minimum automatic polling interval; the OS controls card refresh cadence.

Notch (notch)

Declare <bar notch="true">. Available with Plus on macOS and Windows (virtual notch on notchless displays; hidden on Linux). Probe await $metrix.caniuse("render.notch").

Return notch: { compact: { leading, trailing }, minimal, expanded, activity?, onFileDrop?, transferFormats?, onTransferDrop? }:

  • States & geometry: Use $metrix.outputs().notch ("compact" | "minimal" | "expanded" or omitted) to render only what is requested.
    • compact.leading / compact.trailing: Left and right wings beside the camera (≥ 36 DIP wide, ~20–26 DIP tall)—keep each to one icon, artwork, or ≤ 4 characters (e.g. 100%).
    • minimal: Small round bubble beside the island for the second notch dashboard (additional dashboards count on that bubble and appear in the expanded switcher).
    • expanded: Interactive panel tree (≤ 460×340 DIP, scrolls beyond) with normal Worker callbacks; hover previews on macOS, click expands on macOS/Windows with pin, switcher, and full-panel open button.
  • Temporary activity (notch.activity): { id, expiresAt } (new id per activity, absolute Unix ms expiresAt, max 8 hours; probe render.notch.activity) brings the dashboard into the island until it expires, is dismissed, or is removed.
  • Programmatic expansion ($metrix.notch.setState): Requires user toggle Allow automatic notch expansion (off by default; probe notch.setState):
    js
    if (await $metrix.caniuse("notch.setState")) {
      await $metrix.notch?.setState("expanded", { durationMs: 8000 });
    }
    durationMs is 1..30000 (default 8000), preserves keyboard focus, waits 3 s cooldown after ending, and resolves "accepted" | "busy" | "unavailable" | "idle". Call setState("collapsed") to end your preview early.
  • Drops: Set notch.onFileDrop (probe render.notch.fileDrop, receives source: "notch") or notch.transferFormats + notch.onTransferDrop (probe render.notch.transfer). See File drops and Rich transfers.

Overlay (overlay)

Declare <bar overlay="true"> to render a borderless screen-level transparent tree from render().overlay controlled via $metrix.overlay:

  • await $metrix.overlay.open({ displays?: "primary" | "cursor" | "all" | string[], clickThrough?: boolean }) → { open, displays, clickThrough }
  • await $metrix.overlay.close() / await $metrix.overlay.state()

With clickThrough: true (probe overlay.clickThrough), pointer events pass through to underlying apps everywhere except subtrees marked inputRegion: true. Pressing Esc closes the overlay; click-through overlays require the global exit shortcut (Cmd+Shift+Esc on macOS, Ctrl+Shift+Esc on Windows/Linux) and reject opening if unavailable. Closing the Worker or disabling the dashboard closes its overlays. Probe overlay, overlay.*, and render.overlay (false on GNOME native Wayland without layer-shell).


Selection popover (selectionPopover)

Dashboards declaring <selection-actions> can return render().selectionPopover (falling back to render().panel) to display results anchored beside the selected text without disturbing the main panel. Control with $metrix.selectionPopover:

  • await $metrix.selectionPopover.open({ anchor?: { x, y, width, height }, pinned?: boolean }) → { open, pinned }
  • await $metrix.selectionPopover.close() / setPinned(boolean) / state()

Esc always closes the popover; mark a header container with dragWindow: true to make it draggable. Probe selectionPopover, selectionPopover.*, and render.selectionPopover.