# Display surfaces

> Keep a strip of the glasses display on screen beside other miniapps.

Source: https://docs.dev.glasslyos.com/app-devs/core-concepts/display/surfaces/

A display surface is a strip along one edge of the canvas that stays on screen
beside whatever the main content is. Use one for a dock, a status line or a
rail. Declare `DISPLAY_SURFACES` in your
[manifest](https://docs.dev.glasslyos.com/app-devs/core-concepts/miniapp-manifest.md). There is no OS prompt, and
the Store listing says "Keep a strip on the glasses display". Its canonical key in
[`session.permissions`](https://docs.dev.glasslyos.com/app-devs/core-concepts/permissions.md) is `displaySurfaces`.

```ts
const result = await session.display.requestSurface({id: "rail", edge: "left", size: 96, maxTextElements: 4, maxImageElements: 4})
if (result.status === "granted") {
  const rail = result.surface
  rail.onChange(({surface}) => surface && drawRail(surface.width, surface.height))
  await rail.render([{type: "rect", box: {x: 8, y: 8, w: 80, h: 80}, style: {radius: 8}}])
}
```

## Request a surface

`requestSurface` resolves to `{status: "granted", surface}` or
`{status: "refused", reason}`.

| Option | Meaning |
|---|---|
| `id` | Your name for the surface. Asking again with the same `id` resizes or moves it. |
| `edge` | `"top"`, `"bottom"`, `"left"` or `"right"`. Each edge holds one surface, and the newest request takes it; the previous holder ends with reason `"replaced"`. |
| `size` | The strip's depth in pixels across its edge, at most a third of the canvas. |
| `maxTextElements`, `maxImageElements` | The element counts you need. Text and rects share the text budget. All surfaces together get at most half of each of the glasses' budgets, granted oldest first. |

Only glasses that position and animate elements show surfaces (G2 on Glassly
firmware, simulated glasses). Elsewhere requests are refused and held surfaces
are hidden.

## Draw and release

`DisplaySurface` has:

- `id`, and `state`: `{id, edge, width, height, visible, maxTextElements, maxImageElements}`, or `null` once ended.
- `render(elements)`: the same elements as [`display.render`](https://docs.dev.glasslyos.com/app-devs/core-concepts/display/layouts.md), in the surface's own coordinates from 0,0 to `width` × `height`. Awaited, it resolves once the glasses show it.
- `onChange(handler)`: called with `{surface, reason}`, where `reason` is `"resized"`, `"shown"`, `"hidden"`, `"replaced"` or `"released"`. `surface` is `null` once ended.
- `release()`: gives the edge back.

A surface gets no input of its own. Claim the gestures you handle with
`session.input.setClaimedGestures`.

A double tap normally closes the miniapp on the main view before any claim is
read. While the running dashboard holds a surface and claims `double_tap`, the
tap goes to the dashboard instead and the miniapp beside the surface keeps
running, so a dock can use it to step out of the app (Glassly App 0.4.4 or
later; earlier ones close the miniapp). A surface held by any other miniapp leaves the
rule as it is. The [Dock Dashboard](https://github.com/tetramo-labs/glassly/tree/dev/miniapps/dock-dashboard)
is a complete dashboard built on a left surface.

## Every miniapp's canvas shrinks

While surfaces show, `session.capabilities.display.width`, `height`,
`maxTextElements` and `maxImageElements` become the area beside them, and
`session.onCapabilitiesChange` fires. There is no opt-out. Read the canvas from
capabilities, never hard-code 576 × 288, and redraw on `onCapabilitiesChange`.

The host moves each miniapp's frame into place, so you always draw from 0,0.
Boxes are clamped to your area. Point shapes and rotated elements that would
reach outside it are dropped and reported in `dropped`.
