@native-sdk/cli 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.zig +41 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +3 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +118 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +26 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +62 -7
- package/src/primitives/canvas/ui_markup.zig +51 -4
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +73 -0
- package/src/primitives/canvas/ui_markup_view.zig +63 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
- package/src/primitives/canvas/ui_schema.zig +31 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
- package/src/primitives/canvas/widget_layout.zig +13 -5
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +28 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +159 -28
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +1295 -7
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +88 -6
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +112 -6
- package/src/runtime/flow.zig +51 -1
- package/src/runtime/gpu_surface_events.zig +51 -5
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +52 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +575 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +64 -1
- package/src/runtime/ui_app_tests.zig +794 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
package/src/runtime/core.zig
CHANGED
|
@@ -15,6 +15,7 @@ const shell_layout = @import("shell_layout.zig");
|
|
|
15
15
|
const canvas_frame_helpers = @import("canvas_frame.zig");
|
|
16
16
|
const canvas_limits = @import("canvas_limits.zig");
|
|
17
17
|
const runtime_canvas_images = @import("canvas_images.zig");
|
|
18
|
+
const runtime_media_surface = @import("media_surface.zig");
|
|
18
19
|
const runtime_canvas_fonts = @import("canvas_fonts.zig");
|
|
19
20
|
const runtime_canvas_widget_context_menu = @import("canvas_widget_context_menu.zig");
|
|
20
21
|
const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
|
|
@@ -178,6 +179,18 @@ pub const DispatchErrorPolicy = enum { degrade, propagate };
|
|
|
178
179
|
|
|
179
180
|
pub const Runtime = struct {
|
|
180
181
|
options: Options,
|
|
182
|
+
/// The allocator that owns every runtime-lifetime heap allocation
|
|
183
|
+
/// (registered canvas font bytes, adopted media-surface texture
|
|
184
|
+
/// buffers). Captured from `Options.allocator` at init precisely
|
|
185
|
+
/// because `options` is public and mutable: allocation and free of
|
|
186
|
+
/// owned storage can be a whole runtime lifetime apart, and they
|
|
187
|
+
/// must resolve through ONE allocator identity. Mutating
|
|
188
|
+
/// `options.allocator` on a live runtime does not retarget this —
|
|
189
|
+
/// bytes are always returned to the allocator that made them. Every
|
|
190
|
+
/// on-demand owner (registration and adoption allocs, refusal-path
|
|
191
|
+
/// frees, the `deinit` frees) goes through this field, never
|
|
192
|
+
/// through `options.allocator`.
|
|
193
|
+
owned_allocator: std.mem.Allocator,
|
|
181
194
|
surface: platform.Surface,
|
|
182
195
|
appearance: platform.Appearance = .{},
|
|
183
196
|
windows: [platform.max_windows]RuntimeWindow = undefined,
|
|
@@ -222,6 +235,18 @@ pub const Runtime = struct {
|
|
|
222
235
|
next_window_id: platform.WindowId = 2,
|
|
223
236
|
next_view_id: platform.ViewId = 1,
|
|
224
237
|
invalidated: bool = true,
|
|
238
|
+
/// Whether the platform currently reports the app ACTIVE (frontmost
|
|
239
|
+
/// on macOS — the state the `.app_activated`/`.app_deactivated`
|
|
240
|
+
/// lifecycle events flip). Stamped in the dispatch loop from those
|
|
241
|
+
/// journaled events, so replay reproduces it deterministically.
|
|
242
|
+
/// Defaults true: a launching app is treated as active until the
|
|
243
|
+
/// platform says otherwise, because some hosts deliver input before
|
|
244
|
+
/// the first activation event and suppressing intent until one
|
|
245
|
+
/// arrived would deaden hover on hosts that never send it. The
|
|
246
|
+
/// tooltip intent machine consults this: an INACTIVE app reveals
|
|
247
|
+
/// and arms nothing — including a rebuild the app performs from its
|
|
248
|
+
/// own deactivation callback.
|
|
249
|
+
app_active: bool = true,
|
|
225
250
|
/// Whether the app's stop hook (`App.stop`) has been delivered.
|
|
226
251
|
/// Normally the platform's `.app_shutdown` event delivers it; the
|
|
227
252
|
/// run loop's exit path checks this flag and delivers a missed stop
|
|
@@ -341,15 +366,39 @@ pub const Runtime = struct {
|
|
|
341
366
|
canvas_image_entries: [canvas_limits.max_registered_canvas_images]runtime_canvas_images.CanvasImageEntry = [_]runtime_canvas_images.CanvasImageEntry{.{}} ** canvas_limits.max_registered_canvas_images,
|
|
342
367
|
canvas_image_count: usize = 0,
|
|
343
368
|
canvas_image_pixels: [canvas_limits.max_registered_canvas_images][canvas_limits.max_registered_canvas_image_pixel_bytes]u8 = undefined,
|
|
344
|
-
|
|
369
|
+
/// `ReferenceImage` scratch the frame planner hands to renderers
|
|
370
|
+
/// each plan: the registered images plus the adopted media-surface
|
|
371
|
+
/// textures (appended as `presentation_only` entries).
|
|
372
|
+
canvas_image_resources_scratch: [canvas_limits.max_registered_canvas_images + canvas_limits.max_media_surface_channels]canvas.ReferenceImage = undefined,
|
|
373
|
+
/// Adopted media-surface textures (see media_surface.zig): entry
|
|
374
|
+
/// metadata and the per-channel pixel buffers the loop thread owns.
|
|
375
|
+
/// Each buffer is ONE lazy frame-budget allocation from the frozen
|
|
376
|
+
/// `owned_allocator` at the entry's first adoption (freed only by
|
|
377
|
+
/// `deinit`) — zero media use costs zero bytes, where an embedded
|
|
378
|
+
/// pool at the budget would put 4 x 8 MiB = 32 MiB in EVERY Runtime
|
|
379
|
+
/// (the registered-font-pool regression's twin, measured on the
|
|
380
|
+
/// docs wasm preview host as +32 MB per component tile before any
|
|
381
|
+
/// producer existed). The cross-thread mailbox producers push into
|
|
382
|
+
/// is process-lived module state, deliberately NOT here — a
|
|
383
|
+
/// producer outliving this runtime must never reach runtime memory.
|
|
384
|
+
media_surface_entries: [canvas_limits.max_media_surface_channels]runtime_media_surface.MediaSurfaceTextureEntry = [_]runtime_media_surface.MediaSurfaceTextureEntry{.{}} ** canvas_limits.max_media_surface_channels,
|
|
385
|
+
media_surface_count: usize = 0,
|
|
386
|
+
media_surface_pixels: [canvas_limits.max_media_surface_channels][]u8 = [_][]u8{&.{}} ** canvas_limits.max_media_surface_channels,
|
|
387
|
+
/// Process-unique tag stamped on mailbox slots this runtime claims
|
|
388
|
+
/// (0 until the first acquire): slot ownership survives allocator
|
|
389
|
+
/// address reuse across runtimes in one process.
|
|
390
|
+
media_surface_runtime_tag: u64 = 0,
|
|
345
391
|
/// Runtime-registered canvas fonts (see canvas_fonts.zig): entry
|
|
346
|
-
/// metadata
|
|
347
|
-
///
|
|
348
|
-
///
|
|
349
|
-
///
|
|
392
|
+
/// metadata carrying each face's heap-owned TrueType bytes (exact
|
|
393
|
+
/// file size, allocated from the init-frozen `owned_allocator` at
|
|
394
|
+
/// registration —
|
|
395
|
+
/// zero fonts cost zero bytes; freed only by `deinit`, registration
|
|
396
|
+
/// being permanent), parsed face views over those bytes, the
|
|
397
|
+
/// `ReferenceFont` scratch the frame planner hands to renderers, and
|
|
398
|
+
/// the font-aware measure provider installed on first registration
|
|
399
|
+
/// for platforms without host-side text measurement.
|
|
350
400
|
canvas_font_entries: [canvas_limits.max_registered_canvas_fonts]runtime_canvas_fonts.CanvasFontEntry = [_]runtime_canvas_fonts.CanvasFontEntry{.{}} ** canvas_limits.max_registered_canvas_fonts,
|
|
351
401
|
canvas_font_count: usize = 0,
|
|
352
|
-
canvas_font_bytes: [canvas_limits.max_registered_canvas_fonts][canvas_limits.max_registered_canvas_font_bytes]u8 = undefined,
|
|
353
402
|
canvas_font_faces: [canvas_limits.max_registered_canvas_fonts]canvas.font_ttf.Face = undefined,
|
|
354
403
|
canvas_font_resources_scratch: [canvas_limits.max_registered_canvas_fonts]canvas.ReferenceFont = undefined,
|
|
355
404
|
canvas_font_measure_provider: canvas.TextMeasureProvider = .{ .measure_fn = runtime_canvas_fonts.unboundCanvasFontMeasure },
|
|
@@ -376,6 +425,10 @@ pub const Runtime = struct {
|
|
|
376
425
|
}
|
|
377
426
|
}
|
|
378
427
|
self.options = options;
|
|
428
|
+
// Freeze the ownership allocator now (see the field doc):
|
|
429
|
+
// `options` stays publicly mutable, but the identity that owns
|
|
430
|
+
// on-demand storage must not move under live allocations.
|
|
431
|
+
self.owned_allocator = options.allocator;
|
|
379
432
|
self.surface = options.platform.surface();
|
|
380
433
|
// The profile rings exceed the small-default copy bound above;
|
|
381
434
|
// assign explicitly so the disabled state is never undefined.
|
|
@@ -397,6 +450,36 @@ pub const Runtime = struct {
|
|
|
397
450
|
canvas.bumpTextMeasureGeneration();
|
|
398
451
|
}
|
|
399
452
|
|
|
453
|
+
/// Release the runtime's heap-owned on-demand storage (registered
|
|
454
|
+
/// canvas font bytes and adopted media-surface texture buffers,
|
|
455
|
+
/// allocated from the init-frozen `owned_allocator`) and disarm the
|
|
456
|
+
/// media-surface wake bindings (a producer thread must never wake a
|
|
457
|
+
/// dead host). Ends the runtime's life: parsed faces, atlas keys,
|
|
458
|
+
/// measure providers, adopted textures, and the resource slices
|
|
459
|
+
/// built over them are invalid past this point. Process-lifetime
|
|
460
|
+
/// embeddings (the app runner) may skip it — the default
|
|
461
|
+
/// allocator's pages die with the process, and the run loop's exit
|
|
462
|
+
/// defer already disarms the wakes — but embedders that create and
|
|
463
|
+
/// destroy runtimes in one process (tests, the docs wasm preview
|
|
464
|
+
/// host) call it to return the storage.
|
|
465
|
+
pub fn deinit(self: *Runtime) void {
|
|
466
|
+
self.disarmMediaSurfaceWakes();
|
|
467
|
+
for (self.canvas_font_entries[0..self.canvas_font_count]) |entry| {
|
|
468
|
+
// Through the frozen identity, never `options.allocator`:
|
|
469
|
+
// an embedder may have swapped the public option since these
|
|
470
|
+
// bytes were made, and a free must hit the allocator that
|
|
471
|
+
// allocated.
|
|
472
|
+
self.owned_allocator.free(entry.bytes);
|
|
473
|
+
}
|
|
474
|
+
self.canvas_font_count = 0;
|
|
475
|
+
for (&self.media_surface_pixels) |*buffer| {
|
|
476
|
+
if (buffer.len != 0) self.owned_allocator.free(buffer.*);
|
|
477
|
+
buffer.* = &.{};
|
|
478
|
+
}
|
|
479
|
+
self.media_surface_entries = [_]runtime_media_surface.MediaSurfaceTextureEntry{.{}} ** canvas_limits.max_media_surface_channels;
|
|
480
|
+
self.media_surface_count = 0;
|
|
481
|
+
}
|
|
482
|
+
|
|
400
483
|
fn fieldHasSmallDefault(comptime field: std.builtin.Type.StructField) bool {
|
|
401
484
|
// Large fixed-capacity arrays default to undefined; skip writing
|
|
402
485
|
// them so construction touches kilobytes, not megabytes.
|
|
@@ -704,6 +787,13 @@ pub const Runtime = struct {
|
|
|
704
787
|
pub const registeredCanvasImageCount = CanvasImageMethods.registeredCanvasImageCount;
|
|
705
788
|
pub const canvasImageRegistryBinding = CanvasImageMethods.canvasImageRegistryBinding;
|
|
706
789
|
|
|
790
|
+
const MediaSurfaceMethods = runtime_media_surface.RuntimeMediaSurfaces(Runtime);
|
|
791
|
+
pub const acquireMediaSurfaceProducer = MediaSurfaceMethods.acquireMediaSurfaceProducer;
|
|
792
|
+
pub const adoptMediaSurfaceFrames = MediaSurfaceMethods.adoptMediaSurfaceFrames;
|
|
793
|
+
pub const disarmMediaSurfaceWakes = MediaSurfaceMethods.disarmMediaSurfaceWakes;
|
|
794
|
+
pub const adoptedMediaSurfaceTexture = MediaSurfaceMethods.adoptedMediaSurfaceTexture;
|
|
795
|
+
const adoptedMediaSurfaceTextures = MediaSurfaceMethods.adoptedMediaSurfaceTextures;
|
|
796
|
+
|
|
707
797
|
const CanvasFontMethods = runtime_canvas_fonts.RuntimeCanvasFonts(Runtime);
|
|
708
798
|
pub const registerCanvasFont = CanvasFontMethods.registerCanvasFont;
|
|
709
799
|
pub const registeredCanvasFonts = CanvasFontMethods.registeredCanvasFonts;
|
|
@@ -743,6 +833,7 @@ pub const Runtime = struct {
|
|
|
743
833
|
const refreshCanvasWidgetDisplayList = CanvasWidgetDisplayMethods.refreshCanvasWidgetDisplayList;
|
|
744
834
|
|
|
745
835
|
const CanvasWidgetEventMethods = runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(Runtime);
|
|
836
|
+
pub const advanceCanvasTooltipIntentForFrame = CanvasWidgetEventMethods.advanceCanvasTooltipIntentForFrame;
|
|
746
837
|
pub const routeCanvasWidgetPointerInput = CanvasWidgetEventMethods.routeCanvasWidgetPointerInput;
|
|
747
838
|
pub const routeCanvasWidgetKeyboardInput = CanvasWidgetEventMethods.routeCanvasWidgetKeyboardInput;
|
|
748
839
|
pub const routeCanvasWidgetTextInput = CanvasWidgetEventMethods.routeCanvasWidgetTextInput;
|
|
@@ -791,6 +882,7 @@ pub const Runtime = struct {
|
|
|
791
882
|
const selectAutomationCanvasWidget = AutomationWidgetMethods.selectAutomationCanvasWidget;
|
|
792
883
|
const setAutomationCanvasWidgetText = AutomationWidgetMethods.setAutomationCanvasWidgetText;
|
|
793
884
|
const editAutomationCanvasWidgetText = AutomationWidgetMethods.editAutomationCanvasWidgetText;
|
|
885
|
+
const composeAutomationCanvasWidgetText = AutomationWidgetMethods.composeAutomationCanvasWidgetText;
|
|
794
886
|
const dispatchAutomationCanvasWidgetDrag = AutomationWidgetMethods.dispatchAutomationCanvasWidgetDrag;
|
|
795
887
|
const dispatchAutomationCanvasWidgetFileDrop = AutomationWidgetMethods.dispatchAutomationCanvasWidgetFileDrop;
|
|
796
888
|
};
|
|
@@ -823,6 +915,14 @@ pub fn TestHarness() type {
|
|
|
823
915
|
}
|
|
824
916
|
|
|
825
917
|
pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
|
|
918
|
+
// The harness embeds the runtime's platform: deinit both
|
|
919
|
+
// returns the runtime's heap-owned storage (registered font
|
|
920
|
+
// bytes, lazily allocated media buffers) to the leak-checked
|
|
921
|
+
// test allocator AND disarms the wake bindings, so a
|
|
922
|
+
// producer handle a test keeps past destroy (the orphan
|
|
923
|
+
// tests) can never wake the freed host — the run loop's exit
|
|
924
|
+
// defer for real apps, this line for harness-driven ones.
|
|
925
|
+
self.runtime.deinit();
|
|
826
926
|
gpa.destroy(self);
|
|
827
927
|
}
|
|
828
928
|
|
|
@@ -832,6 +932,12 @@ pub fn TestHarness() type {
|
|
|
832
932
|
Runtime.initAt(&self.runtime, .{
|
|
833
933
|
.platform = self.null_platform.platform(),
|
|
834
934
|
.trace_sink = self.trace_sink.sink(),
|
|
935
|
+
// On-demand runtime storage (registered font bytes,
|
|
936
|
+
// adopted media-surface texture buffers) routes through
|
|
937
|
+
// the leak-checked test allocator (freed by `destroy`
|
|
938
|
+
// via Runtime.deinit), so a registration or adoption
|
|
939
|
+
// that leaks fails the test that made it.
|
|
940
|
+
.allocator = if (builtin.is_test) std.testing.allocator else std.heap.page_allocator,
|
|
835
941
|
// Real-executor effect tests spawn processes that must
|
|
836
942
|
// see the parent environment (HOME, PATH), exactly as
|
|
837
943
|
// the app runner threads it from `std.process.Init`.
|
package/src/runtime/flow.zig
CHANGED
|
@@ -12,6 +12,7 @@ const launch_timing = @import("launch_timing.zig");
|
|
|
12
12
|
const runtime_clock = @import("clock.zig");
|
|
13
13
|
const shell_layout = @import("shell_layout.zig");
|
|
14
14
|
const runtime_builtin_bridge = @import("builtin_bridge.zig");
|
|
15
|
+
const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
|
|
15
16
|
const runtime_canvas_widget_context_menu = @import("canvas_widget_context_menu.zig");
|
|
16
17
|
const runtime_canvas_widget_scroll_drivers = @import("canvas_widget_scroll_drivers.zig");
|
|
17
18
|
const runtime_gpu_surface_events = @import("gpu_surface_events.zig");
|
|
@@ -38,6 +39,7 @@ const parseAutomationProvenanceTarget = automation_commands.parseAutomationProve
|
|
|
38
39
|
const parseAutomationWidgetWheel = automation_commands.parseAutomationWidgetWheel;
|
|
39
40
|
const parseAutomationWidgetContextMenuItem = automation_commands.parseAutomationWidgetContextMenuItem;
|
|
40
41
|
const parseAutomationWidgetKey = automation_commands.parseAutomationWidgetKey;
|
|
42
|
+
const parseAutomationWidgetPinch = automation_commands.parseAutomationWidgetPinch;
|
|
41
43
|
const parseAutomationWidgetPointerDrag = automation_commands.parseAutomationWidgetPointerDrag;
|
|
42
44
|
const parseAutomationResizeCommand = automation_commands.parseAutomationResizeCommand;
|
|
43
45
|
const parseAutomationTrayItemId = automation_commands.parseAutomationTrayItemId;
|
|
@@ -76,6 +78,10 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
76
78
|
return runtime_canvas_widget_context_menu.RuntimeCanvasWidgetContextMenu(Runtime);
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
fn CanvasWidgetEventMethods() type {
|
|
82
|
+
return runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(Runtime);
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
fn AutomationWidgetMethods() type {
|
|
80
86
|
return runtime_automation_widget_dispatch.RuntimeAutomationWidgetDispatch(Runtime);
|
|
81
87
|
}
|
|
@@ -130,6 +136,16 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
130
136
|
// away, so the watcher can never call into a dead host.
|
|
131
137
|
defer if (command_watcher_running) command_watcher.stop();
|
|
132
138
|
|
|
139
|
+
// Media-surface wake teardown: producers a slow app forgot
|
|
140
|
+
// to release may push (and try to wake this platform) at
|
|
141
|
+
// any later time from their own threads. Disarm their wake
|
|
142
|
+
// bindings before the caller's later-declared defers tear
|
|
143
|
+
// the host down — declared BEFORE the app-stop defer below
|
|
144
|
+
// so it runs AFTER the stop hook (LIFO), letting the hook
|
|
145
|
+
// join producer threads first. The same run-exit ordering
|
|
146
|
+
// that stops the automation arrival watcher.
|
|
147
|
+
defer self.disarmMediaSurfaceWakes();
|
|
148
|
+
|
|
133
149
|
// Teardown ordering contract: everything the app must do
|
|
134
150
|
// against the live platform — silencing an active audio
|
|
135
151
|
// player, disarming platform timers, joining effect workers
|
|
@@ -226,10 +242,25 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
226
242
|
log(self, "app.start", "app started", &.{trace.string("app", app.name)});
|
|
227
243
|
},
|
|
228
244
|
.app_activated => {
|
|
245
|
+
self.app_active = true;
|
|
229
246
|
try dispatchEvent(self, app, .{ .lifecycle = .activate });
|
|
230
247
|
emitAppLifecycleEvent(self, "app:activate") catch |err| log(self, "app.activate.emit_failed", @errorName(err), &.{});
|
|
231
248
|
},
|
|
232
249
|
.app_deactivated => {
|
|
250
|
+
// The app-active register flips FIRST — before the
|
|
251
|
+
// tooltip reset and before the app hears the
|
|
252
|
+
// lifecycle event — so a model that rebuilds FROM
|
|
253
|
+
// its deactivation callback adopts under a runtime
|
|
254
|
+
// that already knows the app is inactive: the
|
|
255
|
+
// adoption arm's reveal/arm paths are gated on this
|
|
256
|
+
// register and stay silent.
|
|
257
|
+
self.app_active = false;
|
|
258
|
+
// Deactivation drops every tooltip conversation in
|
|
259
|
+
// every window (see the seam's own rationale) BEFORE
|
|
260
|
+
// the app hears the lifecycle event, so a model that
|
|
261
|
+
// rebuilds on deactivate adopts against clean
|
|
262
|
+
// tooltip state instead of a stale shown slot.
|
|
263
|
+
try CanvasWidgetEventMethods().resetCanvasTooltipIntentForAppDeactivation(self);
|
|
233
264
|
try dispatchEvent(self, app, .{ .lifecycle = .deactivate });
|
|
234
265
|
emitAppLifecycleEvent(self, "app:deactivate") catch |err| log(self, "app.deactivate.emit_failed", @errorName(err), &.{});
|
|
235
266
|
},
|
|
@@ -305,7 +336,10 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
305
336
|
}
|
|
306
337
|
},
|
|
307
338
|
.window_focused => |window_id| {
|
|
308
|
-
|
|
339
|
+
// setFocusedIndex is the window-key seam: the
|
|
340
|
+
// window LOSING key here also drops its views'
|
|
341
|
+
// tooltip conversations there.
|
|
342
|
+
if (WindowViewMethods().findWindowIndexById(self, window_id)) |index| try WindowViewMethods().setFocusedIndex(self, index);
|
|
309
343
|
self.invalidated = true;
|
|
310
344
|
},
|
|
311
345
|
.frame_requested => try frame(self, app),
|
|
@@ -500,6 +534,18 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
500
534
|
|
|
501
535
|
pub fn frame(self: *Runtime, app: App) anyerror!void {
|
|
502
536
|
const start_ns = nowNanoseconds();
|
|
537
|
+
// A media-surface producer's wake arrives as THIS event (the
|
|
538
|
+
// platform's cross-thread frame request): adopt staged
|
|
539
|
+
// frames here so an idle app's push reaches the runtime —
|
|
540
|
+
// adoption's invalidation then arms the prompt gpu-surface
|
|
541
|
+
// frame that composites it (`noteCanvasImagesChanged` ->
|
|
542
|
+
// `requestCanvasFrameForView`). Runs before the invalidation
|
|
543
|
+
// check below because adoption IS an invalidation source; a
|
|
544
|
+
// busy app pays one fenced flag check per idle channel, and
|
|
545
|
+
// the gpu-surface frame dispatch's own adoption call keeps
|
|
546
|
+
// pacing consumption for hosts whose frame events do not
|
|
547
|
+
// pass through here.
|
|
548
|
+
self.adoptMediaSurfaceFrames();
|
|
503
549
|
try consumeAutomationCommand(self, app);
|
|
504
550
|
if (!self.invalidated) return;
|
|
505
551
|
|
|
@@ -793,6 +839,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
793
839
|
.widget_drag => "automation.widget_drag",
|
|
794
840
|
.widget_wheel => "automation.widget_wheel",
|
|
795
841
|
.widget_key => "automation.widget_key",
|
|
842
|
+
.widget_pinch => "automation.widget_pinch",
|
|
796
843
|
.tray_action => "automation.tray_action",
|
|
797
844
|
.provenance => "automation.provenance",
|
|
798
845
|
else => "automation.command",
|
|
@@ -854,6 +901,9 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
854
901
|
.widget_key => {
|
|
855
902
|
try AutomationWidgetMethods().dispatchAutomationWidgetKeyInput(self, app, try parseAutomationWidgetKey(command.value));
|
|
856
903
|
},
|
|
904
|
+
.widget_pinch => {
|
|
905
|
+
try AutomationWidgetMethods().dispatchAutomationWidgetPinch(self, app, try parseAutomationWidgetPinch(command.value));
|
|
906
|
+
},
|
|
857
907
|
.menu_command => {
|
|
858
908
|
try dispatchPlatformEvent(self, app, .{ .menu_command = .{
|
|
859
909
|
.name = try parseAutomationCommandName(command.value),
|
|
@@ -17,6 +17,13 @@ const sizesEqual = canvas_frame_helpers.sizesEqual;
|
|
|
17
17
|
pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
18
18
|
return struct {
|
|
19
19
|
pub fn dispatchGpuSurfaceFrame(self: *Runtime, app: runtime_api.App(Runtime), frame_event: platform.GpuSurfaceFrameEvent) anyerror!void {
|
|
20
|
+
// Media-surface adoption rides the compositor's
|
|
21
|
+
// presented-frame clock: staged producer frames (latest
|
|
22
|
+
// wins) are sampled once per frame event, BEFORE view state
|
|
23
|
+
// and the app dispatch, so a changed texture invalidates
|
|
24
|
+
// the very frame this event is about to present. Idle
|
|
25
|
+
// channels cost one fenced flag check each.
|
|
26
|
+
self.adoptMediaSurfaceFrames();
|
|
20
27
|
var enriched_frame_event = frame_event;
|
|
21
28
|
var had_pending_input = false;
|
|
22
29
|
if (runtimeFindViewIndex(self, frame_event.window_id, frame_event.label)) |index| {
|
|
@@ -61,6 +68,10 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
61
68
|
// so accordion reveals replay frame for frame exactly
|
|
62
69
|
// like split fractions do.
|
|
63
70
|
try self.advanceCanvasWidgetDisclosureTweenForFrame(index, frame_event.timestamp_ns);
|
|
71
|
+
// The anchored-tooltip hover-intent delay fires on the
|
|
72
|
+
// same recorded clock: a dwell past the delay shows its
|
|
73
|
+
// tooltip on a deterministic frame, replayed exactly.
|
|
74
|
+
try self.advanceCanvasTooltipIntentForFrame(index, frame_event.timestamp_ns);
|
|
64
75
|
try dispatchPendingCanvasWidgetScrollEvents(self, app, index);
|
|
65
76
|
// A settling tween notes its ONE split-resize event with
|
|
66
77
|
// no input in flight; drain it here so the controlled
|
|
@@ -180,6 +191,16 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
180
191
|
if (runtimeFindViewIndex(self, input_event.window_id, input_event.label)) |index| {
|
|
181
192
|
self.views[index].recordGpuSurfaceInputTimestamp(input_event.timestamp_ns);
|
|
182
193
|
}
|
|
194
|
+
// The whole consumed stream still feeds the tooltip
|
|
195
|
+
// intent choke point: every pointer-carrying event
|
|
196
|
+
// updates the stored position (a later point-blind
|
|
197
|
+
// reconcile must hit-test where the pointer really is),
|
|
198
|
+
// the secondary down resets the machine before the menu
|
|
199
|
+
// presents ("pointer-down dismisses" holds for EVERY
|
|
200
|
+
// button — no tooltip floats behind or over the native
|
|
201
|
+
// menu), and a consumed cancel is still the pointer
|
|
202
|
+
// leaving the view.
|
|
203
|
+
try CanvasWidgetEventMethods().reconcileCanvasTooltipIntentForConsumedPointerInput(self, input_event);
|
|
183
204
|
if (input_event.kind == .pointer_down) {
|
|
184
205
|
try setFocusedView(self, input_event.window_id, input_event.label);
|
|
185
206
|
self.invalidated = true;
|
|
@@ -244,7 +265,17 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
244
265
|
// click on the native titlebar. Dismissal above still ran:
|
|
245
266
|
// clicking the header closes an open surface first.
|
|
246
267
|
window_drag_started = try CanvasWidgetEventMethods().startCanvasWidgetWindowDragFromPointer(self, input_event, pointer_event.*);
|
|
247
|
-
if (
|
|
268
|
+
if (window_drag_started) {
|
|
269
|
+
// The drag consumed the down, but "pointer-down
|
|
270
|
+
// dismisses" still holds — and the down still
|
|
271
|
+
// carried a position the intent machine must
|
|
272
|
+
// record: the OS owning the pointer from here must
|
|
273
|
+
// not strand an armed or shown tooltip (the
|
|
274
|
+
// matching up may never arrive), and a later
|
|
275
|
+
// point-blind reconcile must hit-test where the
|
|
276
|
+
// pointer really went down.
|
|
277
|
+
try CanvasWidgetEventMethods().reconcileCanvasTooltipIntentForConsumedPointerInput(self, input_event);
|
|
278
|
+
} else {
|
|
248
279
|
try CanvasWidgetEventMethods().updateCanvasWidgetControlFromPointer(self, pointer_event.*);
|
|
249
280
|
try CanvasWidgetEventMethods().updateCanvasWidgetInteractionFromPointer(self, pointer_event.*);
|
|
250
281
|
// The text pass may stamp a clear edit onto the
|
|
@@ -297,11 +328,19 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
297
328
|
&clipboard_paste_buffer,
|
|
298
329
|
);
|
|
299
330
|
}
|
|
300
|
-
|
|
301
|
-
|
|
331
|
+
// The text pass stamps the edit it derived and applied onto
|
|
332
|
+
// the event (Escape's clear included), so the app dispatch
|
|
333
|
+
// below hears exactly the edit the retained editor performed.
|
|
334
|
+
if (widget_keyboard_event) |*keyboard_event| {
|
|
335
|
+
// Keyboard activation counts as a press for tooltips:
|
|
336
|
+
// Space/Enter on the focused trigger dismisses its
|
|
337
|
+
// armed/shown tooltip before the control mutation and
|
|
338
|
+
// app dispatch observe the input.
|
|
339
|
+
try CanvasWidgetEventMethods().updateCanvasTooltipIntentForKeyboardActivation(self, keyboard_event.*);
|
|
340
|
+
try CanvasWidgetEventMethods().updateCanvasWidgetControlFromKeyboard(self, keyboard_event.*);
|
|
302
341
|
try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, keyboard_event);
|
|
303
342
|
}
|
|
304
|
-
|
|
343
|
+
var widget_text_input_event = if (widget_surface_dismissed)
|
|
305
344
|
null
|
|
306
345
|
else
|
|
307
346
|
CanvasWidgetEventMethods().routeCanvasWidgetTextInput(self, input_event, &self.widget_event_route_entries) catch |err| switch (err) {
|
|
@@ -311,7 +350,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
311
350
|
=> null,
|
|
312
351
|
else => return err,
|
|
313
352
|
};
|
|
314
|
-
if (widget_text_input_event)
|
|
353
|
+
if (widget_text_input_event) |*text_input_event| {
|
|
315
354
|
try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, text_input_event);
|
|
316
355
|
}
|
|
317
356
|
// The refresh batch stays open across the app dispatches
|
|
@@ -609,11 +648,18 @@ fn setFocusedView(self: anytype, window_id: platform.WindowId, label: []const u8
|
|
|
609
648
|
for (self.views[0..self.view_count], 0..) |*view, view_index| {
|
|
610
649
|
if (view.window_id != window_id) continue;
|
|
611
650
|
const previous_state = view.canvasWidgetRenderState();
|
|
651
|
+
const was_focused = view.focused;
|
|
612
652
|
view.focused = std.mem.eql(u8, view.label, label);
|
|
613
653
|
const next_state = view.canvasWidgetRenderState();
|
|
614
654
|
if (!runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(@TypeOf(self.*)).canvasWidgetRenderStatesEqual(previous_state, next_state)) {
|
|
615
655
|
try runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(@TypeOf(self.*)).invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, next_state);
|
|
616
656
|
}
|
|
657
|
+
// A view losing focus drops its tooltip state and re-stamps
|
|
658
|
+
// hidden — input landing in a sibling view must not leave the
|
|
659
|
+
// blurred view's tooltip floating.
|
|
660
|
+
if (was_focused and !view.focused) {
|
|
661
|
+
try runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(@TypeOf(self.*)).resetCanvasTooltipIntentForViewBlur(self, view_index);
|
|
662
|
+
}
|
|
617
663
|
}
|
|
618
664
|
for (self.webviews[0..self.webview_count]) |*webview| {
|
|
619
665
|
if (webview.window_id == window_id) webview.focused = std.mem.eql(u8, webview.label, label);
|