@native-sdk/cli 0.5.4 → 0.6.0
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/app.zig +50 -1
- package/build.zig +534 -3
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +280 -8
- package/packages/core/sdk/core.ts +481 -2
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1283 -66
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +16 -0
- package/src/runtime/api.zig +70 -1
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +1 -0
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +109 -15
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2333 -63
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +268 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -34,6 +34,8 @@ const WindowsEventKind = enum(c_int) {
|
|
|
34
34
|
timer = 16,
|
|
35
35
|
appearance = 17,
|
|
36
36
|
audio = 18,
|
|
37
|
+
context_menu_action = 19,
|
|
38
|
+
view_focused = 20,
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
const WindowsEvent = extern struct {
|
|
@@ -101,6 +103,12 @@ const WindowsEvent = extern struct {
|
|
|
101
103
|
/// documented scale (log-spaced 50 Hz..16 kHz buckets, linear-in-dB
|
|
102
104
|
/// from -60 dBFS at 0 to full scale at 255). Zeros elsewhere.
|
|
103
105
|
audio_bands: [platform_mod.audio_spectrum_band_count]u8,
|
|
106
|
+
/// CONTEXT_MENU_ACTION payload (same field names as the macOS host):
|
|
107
|
+
/// `widget_id` echoes the request's correlation token and
|
|
108
|
+
/// `menu_item_id` is the selected item's id (0 = dismissed without a
|
|
109
|
+
/// selection).
|
|
110
|
+
widget_id: u64,
|
|
111
|
+
menu_item_id: u32,
|
|
104
112
|
};
|
|
105
113
|
|
|
106
114
|
const WindowsCallback = *const fn (context: ?*anyopaque, event: *const WindowsEvent) callconv(.c) void;
|
|
@@ -181,6 +189,17 @@ extern fn native_sdk_windows_audio_stop(host: *WindowsHost) c_int;
|
|
|
181
189
|
extern fn native_sdk_windows_audio_seek(host: *WindowsHost, position_ms: u64) c_int;
|
|
182
190
|
extern fn native_sdk_windows_audio_set_volume(host: *WindowsHost, volume: f64) c_int;
|
|
183
191
|
extern fn native_sdk_windows_audio_spectrum_supported(host: *WindowsHost) c_int;
|
|
192
|
+
extern fn native_sdk_windows_show_context_menu(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, token: u64, items: [*]const WindowsContextMenuItem, count: usize) c_int;
|
|
193
|
+
|
|
194
|
+
/// One context-menu entry crossing the C ABI (the same shape the macOS
|
|
195
|
+
/// host takes): labels ride as pointer+length, flags as ints.
|
|
196
|
+
const WindowsContextMenuItem = extern struct {
|
|
197
|
+
item_id: u32,
|
|
198
|
+
label: [*]const u8,
|
|
199
|
+
label_len: usize,
|
|
200
|
+
enabled: c_int,
|
|
201
|
+
separator: c_int,
|
|
202
|
+
};
|
|
184
203
|
|
|
185
204
|
const WindowsOpenDialogOpts = extern struct {
|
|
186
205
|
title: [*]const u8,
|
|
@@ -248,6 +267,18 @@ pub const WindowsPlatform = struct {
|
|
|
248
267
|
app_info: platform_mod.AppInfo,
|
|
249
268
|
surface_value: platform_mod.Surface,
|
|
250
269
|
state: RunState = .{},
|
|
270
|
+
/// Latched when the runtime's effects teardown abandons an
|
|
271
|
+
/// in-flight channel `wake_fn` call (see
|
|
272
|
+
/// `PlatformServices.note_channel_wake_abandoned_fn`): the stale
|
|
273
|
+
/// call still holds this platform as its context and may execute
|
|
274
|
+
/// into it at any later time, so `deinit` must skip destruction
|
|
275
|
+
/// and leak the host, process-lived — and the wrapper struct the
|
|
276
|
+
/// context actually points at (the wake thunk casts to
|
|
277
|
+
/// `*WindowsPlatform` before reaching the host) must outlive the
|
|
278
|
+
/// call too, which is why runners allocate it through
|
|
279
|
+
/// `createWithOptions` and retire it through `destroy`, the
|
|
280
|
+
/// latch-gated free.
|
|
281
|
+
channel_wake_abandoned: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
251
282
|
|
|
252
283
|
pub fn init(title: []const u8, size: geometry.SizeF) Error!WindowsPlatform {
|
|
253
284
|
return initWithEngine(title, size, .system);
|
|
@@ -286,7 +317,44 @@ pub const WindowsPlatform = struct {
|
|
|
286
317
|
};
|
|
287
318
|
}
|
|
288
319
|
|
|
320
|
+
/// Heap-allocate the wrapper (process allocator) and initialize it
|
|
321
|
+
/// in place. Runners must use this over a stack `initWithOptions`
|
|
322
|
+
/// value: `platform().services.context` is this wrapper's ADDRESS,
|
|
323
|
+
/// worker threads dereference it inside the channel wake path, and
|
|
324
|
+
/// a wake call teardown abandons may do so at any later time —
|
|
325
|
+
/// after a runner's stack frame would have unwound. Pair with
|
|
326
|
+
/// `destroy`, the latch-gated free.
|
|
327
|
+
pub fn createWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!*WindowsPlatform {
|
|
328
|
+
const self = std.heap.page_allocator.create(WindowsPlatform) catch return error.CreateFailed;
|
|
329
|
+
errdefer std.heap.page_allocator.destroy(self);
|
|
330
|
+
self.* = try initWithOptions(size, web_engine, app_info);
|
|
331
|
+
return self;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/// `deinit` plus the wrapper's own storage, gated by the same
|
|
335
|
+
/// latch: an abandoned channel wake call dereferences this wrapper
|
|
336
|
+
/// (its context) BEFORE it reaches the native host, so on abandon
|
|
337
|
+
/// both are leaked, process-lived — deinit-gating extended to
|
|
338
|
+
/// lifetime-gating, the honest completion of the abandoned-worker
|
|
339
|
+
/// idiom. No cross-thread race on the gate: the latch is set
|
|
340
|
+
/// synchronously on the loop thread during effects teardown, which
|
|
341
|
+
/// runs before the runner's deferred destroy.
|
|
342
|
+
pub fn destroy(self: *WindowsPlatform) void {
|
|
343
|
+
self.deinit();
|
|
344
|
+
if (self.channel_wake_abandoned.load(.seq_cst)) return;
|
|
345
|
+
std.heap.page_allocator.destroy(self);
|
|
346
|
+
}
|
|
347
|
+
|
|
289
348
|
pub fn deinit(self: *WindowsPlatform) void {
|
|
349
|
+
// An abandoned channel wake call may still enter this host at
|
|
350
|
+
// any later time (see `channel_wake_abandoned`): destroying it
|
|
351
|
+
// would turn that stale call into a use-after-free, so the
|
|
352
|
+
// host is deliberately leaked, process-lived — the
|
|
353
|
+
// abandoned-worker idiom, applied to the platform itself.
|
|
354
|
+
if (self.channel_wake_abandoned.load(.seq_cst)) {
|
|
355
|
+
std.debug.print("windows platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it (and the wrapper it enters through), process-lived, so the stale call stays safe\n", .{});
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
290
358
|
native_sdk_windows_destroy(self.host);
|
|
291
359
|
}
|
|
292
360
|
|
|
@@ -326,6 +394,7 @@ pub const WindowsPlatform = struct {
|
|
|
326
394
|
.request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
|
|
327
395
|
.note_gpu_surface_input_fn = noteGpuSurfaceInput,
|
|
328
396
|
.present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
|
|
397
|
+
.show_context_menu_fn = showContextMenu,
|
|
329
398
|
.create_webview_fn = createWebView,
|
|
330
399
|
.set_webview_frame_fn = setWebViewFrame,
|
|
331
400
|
.navigate_webview_fn = navigateWebView,
|
|
@@ -353,6 +422,11 @@ pub const WindowsPlatform = struct {
|
|
|
353
422
|
.audio_stop_fn = audioStop,
|
|
354
423
|
.audio_seek_fn = audioSeek,
|
|
355
424
|
.audio_set_volume_fn = audioSetVolume,
|
|
425
|
+
// The video load verbs are teaching refusals (see
|
|
426
|
+
// `videoLoad`); the transport verbs stay null — the
|
|
427
|
+
// channel never activates without a successful load.
|
|
428
|
+
.video_load_fn = videoLoad,
|
|
429
|
+
.video_load_url_fn = videoLoadUrl,
|
|
356
430
|
.configure_security_policy_fn = configureSecurityPolicy,
|
|
357
431
|
.configure_menus_fn = configureMenus,
|
|
358
432
|
.configure_shortcuts_fn = configureShortcuts,
|
|
@@ -360,6 +434,7 @@ pub const WindowsPlatform = struct {
|
|
|
360
434
|
.start_timer_fn = startTimer,
|
|
361
435
|
.cancel_timer_fn = cancelTimer,
|
|
362
436
|
.wake_fn = wake,
|
|
437
|
+
.note_channel_wake_abandoned_fn = noteChannelWakeAbandoned,
|
|
363
438
|
.request_frame_fn = requestFrame,
|
|
364
439
|
.decode_image_fn = decodeImage,
|
|
365
440
|
},
|
|
@@ -404,11 +479,21 @@ pub const WindowsPlatform = struct {
|
|
|
404
479
|
// in Windows 10 2004 — the host probes the activation
|
|
405
480
|
// support live instead of assuming the build.
|
|
406
481
|
.audio_spectrum => self.web_engine == .system and audioSpectrumAvailable(self.host),
|
|
407
|
-
// Native
|
|
408
|
-
//
|
|
409
|
-
// the engine
|
|
410
|
-
|
|
411
|
-
|
|
482
|
+
// Native context menus present through TrackPopupMenu (the
|
|
483
|
+
// same popup path the tray menu uses), so the answer rides
|
|
484
|
+
// the same system-engine gate as the tray.
|
|
485
|
+
.context_menus => self.web_engine == .system,
|
|
486
|
+
// Native scroll drivers and app-owned view-surface adoption
|
|
487
|
+
// are macOS-only today; Win32 keeps the engine's wheel
|
|
488
|
+
// physics.
|
|
489
|
+
.gpu_surface_scroll_drivers, .view_surface_adoption => false,
|
|
490
|
+
// Video decode (a Media Foundation session feeding the
|
|
491
|
+
// media-surface texture channel) is not implemented yet:
|
|
492
|
+
// an honest false rather than a half-implemented player.
|
|
493
|
+
// The load verbs teach and refuse (see `videoLoad`), so an
|
|
494
|
+
// app that skips the capability check still learns exactly
|
|
495
|
+
// what is missing.
|
|
496
|
+
.video_playback => false,
|
|
412
497
|
};
|
|
413
498
|
}
|
|
414
499
|
|
|
@@ -502,6 +587,10 @@ fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c
|
|
|
502
587
|
.hidden = event.hidden != 0,
|
|
503
588
|
} });
|
|
504
589
|
},
|
|
590
|
+
.view_focused => state.emit(.{ .view_focused = .{
|
|
591
|
+
.window_id = event.window_id,
|
|
592
|
+
.label = event.view_label[0..event.view_label_len],
|
|
593
|
+
} }),
|
|
505
594
|
.shortcut => state.emit(.{ .shortcut = .{
|
|
506
595
|
.id = event.shortcut_id[0..event.shortcut_id_len],
|
|
507
596
|
.key = event.shortcut_key[0..event.shortcut_key_len],
|
|
@@ -562,9 +651,23 @@ fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c
|
|
|
562
651
|
.buffering = event.audio_buffering != 0,
|
|
563
652
|
.bands = event.audio_bands,
|
|
564
653
|
} }),
|
|
654
|
+
.context_menu_action => state.emit(.{ .context_menu_action = contextMenuActionEventFromWindowsEvent(event) }),
|
|
565
655
|
}
|
|
566
656
|
}
|
|
567
657
|
|
|
658
|
+
/// Pure event mapping (no host calls), unit-testable on every build
|
|
659
|
+
/// host: the C event's `widget_id` is the request's correlation token
|
|
660
|
+
/// and `menu_item_id` the selected item (0 = dismissed) — the same
|
|
661
|
+
/// payload contract as the macOS host, so replay is shape-identical.
|
|
662
|
+
fn contextMenuActionEventFromWindowsEvent(event: *const WindowsEvent) platform_mod.ContextMenuActionEvent {
|
|
663
|
+
return .{
|
|
664
|
+
.window_id = event.window_id,
|
|
665
|
+
.view_label = event.view_label[0..event.view_label_len],
|
|
666
|
+
.token = event.widget_id,
|
|
667
|
+
.item_id = event.menu_item_id,
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
|
|
568
671
|
/// Ordinals match the audio report kinds in webview2_host.cpp (the same
|
|
569
672
|
/// set the macOS host uses); anything unknown degrades to `.failed` so a
|
|
570
673
|
/// host/SDK skew is loud in the app instead of undefined behavior here.
|
|
@@ -696,13 +799,23 @@ fn emitWindowEvent(context: ?*anyopaque, window_id: platform_mod.WindowId, name:
|
|
|
696
799
|
native_sdk_windows_emit_window_event(self.host, window_id, name.ptr, name.len, detail_json.ptr, detail_json.len);
|
|
697
800
|
}
|
|
698
801
|
|
|
699
|
-
/// Thread-safe: `
|
|
700
|
-
///
|
|
802
|
+
/// Thread-safe: `PostMessageW` into the existing message loop (the
|
|
803
|
+
/// enqueue-only shape the wake contract requires — never the
|
|
804
|
+
/// synchronous `SendMessage`), whose window procedure emits `.wake` on
|
|
805
|
+
/// the loop thread.
|
|
701
806
|
fn wake(context: ?*anyopaque) anyerror!void {
|
|
702
807
|
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
703
808
|
native_sdk_windows_wake(self.host);
|
|
704
809
|
}
|
|
705
810
|
|
|
811
|
+
/// Teardown abandoned an in-flight channel wake call: latch the flag
|
|
812
|
+
/// `deinit` consults so this host is leaked rather than destroyed (see
|
|
813
|
+
/// `WindowsPlatform.channel_wake_abandoned`).
|
|
814
|
+
fn noteChannelWakeAbandoned(context: ?*anyopaque) void {
|
|
815
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
816
|
+
self.channel_wake_abandoned.store(true, .seq_cst);
|
|
817
|
+
}
|
|
818
|
+
|
|
706
819
|
/// Thread-safe like `wake`: `PostMessage` into the message loop, whose
|
|
707
820
|
/// window procedure emits one `.frame` event on the loop thread. The
|
|
708
821
|
/// automation arrival watcher calls this when a command lands so
|
|
@@ -1006,6 +1119,71 @@ fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: platform_mod.GpuSurface
|
|
|
1006
1119
|
) == 0) return error.ViewNotFound;
|
|
1007
1120
|
}
|
|
1008
1121
|
|
|
1122
|
+
/// Win32 menus treat `&` in an item label as a mnemonic marker —
|
|
1123
|
+
/// AppendMenuW eats the ampersand and underlines the next character —
|
|
1124
|
+
/// so an app-authored label like "R&D" must cross the ABI with the
|
|
1125
|
+
/// ampersand doubled ("R&&D") to render literally. Labels without an
|
|
1126
|
+
/// ampersand pass through uncopied; a label whose escaped form does
|
|
1127
|
+
/// not fit the remaining pool also passes through raw, because an
|
|
1128
|
+
/// accidental mnemonic on a pathological label beats dropping bytes.
|
|
1129
|
+
fn escapeMenuLabelAmpersands(label: []const u8, pool: []u8, used: *usize) []const u8 {
|
|
1130
|
+
const ampersands = std.mem.count(u8, label, "&");
|
|
1131
|
+
if (ampersands == 0) return label;
|
|
1132
|
+
if (label.len + ampersands > pool.len - used.*) return label;
|
|
1133
|
+
const start = used.*;
|
|
1134
|
+
var out = start;
|
|
1135
|
+
for (label) |byte| {
|
|
1136
|
+
pool[out] = byte;
|
|
1137
|
+
out += 1;
|
|
1138
|
+
if (byte == '&') {
|
|
1139
|
+
pool[out] = '&';
|
|
1140
|
+
out += 1;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
used.* = out;
|
|
1144
|
+
return pool[start..out];
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/// Translate the request's items to the C ABI shape, escaping mnemonic
|
|
1148
|
+
/// ampersands into `label_pool` (the host copies every label before
|
|
1149
|
+
/// returning, so a caller stack pool is safe). Pure (no host calls), so
|
|
1150
|
+
/// the separator/disabled/label mapping is unit-testable on every build
|
|
1151
|
+
/// host.
|
|
1152
|
+
fn contextMenuItemsToWindows(items: []const platform_mod.ContextMenuItem, buffer: []WindowsContextMenuItem, label_pool: []u8) []const WindowsContextMenuItem {
|
|
1153
|
+
const count = @min(items.len, buffer.len);
|
|
1154
|
+
var pool_used: usize = 0;
|
|
1155
|
+
for (items[0..count], 0..) |item, index| {
|
|
1156
|
+
const label = escapeMenuLabelAmpersands(item.label, label_pool, &pool_used);
|
|
1157
|
+
buffer[index] = .{
|
|
1158
|
+
.item_id = item.id,
|
|
1159
|
+
.label = label.ptr,
|
|
1160
|
+
.label_len = label.len,
|
|
1161
|
+
.enabled = if (item.enabled) 1 else 0,
|
|
1162
|
+
.separator = if (item.separator) 1 else 0,
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
return buffer[0..count];
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
fn showContextMenu(context: ?*anyopaque, request: platform_mod.ContextMenuRequest) anyerror!void {
|
|
1169
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1170
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1171
|
+
var items: [platform_mod.max_context_menu_items]WindowsContextMenuItem = undefined;
|
|
1172
|
+
var label_pool: [platform_mod.max_context_menu_items * 64]u8 = undefined;
|
|
1173
|
+
const translated = contextMenuItemsToWindows(request.items, &items, &label_pool);
|
|
1174
|
+
if (native_sdk_windows_show_context_menu(
|
|
1175
|
+
self.host,
|
|
1176
|
+
request.window_id,
|
|
1177
|
+
request.view_label.ptr,
|
|
1178
|
+
request.view_label.len,
|
|
1179
|
+
request.point.x,
|
|
1180
|
+
request.point.y,
|
|
1181
|
+
request.token,
|
|
1182
|
+
translated.ptr,
|
|
1183
|
+
translated.len,
|
|
1184
|
+
) == 0) return error.WindowNotFound;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1009
1187
|
fn createWebView(context: ?*anyopaque, options: platform_mod.WebViewOptions) anyerror!void {
|
|
1010
1188
|
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1011
1189
|
const frame = options.frame;
|
|
@@ -1140,10 +1318,15 @@ fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem
|
|
|
1140
1318
|
var label_lens: [max_tray_items]usize = undefined;
|
|
1141
1319
|
var separators: [max_tray_items]c_int = undefined;
|
|
1142
1320
|
var enabled_flags: [max_tray_items]c_int = undefined;
|
|
1321
|
+
// Tray labels are app-supplied too, so they get the same mnemonic
|
|
1322
|
+
// escape as context-menu items (the host copies before returning).
|
|
1323
|
+
var label_pool: [max_tray_items * 64]u8 = undefined;
|
|
1324
|
+
var pool_used: usize = 0;
|
|
1143
1325
|
for (items[0..count], 0..) |item, index| {
|
|
1326
|
+
const label = escapeMenuLabelAmpersands(item.label, &label_pool, &pool_used);
|
|
1144
1327
|
ids[index] = item.id;
|
|
1145
|
-
labels[index] =
|
|
1146
|
-
label_lens[index] =
|
|
1328
|
+
labels[index] = label.ptr;
|
|
1329
|
+
label_lens[index] = label.len;
|
|
1147
1330
|
separators[index] = if (item.separator) 1 else 0;
|
|
1148
1331
|
enabled_flags[index] = if (item.enabled) 1 else 0;
|
|
1149
1332
|
}
|
|
@@ -1277,6 +1460,26 @@ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
|
|
|
1277
1460
|
_ = native_sdk_windows_audio_set_volume(self.host, volume);
|
|
1278
1461
|
}
|
|
1279
1462
|
|
|
1463
|
+
/// The video tier's teaching refusal: the load verbs exist so a video
|
|
1464
|
+
/// source fails with a NAMED explanation instead of a bare
|
|
1465
|
+
/// unsupported-service, while the transport verbs stay null — the
|
|
1466
|
+
/// channel never activates without a successful load. Pure (no Win32
|
|
1467
|
+
/// externs), so the teaching is unit-testable on every host.
|
|
1468
|
+
fn videoLoad(context: ?*anyopaque, path: []const u8, token: u64, sink: platform_mod.VideoFrameSink) anyerror!void {
|
|
1469
|
+
_ = context;
|
|
1470
|
+
_ = path;
|
|
1471
|
+
_ = token;
|
|
1472
|
+
_ = sink;
|
|
1473
|
+
std.debug.print("video playback is not implemented on windows yet: the Win32 host has no Media Foundation decode path into the media-surface texture channel - the app receives one failed video event (scope video sources to macos builds, or compose a media-surface with your own producer)\n", .{});
|
|
1474
|
+
return error.UnsupportedService;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
/// The URL twin rides the same teaching — a stream would need the same
|
|
1478
|
+
/// missing decode path a file does.
|
|
1479
|
+
fn videoLoadUrl(context: ?*anyopaque, url: []const u8, token: u64, sink: platform_mod.VideoFrameSink) anyerror!void {
|
|
1480
|
+
return videoLoad(context, url, token, sink);
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1280
1483
|
fn configureSecurityPolicy(context: ?*anyopaque, policy: security.Policy) anyerror!void {
|
|
1281
1484
|
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1282
1485
|
var origins_buffer: [4096]u8 = undefined;
|
|
@@ -1462,6 +1665,61 @@ test "windows gpu surface input preserves key and text" {
|
|
|
1462
1665
|
try std.testing.expect(input.modifiers.shift);
|
|
1463
1666
|
}
|
|
1464
1667
|
|
|
1668
|
+
test "windows context menu items translate separators, disabled flags, and labels" {
|
|
1669
|
+
const items = [_]platform_mod.ContextMenuItem{
|
|
1670
|
+
.{ .id = 1, .label = "Complete" },
|
|
1671
|
+
.{ .separator = true },
|
|
1672
|
+
.{ .id = 3, .label = "Delete", .enabled = false },
|
|
1673
|
+
.{ .id = 4, .label = "Move to R&D" },
|
|
1674
|
+
};
|
|
1675
|
+
var buffer: [platform_mod.max_context_menu_items]WindowsContextMenuItem = undefined;
|
|
1676
|
+
var label_pool: [platform_mod.max_context_menu_items * 64]u8 = undefined;
|
|
1677
|
+
const translated = contextMenuItemsToWindows(&items, &buffer, &label_pool);
|
|
1678
|
+
try std.testing.expectEqual(@as(usize, 4), translated.len);
|
|
1679
|
+
try std.testing.expectEqual(@as(u32, 1), translated[0].item_id);
|
|
1680
|
+
try std.testing.expectEqualStrings("Complete", translated[0].label[0..translated[0].label_len]);
|
|
1681
|
+
try std.testing.expectEqual(@as(c_int, 1), translated[0].enabled);
|
|
1682
|
+
try std.testing.expectEqual(@as(c_int, 0), translated[0].separator);
|
|
1683
|
+
try std.testing.expectEqual(@as(c_int, 1), translated[1].separator);
|
|
1684
|
+
try std.testing.expectEqual(@as(u32, 3), translated[2].item_id);
|
|
1685
|
+
try std.testing.expectEqual(@as(c_int, 0), translated[2].enabled);
|
|
1686
|
+
// A literal `&` doubles on the way to AppendMenuW so Win32 renders
|
|
1687
|
+
// it instead of eating it as a mnemonic marker; ampersand-free
|
|
1688
|
+
// labels pass through pointing at the caller's bytes.
|
|
1689
|
+
try std.testing.expectEqualStrings("Move to R&&D", translated[3].label[0..translated[3].label_len]);
|
|
1690
|
+
try std.testing.expectEqual(items[0].label.ptr, translated[0].label);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
test "windows menu label escape passes a label through raw when the pool cannot hold it" {
|
|
1694
|
+
var pool: [4]u8 = undefined;
|
|
1695
|
+
var used: usize = 0;
|
|
1696
|
+
const label = "R&D";
|
|
1697
|
+
// Escaped form needs 4 bytes and fits exactly.
|
|
1698
|
+
try std.testing.expectEqualStrings("R&&D", escapeMenuLabelAmpersands(label, &pool, &used));
|
|
1699
|
+
// The pool is spent: the next ampersand label rides unescaped
|
|
1700
|
+
// (accidental mnemonic) rather than truncated.
|
|
1701
|
+
const passed_through = escapeMenuLabelAmpersands(label, &pool, &used);
|
|
1702
|
+
try std.testing.expectEqualStrings("R&D", passed_through);
|
|
1703
|
+
try std.testing.expectEqual(label.ptr, passed_through.ptr);
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
test "windows context menu action event maps token and item id" {
|
|
1707
|
+
const label = "canvas";
|
|
1708
|
+
var event = std.mem.zeroes(WindowsEvent);
|
|
1709
|
+
event.kind = .context_menu_action;
|
|
1710
|
+
event.window_id = 7;
|
|
1711
|
+
event.view_label = label.ptr;
|
|
1712
|
+
event.view_label_len = label.len;
|
|
1713
|
+
event.widget_id = 42;
|
|
1714
|
+
event.menu_item_id = 3;
|
|
1715
|
+
|
|
1716
|
+
const action = contextMenuActionEventFromWindowsEvent(&event);
|
|
1717
|
+
try std.testing.expectEqual(@as(platform_mod.WindowId, 7), action.window_id);
|
|
1718
|
+
try std.testing.expectEqualStrings("canvas", action.view_label);
|
|
1719
|
+
try std.testing.expectEqual(@as(u64, 42), action.token);
|
|
1720
|
+
try std.testing.expectEqual(@as(u32, 3), action.item_id);
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1465
1723
|
test "windows gpu surface input maps pointer cancel" {
|
|
1466
1724
|
var event = std.mem.zeroes(WindowsEvent);
|
|
1467
1725
|
event.input_kind = 11;
|
|
@@ -1520,6 +1778,7 @@ test "windows chromium reports unsupported native surfaces" {
|
|
|
1520
1778
|
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .gpu_surfaces));
|
|
1521
1779
|
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .audio_playback));
|
|
1522
1780
|
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .audio_streaming));
|
|
1781
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .context_menus));
|
|
1523
1782
|
|
|
1524
1783
|
var chromium = testPlatformWithEngine(.chromium);
|
|
1525
1784
|
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .main_webview));
|
|
@@ -1531,6 +1790,7 @@ test "windows chromium reports unsupported native surfaces" {
|
|
|
1531
1790
|
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .gpu_surfaces));
|
|
1532
1791
|
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .audio_playback));
|
|
1533
1792
|
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .audio_streaming));
|
|
1793
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .context_menus));
|
|
1534
1794
|
}
|
|
1535
1795
|
|
|
1536
1796
|
test "windows hide-on-close support requires the declared tray (the only re-show affordance)" {
|
|
@@ -1584,6 +1844,35 @@ test "windows WM_CLOSE hide consults the live tray state and downgrades to a rea
|
|
|
1584
1844
|
try std.testing.expect(std.mem.indexOf(u8, close_hook, "downgraded to a real close") != null);
|
|
1585
1845
|
}
|
|
1586
1846
|
|
|
1847
|
+
test "windows window focus includes focused native child views" {
|
|
1848
|
+
// This predicate lives in the C++ host, where the real HWND tree is
|
|
1849
|
+
// available. Pin the two parts of its contract textually: focus is
|
|
1850
|
+
// resolved through GA_ROOT, and every emitted window frame uses
|
|
1851
|
+
// that shared answer. Cross-target host builds compile the code;
|
|
1852
|
+
// the Windows canvas smoke supplies the live child-focus exercise.
|
|
1853
|
+
const host_source = @embedFile("webview2_host.cpp");
|
|
1854
|
+
const predicate_at = std.mem.indexOf(u8, host_source, "static bool windowOwnsKeyboardFocus(const Window &window)");
|
|
1855
|
+
try std.testing.expect(predicate_at != null);
|
|
1856
|
+
const predicate = host_source[predicate_at.?..];
|
|
1857
|
+
try std.testing.expect(std.mem.indexOf(u8, predicate, "GetAncestor(focused, GA_ROOT) == window.hwnd") != null);
|
|
1858
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "event.focused = windowOwnsKeyboardFocus(window);") != null);
|
|
1859
|
+
const focus_edge_at = std.mem.indexOf(u8, host_source, "case WM_SETFOCUS:");
|
|
1860
|
+
try std.testing.expect(focus_edge_at != null);
|
|
1861
|
+
const focus_edge = host_source[focus_edge_at.?..];
|
|
1862
|
+
try std.testing.expect(std.mem.indexOf(u8, focus_edge, "HWND root = GetAncestor(hwnd, GA_ROOT);") != null);
|
|
1863
|
+
try std.testing.expect(std.mem.indexOf(u8, focus_edge, "entry.second.hwnd == root") != null);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
test "windows webview focus reports the focused child label" {
|
|
1867
|
+
// WebView2 owns the page HWND and its input; GotFocus is the
|
|
1868
|
+
// controller-level edge that mirrors keyboard ownership back into
|
|
1869
|
+
// the runtime's per-view register.
|
|
1870
|
+
const host_source = @embedFile("webview2_host.cpp");
|
|
1871
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "add_GotFocus(Callback<ICoreWebView2FocusChangedEventHandler>") != null);
|
|
1872
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "event.kind = kViewFocused;") != null);
|
|
1873
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "event.view_label = focused->second.label.c_str();") != null);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1587
1876
|
test "windows audio event maps kinds and payload" {
|
|
1588
1877
|
var event = std.mem.zeroes(WindowsEvent);
|
|
1589
1878
|
event.audio_kind = 1;
|