@native-sdk/cli 0.5.3 → 0.5.4

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 (79) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +223 -3
  3. package/native-sdk.d.ts +17 -1
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/rt/rt.zig +138 -3
  8. package/packages/core/sdk/core.ts +225 -3
  9. package/packages/core/src/emitter.ts +2586 -259
  10. package/skill-data/native-ui/SKILL.md +3 -2
  11. package/skill-data/ts-core/SKILL.md +9 -1
  12. package/src/app_runner/root.zig +81 -1
  13. package/src/app_runner/ts_core_main.zig +4 -0
  14. package/src/embed/tests.zig +119 -1
  15. package/src/platform/linux/gtk_host.c +112 -3
  16. package/src/platform/linux/root.zig +71 -0
  17. package/src/platform/macos/appkit_host.h +48 -2
  18. package/src/platform/macos/appkit_host.m +533 -34
  19. package/src/platform/macos/cef_host.mm +262 -10
  20. package/src/platform/macos/root.zig +92 -4
  21. package/src/platform/null_platform.zig +298 -5
  22. package/src/platform/root.zig +33 -0
  23. package/src/platform/types.zig +138 -4
  24. package/src/platform/windows/root.zig +134 -0
  25. package/src/platform/windows/webview2_host.cpp +152 -40
  26. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  27. package/src/primitives/app_manifest/root.zig +1 -0
  28. package/src/primitives/app_manifest/types.zig +32 -0
  29. package/src/primitives/canvas/tests.zig +1 -0
  30. package/src/primitives/canvas/ui.zig +11 -7
  31. package/src/primitives/canvas/ui_markup.zig +58 -34
  32. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  33. package/src/primitives/canvas/ui_markup_compiled.zig +23 -8
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +1 -1
  36. package/src/primitives/canvas/ui_markup_contract_tests.zig +26 -0
  37. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  38. package/src/primitives/canvas/ui_markup_tests.zig +29 -9
  39. package/src/primitives/canvas/ui_markup_view.zig +29 -11
  40. package/src/primitives/canvas/ui_markup_view_tests.zig +150 -9
  41. package/src/primitives/canvas/ui_schema.zig +13 -0
  42. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  43. package/src/root.zig +7 -0
  44. package/src/runtime/api.zig +6 -4
  45. package/src/runtime/bridge_payload.zig +7 -0
  46. package/src/runtime/bridge_responses.zig +5 -0
  47. package/src/runtime/builtin_bridge.zig +9 -4
  48. package/src/runtime/canvas_font_tests.zig +439 -2
  49. package/src/runtime/canvas_fonts.zig +61 -6
  50. package/src/runtime/canvas_image_tests.zig +195 -0
  51. package/src/runtime/canvas_images.zig +45 -12
  52. package/src/runtime/core.zig +58 -11
  53. package/src/runtime/effects.zig +1664 -43
  54. package/src/runtime/effects_fetch_tests.zig +89 -1
  55. package/src/runtime/effects_file_tests.zig +41 -1
  56. package/src/runtime/effects_image_tests.zig +1304 -0
  57. package/src/runtime/effects_tests.zig +153 -0
  58. package/src/runtime/flow.zig +17 -0
  59. package/src/runtime/root.zig +11 -0
  60. package/src/runtime/session_blobs.zig +689 -0
  61. package/src/runtime/session_journal.zig +85 -21
  62. package/src/runtime/session_record.zig +27 -2
  63. package/src/runtime/session_replay.zig +168 -16
  64. package/src/runtime/session_tests.zig +1992 -0
  65. package/src/runtime/shell_layout.zig +7 -0
  66. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  67. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +439 -4
  70. package/src/runtime/ts_core_host_tests.zig +41 -0
  71. package/src/runtime/ts_ui_app.zig +7 -0
  72. package/src/runtime/ui_app.zig +111 -6
  73. package/src/runtime/ui_app_window_tests.zig +468 -0
  74. package/src/runtime/window_command_bridge_tests.zig +117 -0
  75. package/src/runtime/window_storage.zig +32 -0
  76. package/src/runtime/window_views.zig +61 -1
  77. package/src/tooling/manifest.zig +75 -0
  78. package/src/tooling/raw_manifest.zig +2 -0
  79. package/src/tooling/templates.zig +219 -1
@@ -41,7 +41,16 @@
41
41
  * WebView loads report WebViewNotFound at runtime. */
42
42
  #if defined(NATIVE_SDK_ALLOW_WEBVIEW2_STUB)
43
43
  #define NATIVE_SDK_HAS_WEBVIEW2 0
44
- #pragma message("Embedded WebView layer excluded by the build configuration: building the Windows host without it (canvas apps unaffected; WebView loads will report WebViewNotFound)")
44
+ /* Deliberately NO compiler diagnostic in this branch — not even an
45
+ * informational #pragma message. The stub is the expected, configured
46
+ * state of every native-only Windows build, and zig renders every
47
+ * clang diagnostic of a failing translation unit as `error:` (its
48
+ * serialized clang diagnostics carry no severity into the error
49
+ * bundle), so an informational note here masquerades as the
50
+ * build-killing error the moment any unrelated real error appears
51
+ * anywhere in this file. The teaching lives where it is actionable
52
+ * instead: a stubbed host reports WebViewNotFound the moment an app
53
+ * actually uses a WebView. */
45
54
  #elif __has_include(<WebView2.h>) && __has_include(<wrl.h>)
46
55
  #include <WebView2.h>
47
56
  #include <wrl.h>
@@ -184,6 +193,10 @@ struct WindowsEvent {
184
193
  double y;
185
194
  int open;
186
195
  int focused;
196
+ /* kWindowFrame: nonzero while the window is alive but hidden by its
197
+ * close_policy (.hide intercepted WM_CLOSE). open stays 1 for the
198
+ * window's whole hidden stretch. */
199
+ int hidden;
187
200
  const char *label;
188
201
  size_t label_len;
189
202
  const char *title;
@@ -306,6 +319,14 @@ struct Window {
306
319
  * behind the button cluster matches the app's header). */
307
320
  COLORREF hidden_caption_color = 0;
308
321
  bool hidden_caption_color_set = false;
322
+ /* close_policy: 0 = quit (WM_CLOSE destroys; the default), 1 = hide
323
+ * (WM_CLOSE hides — SW_HIDE — and the app keeps running behind its
324
+ * tray icon, the Win32 tray-player shape). Applied right after
325
+ * create via native_sdk_windows_set_window_close_policy. */
326
+ int close_policy = 0;
327
+ /* True while the .hide policy has this window off the glass; the
328
+ * hwnd stays live and the map entry stays owned. */
329
+ bool policy_hidden = false;
309
330
  };
310
331
 
311
332
  /* One rectangle of a canvas view's window-drag mirror (runtime push,
@@ -1157,6 +1178,7 @@ static void emit(Host *host, const Window &window, EventKind kind) {
1157
1178
  event.y = window.y;
1158
1179
  event.open = window.hwnd != nullptr;
1159
1180
  event.focused = window.hwnd && GetFocus() == window.hwnd;
1181
+ event.hidden = window.policy_hidden ? 1 : 0;
1160
1182
  event.label = window.label.c_str();
1161
1183
  event.label_len = window.label.size();
1162
1184
  event.title = window.title.c_str();
@@ -1808,11 +1830,15 @@ constexpr uint64_t kGpuFrameIntervalNs = 16666667ull;
1808
1830
  * riding the frame channel (on_frame interpolation, armed tweens) and
1809
1831
  * snap it on restore; the heartbeat keeps those models gently current
1810
1832
  * while event-driven truth (audio position, input) flows at its own
1811
- * cadence. Minimize (IsIconic on the root window) is the one occlusion
1812
- * signal Win32 reports reliably for this GDI-presenting host; a window
1813
- * fully covered by other windows has no dependable signal without a
1814
- * DXGI presentation path, so covered-but-not-minimized windows keep
1815
- * full cadence deliberately rather than guess. */
1833
+ * cadence. Two occlusion facts key the throttle: minimize (IsIconic on
1834
+ * the root window — the one signal Win32 reports reliably for this
1835
+ * GDI-presenting host) and the close_policy .hide hide (host-owned
1836
+ * bookkeeping: a policy-hidden window is SW_HIDE'd off the glass, and
1837
+ * the menu-bar app shape keeps it that way for days — full-rate frame
1838
+ * completions there are pure background CPU burn). A window fully
1839
+ * covered by OTHER windows has no dependable signal without a DXGI
1840
+ * presentation path, so covered-but-not-minimized windows keep full
1841
+ * cadence deliberately rather than guess. */
1816
1842
  constexpr uint64_t kGpuOccludedHeartbeatNs = 1000000000ull;
1817
1843
  /* Placeholder pump timer (repeating, retired by the first present). */
1818
1844
  constexpr UINT_PTR kGpuFrameTimerId = 1;
@@ -2389,13 +2415,19 @@ static void gpuSurfaceAdvancePacingClock(NativeView &view) {
2389
2415
  }
2390
2416
  }
2391
2417
 
2392
- /* Frame completions run on the minimized heartbeat when the surface has
2393
- * presented at least once and its top-level window is iconic — the same
2394
- * first-present exemption the macOS occluded pacing keeps, so surface
2395
- * establishment (and the nonblank verdict automation reads) is never
2396
- * throttled. */
2397
- static bool gpuSurfaceOccludedPacingActive(const NativeView &view) {
2418
+ /* Frame completions run on the occluded heartbeat when the surface has
2419
+ * presented at least once and its window is off the glass — iconic, or
2420
+ * alive-but-hidden under close_policy .hide (see kGpuOccludedHeartbeatNs:
2421
+ * both facts are reliable, and a policy-hidden menu-bar app would
2422
+ * otherwise spin its frame loop full-rate for days). First-present
2423
+ * exemption as on macOS, so surface establishment (and the nonblank
2424
+ * verdict automation reads) is never throttled. */
2425
+ static bool gpuSurfaceOccludedPacingActive(Host *host, const NativeView &view) {
2398
2426
  if (!view.gpu_presented || !view.hwnd) return false;
2427
+ if (host) {
2428
+ auto owner = host->windows.find(view.window_id);
2429
+ if (owner != host->windows.end() && owner->second.policy_hidden) return true;
2430
+ }
2399
2431
  HWND root = GetAncestor(view.hwnd, GA_ROOT);
2400
2432
  return root != nullptr && IsIconic(root);
2401
2433
  }
@@ -2429,7 +2461,7 @@ static void gpuSurfaceEmitFrame(Host *host, NativeView &view, HWND hwnd) {
2429
2461
  /* Heartbeat-paced completions are not latency endpoints: their
2430
2462
  * timestamp measures the deliberate minimized cadence, not a paint
2431
2463
  * — the runtime skips input-latency stamping for them. */
2432
- event.occluded = gpuSurfaceOccludedPacingActive(view) ? 1 : 0;
2464
+ event.occluded = gpuSurfaceOccludedPacingActive(host, view) ? 1 : 0;
2433
2465
  emitGpuSurfaceEvent(host, view, event);
2434
2466
  }
2435
2467
 
@@ -2440,16 +2472,17 @@ static void gpuSurfaceEmitFrame(Host *host, NativeView &view, HWND hwnd) {
2440
2472
  * re-enter the engine — and the pacing clock's grid stamping keeps the
2441
2473
  * message hop out of the period. SetTimer clamps short delays up to its
2442
2474
  * ~10 ms floor; the clock absorbs that as jitter, not drift. */
2443
- static void gpuSurfaceScheduleFrameEmission(NativeView &view) {
2475
+ static void gpuSurfaceScheduleFrameEmission(Host *host, NativeView &view) {
2444
2476
  if (!view.hwnd || view.gpu_emission_scheduled) return;
2445
2477
  const uint64_t now = gpuTimestampNs();
2446
- /* Minimized surfaces pace on the heartbeat, not the frame grid —
2447
- * see kGpuOccludedHeartbeatNs. Exempt: an input's responding frame
2448
- * (external truth on its own cadence; it cannot sustain a spin).
2449
- * Restore re-arms the pending timer at the grid delay (the
2450
- * top-level WM_SIZE handler), so the long delay never gates the
2451
- * return to full cadence. */
2452
- const uint64_t pace_ns = (!view.gpu_prompt_frame_pending && gpuSurfaceOccludedPacingActive(view)) ? kGpuOccludedHeartbeatNs : kGpuFrameIntervalNs;
2478
+ /* Occluded surfaces (minimized or policy-hidden) pace on the
2479
+ * heartbeat, not the frame grid — see kGpuOccludedHeartbeatNs.
2480
+ * Exempt: an input's responding frame (external truth on its own
2481
+ * cadence; it cannot sustain a spin). Reveal re-arms the pending
2482
+ * timer at the grid delay (restore through the top-level WM_SIZE
2483
+ * handler, re-show through the show verb), so the long delay never
2484
+ * gates the return to full cadence. */
2485
+ const uint64_t pace_ns = (!view.gpu_prompt_frame_pending && gpuSurfaceOccludedPacingActive(host, view)) ? kGpuOccludedHeartbeatNs : kGpuFrameIntervalNs;
2453
2486
  uint64_t delay_ns = 0;
2454
2487
  if (view.gpu_last_emit_ns > 0 && now < view.gpu_last_emit_ns + pace_ns) {
2455
2488
  delay_ns = view.gpu_last_emit_ns + pace_ns - now;
@@ -2545,7 +2578,7 @@ static LRESULT CALLBACK gpuSurfaceProc(HWND hwnd, UINT message, WPARAM wparam, L
2545
2578
  KillTimer(hwnd, kGpuFrameTimerId);
2546
2579
  return 0;
2547
2580
  }
2548
- gpuSurfaceScheduleFrameEmission(*view);
2581
+ gpuSurfaceScheduleFrameEmission(host, *view);
2549
2582
  return 0;
2550
2583
  }
2551
2584
  if (wparam == kGpuEmitTimerId) {
@@ -3555,16 +3588,19 @@ static void audioSpectrumStartCapture(Host *host) {
3555
3588
  }
3556
3589
 
3557
3590
  /* Whether any of the host's top-level windows still reaches the glass.
3558
- * Minimize-keyed on purpose: IsIconic is the one occlusion fact this
3559
- * host trusts (the same decision the minimized frame heartbeat makes —
3560
- * the covered-but-not-minimized case has no reliable cheap signal on
3561
- * the DXGI presentation path), so covered windows keep full spectrum
3562
- * cadence and only an all-minimized app goes quiet. Checked across the
3563
- * whole window table because a spectrum consumer may draw its bands in
3564
- * any of the app's windows. */
3591
+ * Keyed on the two occlusion facts this host trusts (the same decision
3592
+ * the occluded frame heartbeat makes): minimize (IsIconic) and the
3593
+ * close_policy .hide hide (policy_hidden — a menu-bar app's window off
3594
+ * the glass behind its tray icon must not keep 25 Hz spectrum
3595
+ * emissions flowing for a display nobody can see). The
3596
+ * covered-but-not-minimized case has no reliable cheap signal without
3597
+ * a DXGI presentation path, so covered windows keep full spectrum
3598
+ * cadence and only an app with every window minimized or policy-hidden
3599
+ * goes quiet. Checked across the whole window table because a spectrum
3600
+ * consumer may draw its bands in any of the app's windows. */
3565
3601
  static bool audioAnyWindowReachesGlass(Host *host) {
3566
3602
  for (auto &entry : host->windows) {
3567
- if (entry.second.hwnd && !IsIconic(entry.second.hwnd)) return true;
3603
+ if (entry.second.hwnd && !IsIconic(entry.second.hwnd) && !entry.second.policy_hidden) return true;
3568
3604
  }
3569
3605
  return false;
3570
3606
  }
@@ -3575,12 +3611,13 @@ static bool audioAnyWindowReachesGlass(Host *host) {
3575
3611
  * transports emit nothing — the bars freeze honestly — while silence on
3576
3612
  * a rolling transport still emits its row of zeros. The occluded-
3577
3613
  * emission rule gates delivery too: SPECTRUM bands describe a display,
3578
- * so while every window is minimized no report is emitted — no event
3579
- * wakes the runtime's update loop for glass nobody can see, and the
3580
- * journal records the stretch as honest silence. The capture thread
3581
- * keeps its ring fresh (it must drain the loopback client regardless,
3582
- * and its FFT runs off the loop thread), so the first beat after a
3583
- * restore delivers current bands — honest within one report. */
3614
+ * so while every window is minimized or policy-hidden no report is
3615
+ * emitted — no event wakes the runtime's update loop for glass nobody
3616
+ * can see, and the journal records the stretch as honest silence. The
3617
+ * capture thread keeps its ring fresh (it must drain the loopback
3618
+ * client regardless, and its FFT runs off the loop thread), so the
3619
+ * first beat after a restore or re-show delivers current bands —
3620
+ * honest within one report. */
3584
3621
  static void audioHandleSpectrumMessage(Host *host, WPARAM generation) {
3585
3622
  AudioState &audio = host->audio;
3586
3623
  AudioSpectrumState &spectrum = host->spectrum;
@@ -4783,7 +4820,7 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
4783
4820
  if (surface.kind != kViewGpuSurface || !surface.hwnd || !surface.gpu_emission_scheduled) continue;
4784
4821
  if (GetAncestor(surface.hwnd, GA_ROOT) != hwnd) continue;
4785
4822
  surface.gpu_emission_scheduled = false;
4786
- gpuSurfaceScheduleFrameEmission(surface);
4823
+ gpuSurfaceScheduleFrameEmission(host, surface);
4787
4824
  }
4788
4825
  }
4789
4826
  }
@@ -4896,6 +4933,38 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
4896
4933
  if (host) emitAppearanceIfChanged(host, false);
4897
4934
  break;
4898
4935
  case WM_CLOSE:
4936
+ /* close_policy .hide: the user's close (caption X, Alt+F4)
4937
+ * hides the window instead of destroying it — the hwnd and
4938
+ * every view stay live, the app keeps running behind its
4939
+ * tray icon, and the frame event reports the hidden state.
4940
+ * Runtime-initiated closes call DestroyWindow directly
4941
+ * (native_sdk_windows_close_window) and bypass this hook. */
4942
+ if (host) {
4943
+ for (auto &entry : host->windows) {
4944
+ if (entry.second.hwnd == hwnd && entry.second.close_policy == 1) {
4945
+ /* The hide is honest only while a tray icon is
4946
+ * live: SW_HIDE removes the taskbar entry and
4947
+ * Windows has no dock-reopen path, so without a
4948
+ * tray the hidden window is a running, invisible,
4949
+ * unreachable app. tray_active is set only when
4950
+ * Shell_NotifyIcon actually added the icon, so a
4951
+ * declared tray whose creation FAILED at runtime
4952
+ * lands here too. The trade: consulting the live
4953
+ * state at close time means a close that arrives
4954
+ * before the app installs its tray (or after it
4955
+ * removes it) really closes — a loud, visible
4956
+ * close beats a silently stranded process. */
4957
+ if (!host->tray_active) {
4958
+ fprintf(stderr, "native-sdk: close_policy \"hide\" downgraded to a real close: no live tray icon exists (tray creation failed or no status item was installed), so a hidden window would have no re-show affordance\n");
4959
+ break;
4960
+ }
4961
+ entry.second.policy_hidden = true;
4962
+ ShowWindow(hwnd, SW_HIDE);
4963
+ emit(host, entry.second, kWindowFrame);
4964
+ return 0;
4965
+ }
4966
+ }
4967
+ }
4899
4968
  DestroyWindow(hwnd);
4900
4969
  return 0;
4901
4970
  case WM_DESTROY:
@@ -4905,6 +4974,8 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
4905
4974
  destroyNativeViewsForWindow(host, entry.first);
4906
4975
  destroyChildWebViewsForWindow(host, entry.first);
4907
4976
  entry.second.hwnd = nullptr;
4977
+ /* Destroyed means closed, never hidden. */
4978
+ entry.second.policy_hidden = false;
4908
4979
  emit(host, entry.second, kWindowFrame);
4909
4980
  }
4910
4981
  }
@@ -5594,6 +5665,47 @@ int native_sdk_windows_minimize_window(Host *host, uint64_t window_id) {
5594
5665
  return 1;
5595
5666
  }
5596
5667
 
5668
+ /* The show verb: bring the window back to the glass and foreground it —
5669
+ * the counterpart to a close_policy hide (and the tray-menu "Open"
5670
+ * consequence). Restores a minimized window on the way. */
5671
+ int native_sdk_windows_show_window(Host *host, uint64_t window_id) {
5672
+ if (!host) return 0;
5673
+ auto found = host->windows.find(window_id);
5674
+ if (found == host->windows.end() || !found->second.hwnd) return 0;
5675
+ found->second.policy_hidden = false;
5676
+ ShowWindow(found->second.hwnd, IsIconic(found->second.hwnd) ? SW_RESTORE : SW_SHOW);
5677
+ /* Re-show returns full frame cadence without dropping a beat, the
5678
+ * same supersede the top-level WM_SIZE handler runs on restore:
5679
+ * SW_SHOW on a same-size window dispatches no WM_SIZE, so a
5680
+ * heartbeat-paced emission parked up to a second out on a child
5681
+ * surface's one-shot timer is re-armed here at the frame-grid
5682
+ * delay (policy_hidden just cleared, so the scheduler paces on the
5683
+ * grid again; SetTimer with the same id replaces the pending
5684
+ * timer). */
5685
+ for (auto &view_entry : host->native_views) {
5686
+ NativeView &surface = view_entry.second;
5687
+ if (surface.kind != kViewGpuSurface || !surface.hwnd || !surface.gpu_emission_scheduled) continue;
5688
+ if (surface.window_id != window_id) continue;
5689
+ surface.gpu_emission_scheduled = false;
5690
+ gpuSurfaceScheduleFrameEmission(host, surface);
5691
+ }
5692
+ SetForegroundWindow(found->second.hwnd);
5693
+ SetFocus(found->second.hwnd);
5694
+ emit(host, found->second, kWindowFrame);
5695
+ return 1;
5696
+ }
5697
+
5698
+ /* What the user's close affordance does: 0 = quit (destroy; the
5699
+ * default), 1 = hide (SW_HIDE and keep running). Applied right after
5700
+ * create — close handling is host window state for the window's life. */
5701
+ int native_sdk_windows_set_window_close_policy(Host *host, uint64_t window_id, int close_policy) {
5702
+ if (!host) return 0;
5703
+ auto found = host->windows.find(window_id);
5704
+ if (found == host->windows.end()) return 0;
5705
+ found->second.close_policy = close_policy;
5706
+ return 1;
5707
+ }
5708
+
5597
5709
  int native_sdk_windows_create_view(Host *host, uint64_t window_id, const char *label, size_t label_len, int kind, const char *parent, size_t parent_len, double x, double y, double width, double height, int layer, int visible, int enabled, const char *role, size_t role_len, const char *accessibility_label, size_t accessibility_label_len, const char *text, size_t text_len, const char *command, size_t command_len) {
5598
5710
  if (!host || label_len == 0 || !isSupportedNativeViewKind(kind) || !validNativeViewFrame(x, y, width, height)) return 0;
5599
5711
  auto window = host->windows.find(window_id);
@@ -5740,7 +5852,7 @@ int native_sdk_windows_request_gpu_surface_frame(Host *host, uint64_t window_id,
5740
5852
  * frame-event scheduler: repaint retained content and arm the next
5741
5853
  * grid-paced emission (folding into one already in flight). */
5742
5854
  InvalidateRect(found->second.hwnd, nullptr, FALSE);
5743
- gpuSurfaceScheduleFrameEmission(found->second);
5855
+ gpuSurfaceScheduleFrameEmission(host, found->second);
5744
5856
  return 1;
5745
5857
  }
5746
5858
 
@@ -5758,7 +5870,7 @@ int native_sdk_windows_note_gpu_surface_input(Host *host, uint64_t window_id, co
5758
5870
  view.gpu_prompt_frame_pending = true;
5759
5871
  if (view.gpu_emission_scheduled) {
5760
5872
  view.gpu_emission_scheduled = false;
5761
- gpuSurfaceScheduleFrameEmission(view);
5873
+ gpuSurfaceScheduleFrameEmission(host, view);
5762
5874
  }
5763
5875
  return 1;
5764
5876
  }
@@ -5826,7 +5938,7 @@ int native_sdk_windows_present_gpu_surface_pixels(Host *host, uint64_t window_id
5826
5938
  const bool first_present = !view.gpu_presented;
5827
5939
  view.gpu_presented = true;
5828
5940
  if (first_present) view.gpu_prompt_frame_pending = true;
5829
- gpuSurfaceScheduleFrameEmission(view);
5941
+ gpuSurfaceScheduleFrameEmission(host, view);
5830
5942
  return 1;
5831
5943
  }
5832
5944
 
@@ -83,6 +83,9 @@ fn shellWindowFrom(comptime window: anytype) types.ShellWindow {
83
83
  }
84
84
  if (@hasField(@TypeOf(window), "min_width")) out.min_width = window.min_width;
85
85
  if (@hasField(@TypeOf(window), "min_height")) out.min_height = window.min_height;
86
+ if (@hasField(@TypeOf(window), "close_policy")) {
87
+ out.close_policy = enumField(types.WindowClosePolicy, window.close_policy, "close_policy");
88
+ }
86
89
  if (@hasField(@TypeOf(window), "views")) {
87
90
  var views: []const types.ShellView = &.{};
88
91
  for (window.views) |view| {
@@ -210,6 +213,7 @@ test "shellConfigFrom converts a zon-shaped scene" {
210
213
  .height = 320,
211
214
  .restore_state = false,
212
215
  .restore_policy = "center_on_primary",
216
+ .close_policy = "hide",
213
217
  .views = .{
214
218
  .{ .label = "main-canvas", .kind = "gpu_surface", .fill = true, .gpu_backend = "metal", .gpu_vsync = true },
215
219
  },
@@ -223,6 +227,7 @@ test "shellConfigFrom converts a zon-shaped scene" {
223
227
  try std.testing.expectEqualStrings("Demo", scene.windows[0].title.?);
224
228
  try std.testing.expectEqual(@as(f32, 480), scene.windows[0].width);
225
229
  try std.testing.expectEqual(types.WindowRestorePolicy.center_on_primary, scene.windows[0].restore_policy);
230
+ try std.testing.expectEqual(types.WindowClosePolicy.hide, scene.windows[0].close_policy);
226
231
  try std.testing.expectEqual(@as(usize, 1), scene.windows[0].views.len);
227
232
  try std.testing.expectEqual(types.ViewKind.gpu_surface, scene.windows[0].views[0].kind);
228
233
  try std.testing.expectEqual(types.GpuSurfaceBackend.metal, scene.windows[0].views[0].gpu_backend.?);
@@ -52,6 +52,7 @@ pub const FrontendDevConfig = types.FrontendDevConfig;
52
52
  pub const FrontendConfig = types.FrontendConfig;
53
53
  pub const WindowRestorePolicy = types.WindowRestorePolicy;
54
54
  pub const WindowTitlebarStyle = types.WindowTitlebarStyle;
55
+ pub const WindowClosePolicy = types.WindowClosePolicy;
55
56
  pub const Window = types.Window;
56
57
  pub const ViewKind = types.ViewKind;
57
58
  pub const GpuSurfaceBackend = types.GpuSurfaceBackend;
@@ -310,6 +310,31 @@ pub const WindowTitlebarStyle = enum {
310
310
  chromeless,
311
311
  };
312
312
 
313
+ /// What the window's CLOSE affordance (the red traffic light, cmd+W,
314
+ /// the caption X) does. `.quit` is the classic document-app default:
315
+ /// the window really closes, and closing the last one follows the
316
+ /// host's exit semantics — behavior unchanged for every app that never
317
+ /// declares the field.
318
+ ///
319
+ /// `.hide` is the menu-bar/tray-app shape: the close affordance hides
320
+ /// the window (it stays alive with its views, `WindowState.hidden`
321
+ /// flips true) and the app keeps running behind its status item — a
322
+ /// tray action's `Effects.showWindow`, or the macOS Dock reopen,
323
+ /// brings it back. Supported where the host can re-show a hidden
324
+ /// window (macOS, Windows); platforms without that affordance refuse
325
+ /// the declaration loudly at create time rather than stranding a
326
+ /// hidden window.
327
+ ///
328
+ /// Room is deliberately left for a future `.event` tier — the model
329
+ /// receives the close request as a Msg and owns the consequence
330
+ /// (unsaved-changes prompts) — which is NOT implemented yet;
331
+ /// model-declared secondary windows already have that shape today via
332
+ /// `WindowDescriptor.on_close`.
333
+ pub const WindowClosePolicy = enum {
334
+ quit,
335
+ hide,
336
+ };
337
+
313
338
  pub const Window = struct {
314
339
  label: []const u8 = "main",
315
340
  title: ?[]const u8 = null,
@@ -329,6 +354,8 @@ pub const Window = struct {
329
354
  /// layout clamping/clipping panes below it. 0 = no floor.
330
355
  min_width: f32 = 0,
331
356
  min_height: f32 = 0,
357
+ /// What the user's close affordance does — see `WindowClosePolicy`.
358
+ close_policy: WindowClosePolicy = .quit,
332
359
  };
333
360
 
334
361
  pub const ViewKind = enum {
@@ -459,6 +486,11 @@ pub const ShellWindow = struct {
459
486
  /// runtime-created windows apply their own declaration at create.
460
487
  min_width: f32 = 0,
461
488
  min_height: f32 = 0,
489
+ /// What the user's close affordance does — see `WindowClosePolicy`.
490
+ /// Like `titlebar`, close handling is host window state: the
491
+ /// STARTUP window threads it through the host create, and
492
+ /// runtime-created windows apply their own declaration at create.
493
+ close_policy: WindowClosePolicy = .quit,
462
494
  views: []const ShellView = &.{},
463
495
  };
464
496
 
@@ -11,6 +11,7 @@ test {
11
11
  _ = @import("ui_markup_compiled_tests.zig");
12
12
  _ = @import("ui_markup_contract_tests.zig");
13
13
  _ = @import("ui_markup_huge_model_tests.zig");
14
+ _ = @import("ui_markup_huge_document_tests.zig");
14
15
  _ = @import("chart_tests.zig");
15
16
  _ = @import("render_tests.zig");
16
17
  _ = @import("reference_tests.zig");
@@ -96,12 +96,16 @@ fn warnTextSizeKind(kind: WidgetKind, size: canvas.WidgetSize) void {
96
96
  /// (`automate screenshot`), mobile embeds, provider-less measurement.
97
97
  /// Markup literals get the same lesson as a validation error; this
98
98
  /// diagnostic is the net for DYNAMIC strings (model-derived text
99
- /// reaches no static check) and Zig-authored literals. Logs the first
100
- /// uncovered codepoint per text run and keeps building — live macOS
101
- /// rendering falls back through CoreText, so this must never fail an
102
- /// app, and it logs at .debug (the `logAxisChildrenOverflow`
103
- /// precedent) because a .warn inside a test-built view would fail the
104
- /// whole suite for a rendering nit.
99
+ /// reaches no static check) and Zig-authored literals. The check
100
+ /// knows only bundled coverage — a builder has no view of the
101
+ /// runtime's font registry — so a run whose tokens point at a
102
+ /// registered face covering the codepoint renders real glyphs and
103
+ /// still logs here; that imprecision is one reason this logs at
104
+ /// .debug. Logs the first uncovered codepoint per text run and keeps
105
+ /// building — live macOS rendering falls back through CoreText, so
106
+ /// this must never fail an app, and .debug (the
107
+ /// `logAxisChildrenOverflow` precedent) because a .warn inside a
108
+ /// test-built view would fail the whole suite for a rendering nit.
105
109
  fn warnUncoveredText(kind: WidgetKind, text: []const u8) void {
106
110
  if (builtin.mode != .Debug) return;
107
111
  var index: usize = 0;
@@ -111,7 +115,7 @@ fn warnUncoveredText(kind: WidgetKind, text: []const u8) void {
111
115
  const codepoint = std.unicode.utf8Decode(text[index .. index + len]) catch return;
112
116
  if (codepoint >= 0x20 and codepoint != 0x7F and !font_coverage.covers(codepoint)) {
113
117
  ui_log.debug(
114
- "{s} text contains \"{s}\" (U+{X:0>4}), outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths; use a vector icon (icon option, <icon name>) or plain words",
118
+ "{s} text contains \"{s}\" (U+{X:0>4}), outside the bundled font's coverage - it renders as a tofu box on the reference/screenshot and mobile paths unless a registered font covers it; register a font (UiApp Options.fonts), use a vector icon (icon option, <icon name>), or plain words",
115
119
  .{ @tagName(kind), text[index .. index + len], codepoint },
116
120
  );
117
121
  return;