@native-sdk/cli 0.5.3 → 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.
Files changed (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -9,6 +9,7 @@ pub const Error = error{
9
9
  CreateFailed,
10
10
  FocusFailed,
11
11
  CloseFailed,
12
+ UnsupportedWindowClosePolicy,
12
13
  };
13
14
 
14
15
  const WindowsHost = opaque {};
@@ -33,6 +34,8 @@ const WindowsEventKind = enum(c_int) {
33
34
  timer = 16,
34
35
  appearance = 17,
35
36
  audio = 18,
37
+ context_menu_action = 19,
38
+ view_focused = 20,
36
39
  };
37
40
 
38
41
  const WindowsEvent = extern struct {
@@ -45,6 +48,9 @@ const WindowsEvent = extern struct {
45
48
  y: f64,
46
49
  open: c_int,
47
50
  focused: c_int,
51
+ /// Nonzero while the window is alive but hidden by its close_policy
52
+ /// (`open` stays 1 for the whole hidden stretch).
53
+ hidden: c_int,
48
54
  label: [*]const u8,
49
55
  label_len: usize,
50
56
  title: [*]const u8,
@@ -97,6 +103,12 @@ const WindowsEvent = extern struct {
97
103
  /// documented scale (log-spaced 50 Hz..16 kHz buckets, linear-in-dB
98
104
  /// from -60 dBFS at 0 to full scale at 255). Zeros elsewhere.
99
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,
100
112
  };
101
113
 
102
114
  const WindowsCallback = *const fn (context: ?*anyopaque, event: *const WindowsEvent) callconv(.c) void;
@@ -134,6 +146,8 @@ extern fn native_sdk_windows_cancel_timer(host: *WindowsHost, timer_id: u64) voi
134
146
  extern fn native_sdk_windows_focus_window(host: *WindowsHost, window_id: u64) c_int;
135
147
  extern fn native_sdk_windows_close_window(host: *WindowsHost, window_id: u64) c_int;
136
148
  extern fn native_sdk_windows_minimize_window(host: *WindowsHost, window_id: u64) c_int;
149
+ extern fn native_sdk_windows_show_window(host: *WindowsHost, window_id: u64) c_int;
150
+ extern fn native_sdk_windows_set_window_close_policy(host: *WindowsHost, window_id: u64, close_policy: c_int) c_int;
137
151
  extern fn native_sdk_windows_create_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, kind: c_int, parent: [*]const u8, parent_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, visible: c_int, enabled: c_int, role: [*]const u8, role_len: usize, accessibility_label: [*]const u8, accessibility_label_len: usize, text: [*]const u8, text_len: usize, command: [*]const u8, command_len: usize) c_int;
138
152
  extern fn native_sdk_windows_update_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, has_frame: c_int, x: f64, y: f64, width: f64, height: f64, has_layer: c_int, layer: c_int, has_visible: c_int, visible: c_int, has_enabled: c_int, enabled: c_int, has_role: c_int, role: [*]const u8, role_len: usize, has_accessibility_label: c_int, accessibility_label: [*]const u8, accessibility_label_len: usize, has_text: c_int, text: [*]const u8, text_len: usize, has_command: c_int, command: [*]const u8, command_len: usize) c_int;
139
153
  extern fn native_sdk_windows_set_view_frame(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, width: f64, height: f64) c_int;
@@ -175,6 +189,17 @@ extern fn native_sdk_windows_audio_stop(host: *WindowsHost) c_int;
175
189
  extern fn native_sdk_windows_audio_seek(host: *WindowsHost, position_ms: u64) c_int;
176
190
  extern fn native_sdk_windows_audio_set_volume(host: *WindowsHost, volume: f64) c_int;
177
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
+ };
178
203
 
179
204
  const WindowsOpenDialogOpts = extern struct {
180
205
  title: [*]const u8,
@@ -219,12 +244,41 @@ const WindowsMessageDialogOpts = extern struct {
219
244
  tertiary_button_len: usize,
220
245
  };
221
246
 
247
+ /// The startup-window twin of the runtime's create-time `.hide` gate:
248
+ /// on windows, hide-on-close is honest only when the app declares a
249
+ /// tray (status item) — SW_HIDE removes the taskbar entry and windows
250
+ /// has no dock-reopen path, so without a tray a hidden window is a
251
+ /// running, invisible, unreachable app. The generated runner refuses
252
+ /// the declaration at comptime, the runtime refuses secondary windows
253
+ /// at create (through the conditional `window_hide_on_close` answer
254
+ /// below), and this refuses the platform-created main window at init.
255
+ /// Pure (no Win32 externs), so the refusal is unit-testable on every
256
+ /// host.
257
+ fn refuseUnsupportedMainWindowClosePolicy(app_info: platform_mod.AppInfo) Error!void {
258
+ if (app_info.resolvedMainWindow().close_policy != .hide) return;
259
+ if (app_info.declares_tray) return;
260
+ std.debug.print("window close_policy \"hide\" on windows requires the \"tray\" capability: hiding removes the taskbar entry and windows has no dock-reopen path, so only a status item (tray) could bring the hidden window back - add \"tray\" to .capabilities and install a status item, or declare \"quit\" (the default)\n", .{});
261
+ return error.UnsupportedWindowClosePolicy;
262
+ }
263
+
222
264
  pub const WindowsPlatform = struct {
223
265
  host: *WindowsHost,
224
266
  web_engine: platform_mod.WebEngine,
225
267
  app_info: platform_mod.AppInfo,
226
268
  surface_value: platform_mod.Surface,
227
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),
228
282
 
229
283
  pub fn init(title: []const u8, size: geometry.SizeF) Error!WindowsPlatform {
230
284
  return initWithEngine(title, size, .system);
@@ -236,9 +290,21 @@ pub const WindowsPlatform = struct {
236
290
 
237
291
  pub fn initWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!WindowsPlatform {
238
292
  const window_options = app_info.resolvedMainWindow();
293
+ // The MAIN window is created right here, before any runtime
294
+ // exists, so the runtime's create-time `.hide` gate (the
295
+ // window_hide_on_close feature check) never sees it — the same
296
+ // seam the GTK host holds for its unconditional refusal. On
297
+ // windows the refusal is conditional: hiding removes the
298
+ // taskbar entry and windows has no dock-reopen path, so a
299
+ // declared tray (status item) is the ONLY re-show affordance.
300
+ try refuseUnsupportedMainWindowClosePolicy(app_info);
239
301
  const window_title = window_options.resolvedTitle(app_info.app_name);
240
302
  const frame = window_options.default_frame;
241
303
  const host = native_sdk_windows_create(app_info.app_name.ptr, app_info.app_name.len, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, app_info.icon_path.ptr, app_info.icon_path.len, window_options.label.ptr, window_options.label.len, frame.x, frame.y, frame.width, frame.height, if (window_options.restore_state) 1 else 0, if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), minSizeFloor(window_options.min_width), minSizeFloor(window_options.min_height)) orelse return error.CreateFailed;
304
+ // The manifest's declared close policy rides right after the
305
+ // create, like the min-size floor: close handling is host
306
+ // window state fixed for the window's life.
307
+ applyWindowClosePolicy(host, window_options.id, window_options.close_policy);
242
308
  return .{
243
309
  .host = host,
244
310
  .web_engine = web_engine,
@@ -251,7 +317,44 @@ pub const WindowsPlatform = struct {
251
317
  };
252
318
  }
253
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
+
254
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
+ }
255
358
  native_sdk_windows_destroy(self.host);
256
359
  }
257
360
 
@@ -277,6 +380,8 @@ pub const WindowsPlatform = struct {
277
380
  .focus_window_fn = focusWindow,
278
381
  .close_window_fn = closeWindow,
279
382
  .minimize_window_fn = minimizeWindow,
383
+ .show_window_fn = showWindow,
384
+ .quit_app_fn = quitApp,
280
385
  .start_window_drag_fn = startWindowDrag,
281
386
  .set_window_drag_regions_fn = setWindowDragRegions,
282
387
  .window_chrome_fn = windowChrome,
@@ -289,6 +394,7 @@ pub const WindowsPlatform = struct {
289
394
  .request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
290
395
  .note_gpu_surface_input_fn = noteGpuSurfaceInput,
291
396
  .present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
397
+ .show_context_menu_fn = showContextMenu,
292
398
  .create_webview_fn = createWebView,
293
399
  .set_webview_frame_fn = setWebViewFrame,
294
400
  .navigate_webview_fn = navigateWebView,
@@ -316,6 +422,11 @@ pub const WindowsPlatform = struct {
316
422
  .audio_stop_fn = audioStop,
317
423
  .audio_seek_fn = audioSeek,
318
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,
319
430
  .configure_security_policy_fn = configureSecurityPolicy,
320
431
  .configure_menus_fn = configureMenus,
321
432
  .configure_shortcuts_fn = configureShortcuts,
@@ -323,6 +434,7 @@ pub const WindowsPlatform = struct {
323
434
  .start_timer_fn = startTimer,
324
435
  .cancel_timer_fn = cancelTimer,
325
436
  .wake_fn = wake,
437
+ .note_channel_wake_abandoned_fn = noteChannelWakeAbandoned,
326
438
  .request_frame_fn = requestFrame,
327
439
  .decode_image_fn = decodeImage,
328
440
  },
@@ -354,16 +466,34 @@ pub const WindowsPlatform = struct {
354
466
  .audio_playback,
355
467
  .audio_streaming,
356
468
  => self.web_engine == .system,
469
+ // close_policy .hide: WM_CLOSE hides (ShowWindow SW_HIDE),
470
+ // the window stays in the host map, and the tray is the
471
+ // ONLY re-show affordance — SW_HIDE removes the taskbar
472
+ // entry and windows has no dock-reopen path. An app that
473
+ // declares no tray gets an honest false, so the runtime's
474
+ // create-time gates refuse a `.hide` declaration instead of
475
+ // stranding a hidden window nothing could re-show.
476
+ .window_hide_on_close => self.web_engine == .system and self.app_info.declares_tray,
357
477
  // Spectrum analysis captures the app's OWN audio session
358
478
  // through process-scoped WASAPI loopback, which the OS grew
359
479
  // in Windows 10 2004 — the host probes the activation
360
480
  // support live instead of assuming the build.
361
481
  .audio_spectrum => self.web_engine == .system and audioSpectrumAvailable(self.host),
362
- // Native scroll drivers, native context menus, and app-owned
363
- // view-surface adoption are macOS-only today; Win32 keeps
364
- // the engine's wheel physics (TrackPopupMenu is the natural
365
- // future context-menu seam — the tray already uses it).
366
- .gpu_surface_scroll_drivers, .context_menus, .view_surface_adoption => false,
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,
367
497
  };
368
498
  }
369
499
 
@@ -454,8 +584,13 @@ fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c
454
584
  .scale_factor = @floatCast(event.scale),
455
585
  .open = event.open != 0,
456
586
  .focused = event.focused != 0,
587
+ .hidden = event.hidden != 0,
457
588
  } });
458
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
+ } }),
459
594
  .shortcut => state.emit(.{ .shortcut = .{
460
595
  .id = event.shortcut_id[0..event.shortcut_id_len],
461
596
  .key = event.shortcut_key[0..event.shortcut_key_len],
@@ -516,9 +651,23 @@ fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c
516
651
  .buffering = event.audio_buffering != 0,
517
652
  .bands = event.audio_bands,
518
653
  } }),
654
+ .context_menu_action => state.emit(.{ .context_menu_action = contextMenuActionEventFromWindowsEvent(event) }),
519
655
  }
520
656
  }
521
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
+
522
671
  /// Ordinals match the audio report kinds in webview2_host.cpp (the same
523
672
  /// set the macOS host uses); anything unknown degrades to `.failed` so a
524
673
  /// host/SDK skew is loud in the app instead of undefined behavior here.
@@ -650,13 +799,23 @@ fn emitWindowEvent(context: ?*anyopaque, window_id: platform_mod.WindowId, name:
650
799
  native_sdk_windows_emit_window_event(self.host, window_id, name.ptr, name.len, detail_json.ptr, detail_json.len);
651
800
  }
652
801
 
653
- /// Thread-safe: `PostMessage` into the existing message loop, whose
654
- /// window procedure emits `.wake` on the loop thread.
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.
655
806
  fn wake(context: ?*anyopaque) anyerror!void {
656
807
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
657
808
  native_sdk_windows_wake(self.host);
658
809
  }
659
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
+
660
819
  /// Thread-safe like `wake`: `PostMessage` into the message loop, whose
661
820
  /// window procedure emits one `.frame` event on the loop thread. The
662
821
  /// automation arrival watcher calls this when a command lands so
@@ -666,6 +825,15 @@ fn requestFrame(context: ?*anyopaque) anyerror!void {
666
825
  native_sdk_windows_request_frame(self.host);
667
826
  }
668
827
 
828
+ /// Headless image codec for session replay: the SAME WIC decode a live
829
+ /// host serves (see `decodeImage` below — a context-free bytes-to-pixels
830
+ /// call, no window, no message loop), so journaled image bytes
831
+ /// re-register the identical pixels under a headless replay on the same
832
+ /// platform.
833
+ pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {
834
+ services.decode_image_fn = decodeImage;
835
+ }
836
+
669
837
  /// WIC-backed image decoding (PNG, JPEG, ... — every codec the OS
670
838
  /// ships) into straight-alpha RGBA8.
671
839
  fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
@@ -690,6 +858,20 @@ fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
690
858
 
691
859
  /// Zero/negative/non-finite floors are the "no floor" sentinel (the
692
860
  /// host leaves that axis at its natural minimum).
861
+ fn closePolicyInt(policy: platform_mod.WindowClosePolicy) c_int {
862
+ return switch (policy) {
863
+ .quit => 0,
864
+ .hide => 1,
865
+ };
866
+ }
867
+
868
+ /// Register a window's declared close policy with the host right after
869
+ /// create. `.quit` skips the call — it IS the host default.
870
+ fn applyWindowClosePolicy(host: *WindowsHost, window_id: u64, policy: platform_mod.WindowClosePolicy) void {
871
+ if (policy == .quit) return;
872
+ _ = native_sdk_windows_set_window_close_policy(host, window_id, closePolicyInt(policy));
873
+ }
874
+
693
875
  fn minSizeFloor(value: f32) f64 {
694
876
  return if (std.math.isFinite(value) and value > 0) value else 0;
695
877
  }
@@ -699,6 +881,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
699
881
  const title = options.resolvedTitle(self.app_info.app_name);
700
882
  const frame = options.default_frame;
701
883
  if (native_sdk_windows_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), minSizeFloor(options.min_width), minSizeFloor(options.min_height)) == 0) return error.CreateFailed;
884
+ applyWindowClosePolicy(self.host, options.id, options.close_policy);
702
885
  return .{
703
886
  .id = options.id,
704
887
  .label = options.label,
@@ -725,6 +908,19 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
725
908
  if (native_sdk_windows_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
726
909
  }
727
910
 
911
+ fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
912
+ const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
913
+ if (native_sdk_windows_show_window(self.host, window_id) == 0) return error.WindowNotFound;
914
+ }
915
+
916
+ /// The graceful quit: stop the message loop the same way the last
917
+ /// window's WM_DESTROY does (PostQuitMessage); the run loop's exit
918
+ /// emits the same shutdown event.
919
+ fn quitApp(context: ?*anyopaque) anyerror!void {
920
+ const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
921
+ native_sdk_windows_stop(self.host);
922
+ }
923
+
728
924
  fn startWindowDrag(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
729
925
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
730
926
  if (native_sdk_windows_start_window_drag(self.host, window_id) == 0) return error.WindowNotFound;
@@ -923,6 +1119,71 @@ fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: platform_mod.GpuSurface
923
1119
  ) == 0) return error.ViewNotFound;
924
1120
  }
925
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
+
926
1187
  fn createWebView(context: ?*anyopaque, options: platform_mod.WebViewOptions) anyerror!void {
927
1188
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
928
1189
  const frame = options.frame;
@@ -1057,10 +1318,15 @@ fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem
1057
1318
  var label_lens: [max_tray_items]usize = undefined;
1058
1319
  var separators: [max_tray_items]c_int = undefined;
1059
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;
1060
1325
  for (items[0..count], 0..) |item, index| {
1326
+ const label = escapeMenuLabelAmpersands(item.label, &label_pool, &pool_used);
1061
1327
  ids[index] = item.id;
1062
- labels[index] = item.label.ptr;
1063
- label_lens[index] = item.label.len;
1328
+ labels[index] = label.ptr;
1329
+ label_lens[index] = label.len;
1064
1330
  separators[index] = if (item.separator) 1 else 0;
1065
1331
  enabled_flags[index] = if (item.enabled) 1 else 0;
1066
1332
  }
@@ -1194,6 +1460,26 @@ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1194
1460
  _ = native_sdk_windows_audio_set_volume(self.host, volume);
1195
1461
  }
1196
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
+
1197
1483
  fn configureSecurityPolicy(context: ?*anyopaque, policy: security.Policy) anyerror!void {
1198
1484
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1199
1485
  var origins_buffer: [4096]u8 = undefined;
@@ -1379,6 +1665,61 @@ test "windows gpu surface input preserves key and text" {
1379
1665
  try std.testing.expect(input.modifiers.shift);
1380
1666
  }
1381
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
+
1382
1723
  test "windows gpu surface input maps pointer cancel" {
1383
1724
  var event = std.mem.zeroes(WindowsEvent);
1384
1725
  event.input_kind = 11;
@@ -1437,6 +1778,7 @@ test "windows chromium reports unsupported native surfaces" {
1437
1778
  try std.testing.expect(WindowsPlatform.supportsFeature(&system, .gpu_surfaces));
1438
1779
  try std.testing.expect(WindowsPlatform.supportsFeature(&system, .audio_playback));
1439
1780
  try std.testing.expect(WindowsPlatform.supportsFeature(&system, .audio_streaming));
1781
+ try std.testing.expect(WindowsPlatform.supportsFeature(&system, .context_menus));
1440
1782
 
1441
1783
  var chromium = testPlatformWithEngine(.chromium);
1442
1784
  try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .main_webview));
@@ -1448,6 +1790,87 @@ test "windows chromium reports unsupported native surfaces" {
1448
1790
  try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .gpu_surfaces));
1449
1791
  try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .audio_playback));
1450
1792
  try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .audio_streaming));
1793
+ try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .context_menus));
1794
+ }
1795
+
1796
+ test "windows hide-on-close support requires the declared tray (the only re-show affordance)" {
1797
+ // A system-engine host with a declared tray keeps hide-on-close.
1798
+ var with_tray = testPlatformWithEngine(.system);
1799
+ with_tray.app_info.declares_tray = true;
1800
+ try std.testing.expect(WindowsPlatform.supportsFeature(&with_tray, .window_hide_on_close));
1801
+ // Without the declaration the answer is an honest false: SW_HIDE
1802
+ // removes the taskbar entry and windows has no dock-reopen path, so
1803
+ // the runtime's create-time gates must refuse a `.hide` declaration
1804
+ // instead of stranding a hidden window nothing could re-show.
1805
+ var without_tray = testPlatformWithEngine(.system);
1806
+ try std.testing.expect(!WindowsPlatform.supportsFeature(&without_tray, .window_hide_on_close));
1807
+ // The chromium engine answers false regardless, tray or not.
1808
+ var chromium = testPlatformWithEngine(.chromium);
1809
+ chromium.app_info.declares_tray = true;
1810
+ try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .window_hide_on_close));
1811
+ }
1812
+
1813
+ test "windows refuses a tray-less .hide main window at platform init instead of stranding it hidden" {
1814
+ // The pre-created MAIN window never passes through the runtime's
1815
+ // create gate, so the platform's init gate must hold the same line
1816
+ // (the GTK host's init refusal is the unconditional twin).
1817
+ const hide_no_tray: platform_mod.AppInfo = .{ .app_name = "player", .main_window = .{ .close_policy = .hide } };
1818
+ try std.testing.expectError(error.UnsupportedWindowClosePolicy, refuseUnsupportedMainWindowClosePolicy(hide_no_tray));
1819
+ // The declared tray is the re-show affordance: with it, the same
1820
+ // declaration passes.
1821
+ const hide_with_tray: platform_mod.AppInfo = .{ .app_name = "player", .declares_tray = true, .main_window = .{ .close_policy = .hide } };
1822
+ try refuseUnsupportedMainWindowClosePolicy(hide_with_tray);
1823
+ // The default (.quit) never consults the tray.
1824
+ const quit_app: platform_mod.AppInfo = .{ .app_name = "player" };
1825
+ try refuseUnsupportedMainWindowClosePolicy(quit_app);
1826
+ }
1827
+
1828
+ test "windows WM_CLOSE hide consults the live tray state and downgrades to a real close without it" {
1829
+ // The downgrade branch is C++ this test suite cannot execute, so
1830
+ // this pins the tray-alive consult and the loud downgrade line
1831
+ // textually: a refactor that drops either fails here. Compilation
1832
+ // is covered by the cross-target syntax checks the packaging path
1833
+ // runs; live close behavior stays windows-host territory.
1834
+ const host_source = @embedFile("webview2_host.cpp");
1835
+ const close_at = std.mem.indexOf(u8, host_source, "case WM_CLOSE:");
1836
+ try std.testing.expect(close_at != null);
1837
+ const close_hook = host_source[close_at.?..];
1838
+ const consult_at = std.mem.indexOf(u8, close_hook, "if (!host->tray_active)");
1839
+ const hide_at = std.mem.indexOf(u8, close_hook, "ShowWindow(hwnd, SW_HIDE);");
1840
+ try std.testing.expect(consult_at != null);
1841
+ try std.testing.expect(hide_at != null);
1842
+ // The consult sits INSIDE the close hook, BEFORE the hide.
1843
+ try std.testing.expect(consult_at.? < hide_at.?);
1844
+ try std.testing.expect(std.mem.indexOf(u8, close_hook, "downgraded to a real close") != null);
1845
+ }
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);
1451
1874
  }
1452
1875
 
1453
1876
  test "windows audio event maps kinds and payload" {