Windows

zero-native supports multiple windows. The main window is created automatically; secondary windows can be created from Zig or JavaScript.

Creating windows from Zig

const info = try runtime.createWindow(.{
    .label = "tools",
    .title = "Tools",
    .default_frame = zero_native.geometry.RectF.init(80, 80, 420, 320),
});
try runtime.focusWindow(info.id);

Creating windows from JavaScript

js_window_api exposes the window.zero.windows.* helper in JavaScript. Window commands still require an allowed origin and the window permission when runtime permissions are configured:

const app_permissions = [_][]const u8{zero_native.security.permission_window};

.security = .{
    .permissions = &app_permissions,
    .navigation = .{ .allowed_origins = &.{ "zero://app" } },
},
.js_window_api = true,

Then JavaScript can call the helper from an allowed origin:

const win = await window.zero.windows.create({
  label: "tools",
  title: "Tools",
  width: 420,
  height: 320,
});

const all = await window.zero.windows.list();
await window.zero.windows.focus(win.id);
await window.zero.windows.close(win.id);

Window types

TypeDescription
WindowIdOpaque identifier (u64)
WindowCreateOptionsOptions for runtime.createWindow(): label, title, frame
WindowInfoReturned after creation: id, label, title, frame
WindowStatePersisted state: id, label, title, frame, open, focused, maximized, fullscreen, scale
WindowRestorePolicyHow restored frames are placed, such as clamping to the visible screen or centering on the primary display

Platform limits

ConstantValue
max_windows16
max_window_label_bytes64
max_window_title_bytes128

Window state persistence

The window_state.Store persists geometry to windows.zon in the app's state directory. Startup restore uses the window label from the manifest and applies the saved frame; titles continue to come from app.zon or runtime window creation options.

FieldDescription
idWindow ID
labelWindow label (used for merge matching)
framePosition and size (x, y, width, height)
maximizedWhether the window was maximized
fullscreenWhether the window was fullscreen
scaleDisplay scale factor

When saveWindow is called, the store merges by matching on label or id, so secondary windows are preserved alongside the main window. Records with missing, malformed, or empty labels are ignored on load and omitted the next time the file is rewritten.

Declaring windows in app.zon

.windows = .{
    .{ .label = "main", .title = "zero-native", .width = 720, .height = 480, .restore_state = true },
},