@native-sdk/cli 0.6.1 → 0.6.2

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 (40) hide show
  1. package/native-sdk.d.ts +16 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/src/app_runner/root.zig +19 -0
  6. package/src/platform/linux/gtk_host.c +167 -8
  7. package/src/platform/linux/gtk_host.h +3 -2
  8. package/src/platform/linux/root.zig +198 -9
  9. package/src/platform/macos/appkit_host.h +2 -2
  10. package/src/platform/macos/appkit_host.m +101 -28
  11. package/src/platform/macos/cef_host.mm +46 -11
  12. package/src/platform/macos/root.zig +143 -5
  13. package/src/platform/null_platform.zig +32 -4
  14. package/src/platform/types.zig +29 -4
  15. package/src/platform/windows/root.zig +220 -10
  16. package/src/platform/windows/webview2_host.cpp +330 -31
  17. package/src/primitives/app_manifest/comptime_scene.zig +4 -0
  18. package/src/primitives/app_manifest/types.zig +16 -0
  19. package/src/primitives/canvas/widget_render.zig +21 -2
  20. package/src/primitives/canvas/widget_runtime_tests.zig +51 -0
  21. package/src/runtime/bridge_payload.zig +9 -0
  22. package/src/runtime/bridge_responses.zig +2 -0
  23. package/src/runtime/builtin_bridge.zig +10 -0
  24. package/src/runtime/canvas_widget_floating_tests.zig +3 -3
  25. package/src/runtime/effects.zig +5 -6
  26. package/src/runtime/flow.zig +45 -7
  27. package/src/runtime/gpu_surface_events.zig +8 -1
  28. package/src/runtime/runtime_event_tests.zig +9 -6
  29. package/src/runtime/shell_layout.zig +25 -11
  30. package/src/runtime/shell_layout_tests.zig +184 -0
  31. package/src/runtime/shell_view_tests.zig +9 -7
  32. package/src/runtime/state.zig +6 -0
  33. package/src/runtime/ui_app.zig +61 -14
  34. package/src/runtime/ui_app_window_tests.zig +107 -2
  35. package/src/runtime/window_command_bridge_tests.zig +82 -6
  36. package/src/runtime/window_storage.zig +14 -3
  37. package/src/runtime/window_views.zig +12 -11
  38. package/src/tooling/manifest.zig +38 -2
  39. package/src/tooling/raw_manifest.zig +8 -0
  40. package/src/tooling/templates.zig +17 -0
@@ -10,6 +10,7 @@ pub const Error = error{
10
10
  FocusFailed,
11
11
  CloseFailed,
12
12
  UnsupportedWindowClosePolicy,
13
+ UnsupportedWindowTransparency,
13
14
  };
14
15
 
15
16
  const WindowsHost = opaque {};
@@ -120,7 +121,7 @@ const shortcut_modifier_control: u32 = 1 << 2;
120
121
  const shortcut_modifier_option: u32 = 1 << 3;
121
122
  const shortcut_modifier_shift: u32 = 1 << 4;
122
123
 
123
- extern fn native_sdk_windows_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64) ?*WindowsHost;
124
+ extern fn native_sdk_windows_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) ?*WindowsHost;
124
125
  extern fn native_sdk_windows_destroy(host: *WindowsHost) void;
125
126
  extern fn native_sdk_windows_run(host: *WindowsHost, callback: WindowsCallback, context: ?*anyopaque) void;
126
127
  extern fn native_sdk_windows_stop(host: *WindowsHost) void;
@@ -128,16 +129,16 @@ extern fn native_sdk_windows_wake(host: *WindowsHost) void;
128
129
  extern fn native_sdk_windows_request_frame(host: *WindowsHost) void;
129
130
  extern fn native_sdk_windows_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, out_width: *usize, out_height: *usize) c_int;
130
131
  extern fn native_sdk_windows_load_webview(host: *WindowsHost, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
131
- extern fn native_sdk_windows_load_window_webview(host: *WindowsHost, window_id: u64, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
132
+ extern fn native_sdk_windows_load_window_webview(host: *WindowsHost, window_id: u64, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) c_int;
132
133
  extern fn native_sdk_windows_set_bridge_callback(host: *WindowsHost, callback: WindowsBridgeCallback, context: ?*anyopaque) void;
133
134
  extern fn native_sdk_windows_bridge_respond(host: *WindowsHost, response: [*]const u8, response_len: usize) void;
134
135
  extern fn native_sdk_windows_bridge_respond_window(host: *WindowsHost, window_id: u64, response: [*]const u8, response_len: usize) void;
135
136
  extern fn native_sdk_windows_bridge_respond_webview(host: *WindowsHost, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, response: [*]const u8, response_len: usize) void;
136
137
  extern fn native_sdk_windows_emit_window_event(host: *WindowsHost, window_id: u64, name: [*]const u8, name_len: usize, detail_json: [*]const u8, detail_json_len: usize) void;
137
138
  extern fn native_sdk_windows_set_security_policy(host: *WindowsHost, allowed_origins: [*]const u8, allowed_origins_len: usize, external_urls: [*]const u8, external_urls_len: usize, external_action: c_int) void;
138
- extern fn native_sdk_windows_set_menus(host: *WindowsHost, menu_titles: [*]const [*]const u8, menu_title_lens: [*]const usize, menu_count: usize, item_menu_indices: [*]const u32, item_labels: [*]const [*]const u8, item_label_lens: [*]const usize, item_commands: [*]const [*]const u8, item_command_lens: [*]const usize, item_keys: [*]const [*]const u8, item_key_lens: [*]const usize, item_modifiers: [*]const u32, item_separators: [*]const c_int, item_enabled: [*]const c_int, item_checked: [*]const c_int, item_count: usize) void;
139
+ extern fn native_sdk_windows_set_menus(host: *WindowsHost, menu_titles: [*]const [*]const u8, menu_title_lens: [*]const usize, menu_count: usize, item_menu_indices: [*]const u32, item_labels: [*]const [*]const u8, item_label_lens: [*]const usize, item_commands: [*]const [*]const u8, item_command_lens: [*]const usize, item_keys: [*]const [*]const u8, item_key_lens: [*]const usize, item_modifiers: [*]const u32, item_separators: [*]const c_int, item_enabled: [*]const c_int, item_checked: [*]const c_int, item_count: usize) c_int;
139
140
  extern fn native_sdk_windows_set_shortcuts(host: *WindowsHost, ids: [*]const [*]const u8, id_lens: [*]const usize, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) void;
140
- extern fn native_sdk_windows_create_window(host: *WindowsHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64) c_int;
141
+ extern fn native_sdk_windows_create_window(host: *WindowsHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64, show_policy: c_int, window_flags: u32) c_int;
141
142
  extern fn native_sdk_windows_start_window_drag(host: *WindowsHost, window_id: u64) c_int;
142
143
  extern fn native_sdk_windows_set_window_drag_regions(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, rects: [*]const f64, exclusions: [*]const c_int, count: usize) c_int;
143
144
  extern fn native_sdk_windows_window_chrome(host: *WindowsHost, window_id: u64, top: *f64, left: *f64, bottom: *f64, right: *f64, buttons_x: *f64, buttons_y: *f64, buttons_width: *f64, buttons_height: *f64) c_int;
@@ -261,12 +262,30 @@ fn refuseUnsupportedMainWindowClosePolicy(app_info: platform_mod.AppInfo) Error!
261
262
  return error.UnsupportedWindowClosePolicy;
262
263
  }
263
264
 
265
+ /// A Win32 per-pixel-alpha window is painted as one top-level layered
266
+ /// bitmap: child HWNDs and non-client chrome do not participate in that
267
+ /// bitmap. Canvas children are redirected explicitly by the host, but
268
+ /// standard/hidden titlebars and an HMENU would otherwise be silently
269
+ /// erased by the transparent DIB. Keep that limitation explicit at the
270
+ /// create/configure seams instead of accepting an unusable combination.
271
+ fn refuseUnsupportedTransparentWindow(options: platform_mod.WindowOptions, menus_active: bool) Error!void {
272
+ if (!options.transparent) return;
273
+ if (options.titlebar != .chromeless or menus_active) {
274
+ std.debug.print("transparent windows on windows require titlebar = \"chromeless\" and cannot be combined with application menus because Win32 layered windows cannot composite non-client chrome\n", .{});
275
+ return error.UnsupportedWindowTransparency;
276
+ }
277
+ }
278
+
264
279
  pub const WindowsPlatform = struct {
265
280
  host: *WindowsHost,
266
281
  web_engine: platform_mod.WebEngine,
267
282
  app_info: platform_mod.AppInfo,
268
283
  surface_value: platform_mod.Surface,
269
284
  state: RunState = .{},
285
+ /// Mirrors the successfully installed native menu model so a
286
+ /// later runtime-created alpha window can fail with the precise
287
+ /// transparency error before crossing the C ABI.
288
+ menus_active: bool = false,
270
289
  /// Latched when the runtime's effects teardown abandons an
271
290
  /// in-flight channel `wake_fn` call (see
272
291
  /// `PlatformServices.note_channel_wake_abandoned_fn`): the stale
@@ -298,9 +317,10 @@ pub const WindowsPlatform = struct {
298
317
  // taskbar entry and windows has no dock-reopen path, so a
299
318
  // declared tray (status item) is the ONLY re-show affordance.
300
319
  try refuseUnsupportedMainWindowClosePolicy(app_info);
320
+ try refuseUnsupportedTransparentWindow(window_options, false);
301
321
  const window_title = window_options.resolvedTitle(app_info.app_name);
302
322
  const frame = window_options.default_frame;
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;
323
+ 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), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
304
324
  // The manifest's declared close policy rides right after the
305
325
  // create, like the min-size floor: close handling is host
306
326
  // window state fixed for the window's life.
@@ -758,7 +778,7 @@ fn loadWebView(context: ?*anyopaque, source: platform_mod.WebViewSource) anyerro
758
778
  fn loadWindowWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, source: platform_mod.WebViewSource) anyerror!void {
759
779
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
760
780
  const assets: platform_mod.WebViewAssetSource = source.asset_options orelse .{ .root_path = "", .entry = "", .origin = "", .spa_fallback = false };
761
- native_sdk_windows_load_window_webview(
781
+ const result = native_sdk_windows_load_window_webview(
762
782
  self.host,
763
783
  window_id,
764
784
  source.bytes.ptr,
@@ -776,6 +796,8 @@ fn loadWindowWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, sou
776
796
  assets.origin.len,
777
797
  if (assets.spa_fallback) 1 else 0,
778
798
  );
799
+ if (result < 0) return error.UnsupportedWindowTransparency;
800
+ if (result == 0) return error.CreateFailed;
779
801
  }
780
802
 
781
803
  fn completeBridge(context: ?*anyopaque, response: []const u8) anyerror!void {
@@ -856,6 +878,22 @@ fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
856
878
  };
857
879
  }
858
880
 
881
+ fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
882
+ return switch (mode) {
883
+ .immediate => 0,
884
+ .on_first_present => 1,
885
+ };
886
+ }
887
+
888
+ fn windowFlags(options: platform_mod.WindowOptions) u32 {
889
+ var flags: u32 = 0;
890
+ if (options.transparent) flags |= 1 << 0;
891
+ if (options.always_on_top) flags |= 1 << 1;
892
+ if (options.click_through) flags |= 1 << 2;
893
+ if (!options.activate_on_show) flags |= 1 << 3;
894
+ return flags;
895
+ }
896
+
859
897
  /// Zero/negative/non-finite floors are the "no floor" sentinel (the
860
898
  /// host leaves that axis at its natural minimum).
861
899
  fn closePolicyInt(policy: platform_mod.WindowClosePolicy) c_int {
@@ -878,9 +916,10 @@ fn minSizeFloor(value: f32) f64 {
878
916
 
879
917
  fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyerror!platform_mod.WindowInfo {
880
918
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
919
+ try refuseUnsupportedTransparentWindow(options, self.menus_active);
881
920
  const title = options.resolvedTitle(self.app_info.app_name);
882
921
  const frame = options.default_frame;
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;
922
+ 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), showModeInt(options.show), windowFlags(options)) == 0) return error.CreateFailed;
884
923
  applyWindowClosePolicy(self.host, options.id, options.close_policy);
885
924
  return .{
886
925
  .id = options.id,
@@ -889,7 +928,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
889
928
  .frame = frame,
890
929
  .scale_factor = 1,
891
930
  .open = true,
892
- .focused = false,
931
+ .focused = options.activate_on_show and options.show == .immediate,
893
932
  };
894
933
  }
895
934
 
@@ -1535,7 +1574,7 @@ fn configureMenus(context: ?*anyopaque, menus: []const platform_mod.Menu) anyerr
1535
1574
  }
1536
1575
  }
1537
1576
 
1538
- native_sdk_windows_set_menus(
1577
+ if (native_sdk_windows_set_menus(
1539
1578
  self.host,
1540
1579
  menu_titles[0..menus.len].ptr,
1541
1580
  menu_title_lens[0..menus.len].ptr,
@@ -1552,7 +1591,8 @@ fn configureMenus(context: ?*anyopaque, menus: []const platform_mod.Menu) anyerr
1552
1591
  item_enabled[0..item_count].ptr,
1553
1592
  item_checked[0..item_count].ptr,
1554
1593
  item_count,
1555
- );
1594
+ ) == 0) return error.UnsupportedWindowTransparency;
1595
+ self.menus_active = menus.len > 0;
1556
1596
  }
1557
1597
 
1558
1598
  fn configureShortcuts(context: ?*anyopaque, shortcuts: []const platform_mod.Shortcut) anyerror!void {
@@ -1844,6 +1884,176 @@ test "windows WM_CLOSE hide consults the live tray state and downgrades to a rea
1844
1884
  try std.testing.expect(std.mem.indexOf(u8, close_hook, "downgraded to a real close") != null);
1845
1885
  }
1846
1886
 
1887
+ test "windows passive show never foregrounds or focuses the window" {
1888
+ const host_source = @embedFile("webview2_host.cpp");
1889
+ const show_at = std.mem.indexOf(u8, host_source, "int native_sdk_windows_show_window(") orelse return error.TestExpectedEqual;
1890
+ const tail = host_source[show_at..];
1891
+ const next_at = std.mem.indexOf(u8, tail, "int native_sdk_windows_set_window_close_policy(") orelse return error.TestExpectedEqual;
1892
+ const show_fn = tail[0..next_at];
1893
+ const passive_at = std.mem.indexOf(u8, show_fn, "ShowWindow(found->second.hwnd, SW_SHOWNOACTIVATE);") orelse return error.TestExpectedEqual;
1894
+ const focused_at = std.mem.indexOf(u8, show_fn, "SetFocus(found->second.hwnd);") orelse return error.TestExpectedEqual;
1895
+ const active_branch_end = std.mem.indexOfPos(u8, show_fn, focused_at, "} else {") orelse return error.TestExpectedEqual;
1896
+ try std.testing.expect(focused_at < active_branch_end);
1897
+ try std.testing.expect(std.mem.indexOfPos(u8, show_fn, passive_at, "SetForegroundWindow(") == null);
1898
+ try std.testing.expect(std.mem.indexOfPos(u8, show_fn, passive_at, "SetFocus(") == null);
1899
+
1900
+ // Passive is a SHOW policy, not a permanent interaction policy:
1901
+ // WS_EX_NOACTIVATE would also suppress activation on a later user
1902
+ // click, making an interactive passive overlay impossible to focus.
1903
+ const style_at = std.mem.indexOf(u8, host_source, "static DWORD windowExtendedStyle(") orelse return error.TestExpectedEqual;
1904
+ const style_tail = host_source[style_at..];
1905
+ const style_end = std.mem.indexOf(u8, style_tail, "static bool createNativeWindow(") orelse return error.TestExpectedEqual;
1906
+ try std.testing.expect(std.mem.indexOf(u8, style_tail[0..style_end], "WS_EX_NOACTIVATE") == null);
1907
+ }
1908
+
1909
+ test "windows passive canvas creation does not focus its child hwnd" {
1910
+ const host_source = @embedFile("webview2_host.cpp");
1911
+ const create_at = std.mem.indexOf(u8, host_source, "int native_sdk_windows_create_view(") orelse return error.TestExpectedEqual;
1912
+ const tail = host_source[create_at..];
1913
+ const next_at = std.mem.indexOf(u8, tail, "int native_sdk_windows_request_gpu_surface_frame(") orelse return error.TestExpectedEqual;
1914
+ const create_fn = tail[0..next_at];
1915
+ try std.testing.expect(std.mem.indexOf(
1916
+ u8,
1917
+ create_fn,
1918
+ "if (window->second.activate_on_show) SetFocus(hwnd);",
1919
+ ) != null);
1920
+ }
1921
+
1922
+ test "windows click-through uses a layered surface even when visually opaque" {
1923
+ const host_source = @embedFile("webview2_host.cpp");
1924
+ try std.testing.expect(std.mem.indexOf(
1925
+ u8,
1926
+ host_source,
1927
+ "if (window.transparent || window.click_through) style |= WS_EX_LAYERED;",
1928
+ ) != null);
1929
+ try std.testing.expect(std.mem.indexOf(
1930
+ u8,
1931
+ host_source,
1932
+ "if (window.click_through && !window.transparent &&\n !SetLayeredWindowAttributes(hwnd, 0, 255, LWA_ALPHA))",
1933
+ ) != null);
1934
+ }
1935
+
1936
+ test "windows transparent windows compose canvas siblings and reject unredirectable children" {
1937
+ const host_source = @embedFile("webview2_host.cpp");
1938
+ try std.testing.expect(std.mem.indexOf(
1939
+ u8,
1940
+ host_source,
1941
+ "static bool presentTransparentWindow(Host *host, Window &window)",
1942
+ ) != null);
1943
+ try std.testing.expect(std.mem.indexOf(
1944
+ u8,
1945
+ host_source,
1946
+ "std::sort(surfaces.begin(), surfaces.end()",
1947
+ ) != null);
1948
+ try std.testing.expect(std.mem.indexOf(
1949
+ u8,
1950
+ host_source,
1951
+ "compositePremultipliedChannel(128, 128, 64) == 160",
1952
+ ) != null);
1953
+ try std.testing.expect(std.mem.indexOf(
1954
+ u8,
1955
+ host_source,
1956
+ "if (window->second.transparent && kind != kViewGpuSurface) return 0;",
1957
+ ) != null);
1958
+ try std.testing.expect(std.mem.indexOf(
1959
+ u8,
1960
+ host_source,
1961
+ "if (window->second.transparent) return 0;",
1962
+ ) != null);
1963
+ try std.testing.expect(std.mem.indexOf(
1964
+ u8,
1965
+ host_source,
1966
+ "if (window->second.transparent) return -1;",
1967
+ ) != null);
1968
+ try std.testing.expect(std.mem.indexOf(
1969
+ u8,
1970
+ host_source,
1971
+ "if (window.transparent && (!windowIsChromeless(window) || !host->menus.empty())) return false;",
1972
+ ) != null);
1973
+ try std.testing.expect(std.mem.indexOf(
1974
+ u8,
1975
+ host_source,
1976
+ "if (menu_count > 0) {\n for (const auto &entry : host->windows) {\n if (entry.second.transparent) return 0;",
1977
+ ) != null);
1978
+ }
1979
+
1980
+ test "windows transparent resize frame remains hit-testable without filling the client" {
1981
+ const host_source = @embedFile("webview2_host.cpp");
1982
+ try std.testing.expect(std.mem.indexOf(
1983
+ u8,
1984
+ host_source,
1985
+ "static constexpr uint8_t kTransparentResizeHitAlpha = 1;",
1986
+ ) != null);
1987
+ try std.testing.expect(std.mem.indexOf(
1988
+ u8,
1989
+ host_source,
1990
+ "outsideTransparentClientBounds(6, 100, 7, 7, 713, 513)",
1991
+ ) != null);
1992
+ const present_at = std.mem.indexOf(
1993
+ u8,
1994
+ host_source,
1995
+ "static bool presentTransparentWindow(Host *host, Window &window)",
1996
+ ) orelse return error.TestExpectedEqual;
1997
+ const present = host_source[present_at..];
1998
+ const seed_at = std.mem.indexOf(
1999
+ u8,
2000
+ present,
2001
+ "if (window.resizable) {\n seedTransparentResizeHitFrame(",
2002
+ ) orelse return error.TestExpectedEqual;
2003
+ const surfaces_at = std.mem.indexOf(
2004
+ u8,
2005
+ present,
2006
+ "std::vector<NativeView *> surfaces;",
2007
+ ) orelse return error.TestExpectedEqual;
2008
+ try std.testing.expect(seed_at < surfaces_at);
2009
+ try std.testing.expect(std.mem.indexOf(
2010
+ u8,
2011
+ present,
2012
+ "if (input_window && input_window->click_through && message == WM_NCHITTEST) return HTTRANSPARENT;",
2013
+ ) != null);
2014
+ }
2015
+
2016
+ test "windows transparent windows require chromeless chrome and no menus" {
2017
+ try refuseUnsupportedTransparentWindow(.{
2018
+ .titlebar = .chromeless,
2019
+ .transparent = true,
2020
+ }, false);
2021
+ try std.testing.expectError(error.UnsupportedWindowTransparency, refuseUnsupportedTransparentWindow(.{
2022
+ .titlebar = .standard,
2023
+ .transparent = true,
2024
+ }, false));
2025
+ try std.testing.expectError(error.UnsupportedWindowTransparency, refuseUnsupportedTransparentWindow(.{
2026
+ .titlebar = .hidden_inset,
2027
+ .transparent = true,
2028
+ }, false));
2029
+ try std.testing.expectError(error.UnsupportedWindowTransparency, refuseUnsupportedTransparentWindow(.{
2030
+ .titlebar = .chromeless,
2031
+ .transparent = true,
2032
+ }, true));
2033
+ // The constraint is only about per-pixel alpha: ordinary menu
2034
+ // windows keep every titlebar style.
2035
+ try refuseUnsupportedTransparentWindow(.{}, true);
2036
+ }
2037
+
2038
+ test "windows first-present windows have a fallback reveal deadline" {
2039
+ const host_source = @embedFile("webview2_host.cpp");
2040
+ try std.testing.expect(std.mem.indexOf(
2041
+ u8,
2042
+ host_source,
2043
+ "constexpr ULONGLONG kDeferredShowDeadlineMs = 1000;",
2044
+ ) != null);
2045
+ try std.testing.expect(std.mem.indexOf(
2046
+ u8,
2047
+ host_source,
2048
+ "showDeferredWindowIfDeadlinePassed(entry.second);",
2049
+ ) != null);
2050
+ try std.testing.expect(std.mem.indexOf(
2051
+ u8,
2052
+ host_source,
2053
+ "window.deferred_show_started_ms = window.show_on_first_present ? GetTickCount64() : 0;",
2054
+ ) != null);
2055
+ }
2056
+
1847
2057
  test "windows window focus includes focused native child views" {
1848
2058
  // This predicate lives in the C++ host, where the real HWND tree is
1849
2059
  // available. Pin the two parts of its contract textually: focus is