Atv0.2.3Repositorysigil-ui
Document

macOS windows

(sigil ui window) selects AppKit on macOS and Wayland on Linux. It exports open-window, geometry/focus/close accessors, window-dispatch, window-make-ui, window-present!, window-present-ui! and window-close!. Sizes and input coordinates are logical pixels; canvases and present damage use device pixels. Events have the forms documented in (sigil ui wayland). Existing Wayland APIs and behavior remain available on Linux.

On macOS, open-window accepts min-width and min-height (logical pixels, default 240 and 160, each overridable down to zero). The native frame tracker honors those minima. Empty native content still uses a 1×1 logical backing placeholder and recovers on the next nonempty resize. Retained UI repainting clips text at the viewport, including partial glyphs; direct render-items! keeps its strict text bounds check.

The package compiles its Objective-C C ABI only for Darwin and links the system AppKit and QuartzCore frameworks. Wayland and Linux device code stay Linux-only. Offscreen rendering and PNG output work on either platform; opening fbdev or DRM on macOS raises an explicit unsupported-device error.

Build the demo

Requires macOS 13 or later, Command Line Tools and Sigil 0.24.5. From outside the checkout, pass the absolute path of the installed Sigil executable:

sigil /path/to/checkout/scripts/build-macos-demo.sgl /path/to/sigil build
sigil /path/to/checkout/scripts/build-macos-demo.sgl /path/to/sigil bundle
open "/path/to/checkout/build/macos/Sigil UI Demo.app"

The driver uses the ordinary package build and a dependency redirect to the checkout for the demo. Build caches and dependency state stay below build/macos/. The bundle contains the compiled demo and bitmap fonts; its launcher records the PID and input-event log beside the bundle. The demo writes app.exit for controlled exits (0 for normal close, 1 for a caught error); the launcher removes an old receipt first. A missing receipt is not proof of a normal exit. Type sample text when testing. Close the window, press Escape, or use Command-Q to exit. This is a development bundle without distribution signing or notarization. Passing --timing to the demo enables pointer event-to-copy and event-to-draw statistics, sampled periodically and printed when the window closes. Drawing follows input processing without an intervening timer; the system cursor can still lead the software crosshair by a display frame.

Presentation and event loop

The host keeps a native XRGB8888 buffer, copying only submitted damage from the Sigil canvas. A layer-backed NSView draws that buffer using a temporary CGImage and CGContextDrawImage, with interpolation disabled. This avoids asynchronous Core Animation ownership of a GC-managed bytevector and keeps exposure repaint independent of the application's next render. AppKit coalesces invalidation and schedules drawing. Frame events report view drawing, not a hardware presentation timestamp. No periodic frame timer runs while idle.

The window's integer backing scale determines canvas dimensions and ui-scale. Recreate the UI after a resize event, including a scale change between screens. Damage rectangles become logical view invalidations. Frame-edge drags are tracked through ordinary mouse events so each size returns to the application's dispatch loop. When AppKit takes over a native tracking path, window-run! uses its scoped common-mode application step to keep layout/rendering moving. A stale canvas stays anchored at the upper left at its original logical size. AppKit controls final display timing; other synchronous native tracking loops, such as menus, can postpone application updates until they return.

All window operations run on the main thread. Native input/delegate callbacks queue data. window-run! installs a scoped application step on a common-mode run-loop source so queued events and rendering continue during AppKit's native tracking loops. The step receives event batches and must update state/render synchronously: it must not suspend, block, capture a continuation or escape. Queue asynchronous work outside that callback. Its procedure stays GC-rooted; registration is removed on close or when the driver exits. Ordinary dispatch remains available, but a dispatch-only outer loop cannot update while AppKit holds the stack in a nested tracker.

Outside an async scheduler, dispatch blocks in AppKit until an event or the requested timeout. Within a scheduler, dispatch first yields through the normal I/O distributor, then watches current socket and raw descriptor waits through one-shot CFFileDescriptor run-loop sources. The earliest timer/I/O deadline bounds the wait; runnable tasks prevent blocking. The next dispatch distributes readiness using the existing scheduler. Keep the GUI task calling dispatch; blocking it elsewhere cannot service AppKit. Only predicate-based external waiters retain the scheduler's 100 ms fallback because they have no wake descriptor. The adapter follows the scheduler waiter record layout in Sigil 0.24 and has regression tests for that boundary.

Input and gaps

Keys report press/repeat/release, keysym-style names, text, the common modifier list and evdev position codes (zero for unmapped positions). Pointer coordinates start at the upper left. Scroll deltas use the Wayland sign convention; precise trackpad scrolling has zero wheel steps. Window focus and close requests use the same event forms as Wayland. A minimal app menu supplies Quit.

Text currently uses NSEvent characters. Composition, dead-key handling and IME need NSTextInputClient integration. Accessibility, clipboard, drag and drop, fullscreen/output selection, richer menus, Metal rendering and native fractional scaling remain follow-ups. There is no WKWebView or browser integration.

Native child views and overlays

(window-host-token window) returns an opaque process-local AppKit host ID, or #f on platforms without this capability. Keep the window alive while using its token. The trusted C adapter API is appkit-host.h. Application code receives no NSWindow/NSView pointers. The adapter passes its unparented NSView to sigil_ui_appkit_child_adopt; the host retains it until removal or close, independently of the adapter's ownership. Tokens are never reused, and stale tokens fail. All calls and callbacks require the main thread.

Child allocations use logical top-left coordinates, with clipping at the child and content boundaries. Greater sibling order draws above lower order, beneath the canvas. Geometry notifications include actual content size and integer backing scale: the adapter supplies its layout policy by placing the child again. An empty allocation hides the child and restores UI focus. Notifications run before detach or window destruction while the child is still parented. A close notification replaces the detach notification. Callbacks may remove children reentrantly; a repeated removal fails. Drop adapter contexts only after their detach/close notification has returned.

(window-present-overlay! window canvas alpha-mask) presents the XRGB canvas above native children using a (sigil ui mask) A8 mask of the same device size. Zero alpha exposes the native child and passes pointer hit tests through; any nonzero alpha captures input for the UI, including partially transparent chrome. The host copies both planes and premultiplies its native image, leaving the canvas unchanged. Overlay presentation currently copies the whole image because alpha may change independently of RGB damage. Ordinary window-present! restores opaque canvas presentation. These overlay calls are currently macOS-only.

Scoped key filters run newest first before key equivalents or child responder dispatch. They receive copied key data and the target child ID (zero for UI). Returning true consumes the press; otherwise it passes. The chosen target and decision persist through repeats and release, without rerunning filters. Passed child events continue through AppKit exactly once; UI events keep the ordinary Sigil input forms. Filter removal, focus loss, detach or a reentrant focus change cancels pending ownership and suppresses stale releases. Explicit focus APIs select a child or the canvas; detaching a focused child restores the canvas responder. Focus and deactivation notifications let the adapter update its state.

Native notifications and filters must return synchronously: do not block, suspend, navigate, run JavaScript or enter Sigil from them. Queue such work for the ordinary event loop. No WebKit types or navigation policy are part of this API. embedding-check in the development driver tests it with a plain native child; resize-check and tracking-check cover the existing window controls.