@native-sdk/cli 0.9.1 → 0.9.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.
- package/build/app.zig +26 -9
- package/build.zig +55 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/skill-data/native-ui/SKILL.md +7 -7
- package/skill-data/ts-core/SKILL.md +1 -1
- package/src/app_runner/root.zig +93 -6
- package/src/app_runner/ts_core_main.zig +4 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +192 -40
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +154 -9
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ui_app.zig +9 -3
- package/src/runtime/ui_app_tests.zig +119 -19
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/web_engine.zig +1 -1
|
@@ -4,9 +4,10 @@ const geometry = @import("geometry");
|
|
|
4
4
|
const platform_mod = @import("../root.zig");
|
|
5
5
|
const policy_values = @import("../policy_values.zig");
|
|
6
6
|
const security = @import("../../security/root.zig");
|
|
7
|
+
const canvas = @import("canvas");
|
|
7
8
|
// The packaging pipeline's one-image icon machinery: dev runs borrow its
|
|
8
9
|
// macOS mask/inset render so the Dock tile matches `native package`.
|
|
9
|
-
const app_icon =
|
|
10
|
+
const app_icon = canvas.app_icon;
|
|
10
11
|
|
|
11
12
|
pub const Error = error{
|
|
12
13
|
CallbackFailed,
|
|
@@ -153,13 +154,23 @@ const AppKitBridgeCallback = *const fn (context: ?*anyopaque, window_id: u64, we
|
|
|
153
154
|
/// anything else one dropped frame.
|
|
154
155
|
const AppKitVideoSinkPush = *const fn (context: ?*anyopaque, width: usize, height: usize, pixels: [*c]const u8, len: usize) callconv(.c) c_int;
|
|
155
156
|
|
|
157
|
+
extern fn native_sdk_test_imageio_thumbnail_dimensions(
|
|
158
|
+
bytes: [*]const u8,
|
|
159
|
+
bytes_len: usize,
|
|
160
|
+
source_width: usize,
|
|
161
|
+
source_height: usize,
|
|
162
|
+
max_pixels: usize,
|
|
163
|
+
out_width: *usize,
|
|
164
|
+
out_height: *usize,
|
|
165
|
+
) c_int;
|
|
166
|
+
|
|
156
167
|
const shortcut_modifier_primary: u32 = 1 << 0;
|
|
157
168
|
const shortcut_modifier_command: u32 = 1 << 1;
|
|
158
169
|
const shortcut_modifier_control: u32 = 1 << 2;
|
|
159
170
|
const shortcut_modifier_option: u32 = 1 << 3;
|
|
160
171
|
const shortcut_modifier_shift: u32 = 1 << 4;
|
|
161
172
|
|
|
162
|
-
extern fn native_sdk_appkit_create(app_name: [*]const u8, app_name_len: usize, display_name: [*]const u8, display_name_len: usize, version: [*]const u8, version_len: usize, about_description: [*]const u8, about_description_len: usize, has_web_content: c_int, 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, show_policy: c_int, window_flags: u32) ?*AppKitHost;
|
|
173
|
+
extern fn native_sdk_appkit_create(app_name: [*]const u8, app_name_len: usize, display_name: [*]const u8, display_name_len: usize, version: [*]const u8, version_len: usize, about_description: [*]const u8, about_description_len: usize, has_web_content: c_int, dock_visible: c_int, 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, initial_placement: c_int, restore_policy: c_int, resizable: c_int, titlebar_style: c_int, show_policy: c_int, window_flags: u32) ?*AppKitHost;
|
|
163
174
|
extern fn native_sdk_appkit_destroy(host: *AppKitHost) void;
|
|
164
175
|
extern fn native_sdk_appkit_set_dock_icon_rgba(host: *AppKitHost, pixels: [*]const u8, width: usize, height: usize) void;
|
|
165
176
|
extern fn native_sdk_appkit_set_dock_icon_file(host: *AppKitHost, path: [*]const u8, path_len: usize) void;
|
|
@@ -177,7 +188,7 @@ extern fn native_sdk_appkit_set_security_policy(host: *AppKitHost, allowed_origi
|
|
|
177
188
|
extern fn native_sdk_appkit_set_menus(host: *AppKitHost, 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;
|
|
178
189
|
extern fn native_sdk_appkit_set_shortcuts(host: *AppKitHost, ids: [*]const [*]const u8, id_lens: [*]const usize, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) void;
|
|
179
190
|
extern fn native_sdk_appkit_request_frame(host: *AppKitHost) void;
|
|
180
|
-
extern fn native_sdk_appkit_create_window(host: *AppKitHost, 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, show_policy: c_int, window_flags: u32) c_int;
|
|
191
|
+
extern fn native_sdk_appkit_create_window(host: *AppKitHost, 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, initial_placement: c_int, restore_policy: c_int, resizable: c_int, titlebar_style: c_int, show_policy: c_int, window_flags: u32) c_int;
|
|
181
192
|
extern fn native_sdk_appkit_set_window_content_min_size(host: *AppKitHost, window_id: u64, min_width: f64, min_height: f64) c_int;
|
|
182
193
|
extern fn native_sdk_appkit_focus_window(host: *AppKitHost, window_id: u64) c_int;
|
|
183
194
|
extern fn native_sdk_appkit_close_window(host: *AppKitHost, window_id: u64) c_int;
|
|
@@ -244,7 +255,7 @@ extern fn native_sdk_appkit_measure_text_advances(font_id: u64, size: f64, text:
|
|
|
244
255
|
extern fn native_sdk_appkit_register_font(font_id: u64, bytes: [*]const u8, bytes_len: usize, out_token: *u64) c_int;
|
|
245
256
|
extern fn native_sdk_appkit_unregister_font(font_id: u64, token: u64) c_int;
|
|
246
257
|
extern fn native_sdk_appkit_register_bundled_fonts() void;
|
|
247
|
-
extern fn native_sdk_appkit_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, out_width: *usize, out_height: *usize) c_int;
|
|
258
|
+
extern fn native_sdk_appkit_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, max_pixels: usize, out_width: *usize, out_height: *usize) c_int;
|
|
248
259
|
extern fn native_sdk_appkit_clipboard_write(host: *AppKitHost, text: [*]const u8, text_len: usize) void;
|
|
249
260
|
extern fn native_sdk_appkit_clipboard_read_data(host: *AppKitHost, mime_type: [*]const u8, mime_type_len: usize, buffer: [*]u8, buffer_len: usize) usize;
|
|
250
261
|
extern fn native_sdk_appkit_clipboard_write_data(host: *AppKitHost, mime_type: [*]const u8, mime_type_len: usize, bytes: [*]const u8, bytes_len: usize) c_int;
|
|
@@ -337,6 +348,7 @@ const AppKitMessageDialogOpts = extern struct {
|
|
|
337
348
|
|
|
338
349
|
const AppKitWidgetAccessibilityNode = extern struct {
|
|
339
350
|
id: u64,
|
|
351
|
+
parent_id: u64,
|
|
340
352
|
role: c_int,
|
|
341
353
|
label: [*]const u8,
|
|
342
354
|
label_len: usize,
|
|
@@ -628,7 +640,7 @@ pub const MacPlatform = struct {
|
|
|
628
640
|
// the classic load byte-for-byte.
|
|
629
641
|
const dock_icon = planDockIcon(app_info.icon_path);
|
|
630
642
|
const icon_path = if (dock_icon == .host_file) app_info.icon_path else "";
|
|
631
|
-
const host = native_sdk_appkit_create(app_info.app_name.ptr, app_info.app_name.len, display_name.ptr, display_name.len, app_info.version.ptr, app_info.version.len, app_info.description.ptr, app_info.description.len, if (app_info.has_web_content) 1 else 0, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, icon_path.ptr, 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), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
|
|
643
|
+
const host = native_sdk_appkit_create(app_info.app_name.ptr, app_info.app_name.len, display_name.ptr, display_name.len, app_info.version.ptr, app_info.version.len, app_info.description.ptr, app_info.description.len, if (app_info.has_web_content) 1 else 0, if (app_info.dock_visible) 1 else 0, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, icon_path.ptr, 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, initialPlacementInt(window_options.initial_placement), restorePolicyInt(window_options.restore_policy), if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), showModeInt(window_options.show), windowFlags(window_options)) orelse return error.CreateFailed;
|
|
632
644
|
switch (dock_icon) {
|
|
633
645
|
.host_file => {},
|
|
634
646
|
.masked_render => spawnDevDockIconRender(host, app_info.icon_path),
|
|
@@ -1179,17 +1191,89 @@ fn measureTextAdvances(context: ?*anyopaque, font_id: u64, size: f32, text: []co
|
|
|
1179
1191
|
|
|
1180
1192
|
/// System image decoding (ImageIO raster codecs plus NSImage's SVG
|
|
1181
1193
|
/// rasterizer) into straight-alpha RGBA8.
|
|
1182
|
-
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
|
|
1194
|
+
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!platform_mod.DecodedImage {
|
|
1183
1195
|
_ = context;
|
|
1184
1196
|
var width: usize = 0;
|
|
1185
1197
|
var height: usize = 0;
|
|
1186
|
-
return switch (native_sdk_appkit_decode_image(bytes.ptr, bytes.len, buffer.ptr, buffer.len, &width, &height)) {
|
|
1198
|
+
return switch (native_sdk_appkit_decode_image(bytes.ptr, bytes.len, buffer.ptr, buffer.len, max_pixels, &width, &height)) {
|
|
1187
1199
|
1 => .{ .width = width, .height = height, .rgba8 = buffer[0 .. width * height * 4] },
|
|
1188
1200
|
-1 => error.ImageTooLarge,
|
|
1189
1201
|
else => error.ImageDecodeFailed,
|
|
1190
1202
|
};
|
|
1191
1203
|
}
|
|
1192
1204
|
|
|
1205
|
+
test "mac image decoder keeps ImageIO thumbnail rounding inside the pixel cap" {
|
|
1206
|
+
// The Objective-C probe is compiled and linked only for macOS test
|
|
1207
|
+
// artifacts (build.zig's target-gated image_fit_test.m source). Keep
|
|
1208
|
+
// every other host from referencing its symbol at link time.
|
|
1209
|
+
if (comptime builtin.os.tag != .macos) return error.SkipZigTest;
|
|
1210
|
+
|
|
1211
|
+
// ImageIO derives the minor dimension from ThumbnailMaxPixelSize and
|
|
1212
|
+
// rounds it. 537x503 at the default 262,144-pixel target used to ask
|
|
1213
|
+
// for a 529px major side and return 529x496 = 262,384 pixels, which
|
|
1214
|
+
// the runtime correctly rejected as ImageTooLarge. The host must leave
|
|
1215
|
+
// enough headroom for that platform rounding before it asks ImageIO.
|
|
1216
|
+
const source_width: usize = 537;
|
|
1217
|
+
const source_height: usize = 503;
|
|
1218
|
+
const source_pixels = try std.testing.allocator.alloc(u8, source_width * source_height * 4);
|
|
1219
|
+
defer std.testing.allocator.free(source_pixels);
|
|
1220
|
+
var offset: usize = 0;
|
|
1221
|
+
while (offset < source_pixels.len) : (offset += 4) {
|
|
1222
|
+
source_pixels[offset..][0..4].* = .{ 23, 91, 177, 255 };
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const encoded_len = try canvas.png.encodedRgba8ByteLen(source_width, source_height);
|
|
1226
|
+
const encoded = try std.testing.allocator.alloc(u8, encoded_len);
|
|
1227
|
+
defer std.testing.allocator.free(encoded);
|
|
1228
|
+
var writer = std.Io.Writer.fixed(encoded);
|
|
1229
|
+
try canvas.png.writeRgba8(&writer, source_width, source_height, source_pixels);
|
|
1230
|
+
|
|
1231
|
+
const max_pixels: usize = 512 * 512;
|
|
1232
|
+
var decoded_width: usize = 0;
|
|
1233
|
+
var decoded_height: usize = 0;
|
|
1234
|
+
try std.testing.expectEqual(@as(c_int, 1), native_sdk_test_imageio_thumbnail_dimensions(
|
|
1235
|
+
writer.buffered().ptr,
|
|
1236
|
+
writer.buffered().len,
|
|
1237
|
+
source_width,
|
|
1238
|
+
source_height,
|
|
1239
|
+
max_pixels,
|
|
1240
|
+
&decoded_width,
|
|
1241
|
+
&decoded_height,
|
|
1242
|
+
));
|
|
1243
|
+
try std.testing.expect(decoded_width > 0 and decoded_height > 0);
|
|
1244
|
+
try std.testing.expect(decoded_width * decoded_height <= max_pixels);
|
|
1245
|
+
|
|
1246
|
+
// A source panorama may exceed the decoded-axis ceiling. The host must
|
|
1247
|
+
// request a bounded thumbnail instead of rejecting the source metadata.
|
|
1248
|
+
const panorama_width = platform_mod.max_decoded_image_dimension + 1;
|
|
1249
|
+
const panorama_pixels = try std.testing.allocator.alloc(u8, panorama_width * 4);
|
|
1250
|
+
defer std.testing.allocator.free(panorama_pixels);
|
|
1251
|
+
offset = 0;
|
|
1252
|
+
while (offset < panorama_pixels.len) : (offset += 4) {
|
|
1253
|
+
panorama_pixels[offset..][0..4].* = .{ 47, 113, 191, 255 };
|
|
1254
|
+
}
|
|
1255
|
+
const panorama_encoded_len = try canvas.png.encodedRgba8ByteLen(panorama_width, 1);
|
|
1256
|
+
const panorama_encoded = try std.testing.allocator.alloc(u8, panorama_encoded_len);
|
|
1257
|
+
defer std.testing.allocator.free(panorama_encoded);
|
|
1258
|
+
var panorama_writer = std.Io.Writer.fixed(panorama_encoded);
|
|
1259
|
+
try canvas.png.writeRgba8(&panorama_writer, panorama_width, 1, panorama_pixels);
|
|
1260
|
+
|
|
1261
|
+
decoded_width = 0;
|
|
1262
|
+
decoded_height = 0;
|
|
1263
|
+
try std.testing.expectEqual(@as(c_int, 1), native_sdk_test_imageio_thumbnail_dimensions(
|
|
1264
|
+
panorama_writer.buffered().ptr,
|
|
1265
|
+
panorama_writer.buffered().len,
|
|
1266
|
+
panorama_width,
|
|
1267
|
+
1,
|
|
1268
|
+
max_pixels,
|
|
1269
|
+
&decoded_width,
|
|
1270
|
+
&decoded_height,
|
|
1271
|
+
));
|
|
1272
|
+
try std.testing.expect(decoded_width <= platform_mod.max_decoded_image_dimension);
|
|
1273
|
+
try std.testing.expect(decoded_height > 0);
|
|
1274
|
+
try std.testing.expect(decoded_width * decoded_height <= max_pixels);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1193
1277
|
fn writeClipboard(context: ?*anyopaque, text: []const u8) anyerror!void {
|
|
1194
1278
|
const self: *MacPlatform = @ptrCast(@alignCast(context.?));
|
|
1195
1279
|
native_sdk_appkit_clipboard_write(self.host, text.ptr, text.len);
|
|
@@ -1263,6 +1347,21 @@ fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
|
|
|
1263
1347
|
};
|
|
1264
1348
|
}
|
|
1265
1349
|
|
|
1350
|
+
fn initialPlacementInt(placement: platform_mod.WindowInitialPlacement) c_int {
|
|
1351
|
+
return switch (placement) {
|
|
1352
|
+
.restored => 0,
|
|
1353
|
+
.explicit => 1,
|
|
1354
|
+
.default => 2,
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
fn restorePolicyInt(policy: platform_mod.WindowRestorePolicy) c_int {
|
|
1359
|
+
return switch (policy) {
|
|
1360
|
+
.clamp_to_visible_screen => 0,
|
|
1361
|
+
.center_on_primary => 1,
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1266
1365
|
fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
|
|
1267
1366
|
return switch (mode) {
|
|
1268
1367
|
.immediate => 0,
|
|
@@ -1317,13 +1416,16 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
|
|
|
1317
1416
|
try refuseUnsupportedTransparentWindow(self.web_engine, options);
|
|
1318
1417
|
const title = options.resolvedTitle(self.app_info.app_name);
|
|
1319
1418
|
const frame = options.default_frame;
|
|
1320
|
-
if (native_sdk_appkit_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), showModeInt(options.show), windowFlags(options)) == 0) return error.CreateFailed;
|
|
1419
|
+
if (native_sdk_appkit_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, initialPlacementInt(options.initial_placement), restorePolicyInt(options.restore_policy), if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), showModeInt(options.show), windowFlags(options)) == 0) return error.CreateFailed;
|
|
1321
1420
|
applyWindowContentMinSize(self.host, options.id, options.min_width, options.min_height);
|
|
1322
1421
|
applyWindowClosePolicy(self.host, options.id, options.close_policy);
|
|
1323
1422
|
return .{
|
|
1324
1423
|
.id = options.id,
|
|
1325
1424
|
.label = options.label,
|
|
1326
1425
|
.title = title,
|
|
1426
|
+
// Placement can alter the origin synchronously in AppKit; the host's
|
|
1427
|
+
// window_frame_changed event reports that actual frame immediately
|
|
1428
|
+
// after startup/create and replaces this requested-frame placeholder.
|
|
1327
1429
|
.frame = frame,
|
|
1328
1430
|
.scale_factor = 1,
|
|
1329
1431
|
.open = true,
|
|
@@ -1984,6 +2086,7 @@ fn updateWidgetAccessibility(context: ?*anyopaque, snapshot: platform_mod.Widget
|
|
|
1984
2086
|
for (snapshot.nodes, 0..) |node, index| {
|
|
1985
2087
|
nodes[index] = .{
|
|
1986
2088
|
.id = node.id,
|
|
2089
|
+
.parent_id = node.parent_id orelse 0,
|
|
1987
2090
|
.role = @intFromEnum(node.role),
|
|
1988
2091
|
.label = node.label.ptr,
|
|
1989
2092
|
.label_len = node.label.len,
|
|
@@ -2745,7 +2848,9 @@ test "mac unrestored secondary windows cascade within the active screen" {
|
|
|
2745
2848
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;") != null);
|
|
2746
2849
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMinX(referenceFrame) + 24.0") != null);
|
|
2747
2850
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMaxY(referenceFrame) - 24.0") != null);
|
|
2748
|
-
|
|
2851
|
+
// Only fresh/default windows under the default clamp policy cascade.
|
|
2852
|
+
// center_on_primary deliberately keeps the preceding center placement.
|
|
2853
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "if (initialPlacement == 2 && restorePolicy == 0 && !makeMain && referenceWindow)") != null);
|
|
2749
2854
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSRect visibleFrame = referenceScreen.visibleFrame;") != null);
|
|
2750
2855
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMaxX(visibleFrame) - NSWidth(cascadedFrame)") != null);
|
|
2751
2856
|
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMaxY(visibleFrame) - NSHeight(cascadedFrame)") != null);
|
|
@@ -2753,6 +2858,29 @@ test "mac unrestored secondary windows cascade within the active screen" {
|
|
|
2753
2858
|
}
|
|
2754
2859
|
}
|
|
2755
2860
|
|
|
2861
|
+
test "both mac hosts distinguish restored explicit and default placement" {
|
|
2862
|
+
for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
|
|
2863
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "const BOOL restoredPlacement = initialPlacement == 0") != null);
|
|
2864
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "initialPlacement == 2 || (restoredPlacement && restorePolicy == 1)") != null);
|
|
2865
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "NativeSdkConstrainFrameToScreen(NSMakeRect(0, 0, width, height), primaryScreen)") != null);
|
|
2866
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "NativeSdkConstrainFrame(NSMakeRect(x, y, width, height))") != null);
|
|
2867
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "return [NSScreen screens].firstObject ?: [NSScreen mainScreen]") != null);
|
|
2868
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "[window frameRectForContentRect:restoredContentFrame]") != null);
|
|
2869
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "[window setFrame:restoredWindowFrame display:NO]") != null);
|
|
2870
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "[window setFrame:NativeSdkCenterFrameOnScreen(window.frame, primaryScreen) display:NO]") != null);
|
|
2871
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "initialPlacement == 2 && restorePolicy == 0 && !makeMain && referenceWindow") != null);
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
test "both mac hosts preserve valid secondary-display frames" {
|
|
2876
|
+
for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
|
|
2877
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "static NSScreen *NativeSdkScreenForFrame(NSRect frame)") != null);
|
|
2878
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSArray<NSScreen *> *screens = [NSScreen screens]") != null);
|
|
2879
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "NSIntersectionRect(frame, screen.visibleFrame)") != null);
|
|
2880
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "NativeSdkConstrainFrameToScreen(frame, NativeSdkScreenForFrame(frame))") != null);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2756
2884
|
test "mac explicit focus activates before making the window key" {
|
|
2757
2885
|
for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
|
|
2758
2886
|
const focus_at = std.mem.indexOf(u8, host_source, "- (void)focusWindowWithId:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
|
|
@@ -2776,6 +2904,23 @@ test "mac dock presence changes policy without activating the app" {
|
|
|
2776
2904
|
}
|
|
2777
2905
|
}
|
|
2778
2906
|
|
|
2907
|
+
test "both mac hosts apply launch dock presence before configuring the app" {
|
|
2908
|
+
for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
|
|
2909
|
+
const init_at = std.mem.indexOf(u8, host_source, "dockVisible:(BOOL)dockVisible") orelse return error.TestExpectedEqual;
|
|
2910
|
+
const init_tail = host_source[init_at..];
|
|
2911
|
+
const policy_at = std.mem.indexOf(u8, init_tail, "dockVisible ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory") orelse return error.TestExpectedEqual;
|
|
2912
|
+
const configure_at = std.mem.indexOf(u8, init_tail, "[self configureApplication]") orelse return error.TestExpectedEqual;
|
|
2913
|
+
const create_at = std.mem.indexOf(u8, init_tail, "[self createWindowWithId:1") orelse return error.TestExpectedEqual;
|
|
2914
|
+
try std.testing.expect(policy_at < configure_at);
|
|
2915
|
+
try std.testing.expect(policy_at < create_at);
|
|
2916
|
+
if (std.mem.indexOf(u8, init_tail, "ensureCefInitialized();")) |cef_init_at| {
|
|
2917
|
+
try std.testing.expect(policy_at < cef_init_at);
|
|
2918
|
+
}
|
|
2919
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "int has_web_content, int dock_visible") != null);
|
|
2920
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "dockVisible:(dock_visible != 0)") != null);
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2779
2924
|
test "mac transparent raw frames are premultiplied exactly once before Metal upload" {
|
|
2780
2925
|
const host_source = @embedFile("appkit_host.m");
|
|
2781
2926
|
const helper_at = std.mem.indexOf(
|
|
@@ -76,6 +76,7 @@ const validateMenus = types.validateMenus;
|
|
|
76
76
|
const validateMenuItem = types.validateMenuItem;
|
|
77
77
|
const isValidShortcutKey = types.isValidShortcutKey;
|
|
78
78
|
const WindowRestorePolicy = types.WindowRestorePolicy;
|
|
79
|
+
const WindowInitialPlacement = types.WindowInitialPlacement;
|
|
79
80
|
const WindowOptions = types.WindowOptions;
|
|
80
81
|
const WindowState = types.WindowState;
|
|
81
82
|
const WindowInfo = types.WindowInfo;
|
|
@@ -377,6 +378,10 @@ pub const NullPlatform = struct {
|
|
|
377
378
|
/// like `windows` — same seam-regression purpose as
|
|
378
379
|
/// `window_resizable` (the startup create used to hardcode it).
|
|
379
380
|
window_titlebar: [max_windows]WindowTitlebarStyle = [_]WindowTitlebarStyle{.standard} ** max_windows,
|
|
381
|
+
/// Captured independently from `restore_state`: persistence opt-in does
|
|
382
|
+
/// not mean a frame was actually found and restored.
|
|
383
|
+
window_placement: [max_windows]WindowInitialPlacement = [_]WindowInitialPlacement{.default} ** max_windows,
|
|
384
|
+
window_restore_policy: [max_windows]WindowRestorePolicy = [_]WindowRestorePolicy{.clamp_to_visible_screen} ** max_windows,
|
|
380
385
|
window_transparent: [max_windows]bool = [_]bool{false} ** max_windows,
|
|
381
386
|
window_always_on_top: [max_windows]bool = [_]bool{false} ** max_windows,
|
|
382
387
|
window_click_through: [max_windows]bool = [_]bool{false} ** max_windows,
|
|
@@ -802,7 +807,12 @@ pub const NullPlatform = struct {
|
|
|
802
807
|
}
|
|
803
808
|
|
|
804
809
|
pub fn initWithOptions(surface_value: Surface, web_engine: WebEngine, app_info: AppInfo) NullPlatform {
|
|
805
|
-
return .{
|
|
810
|
+
return .{
|
|
811
|
+
.surface_value = surface_value,
|
|
812
|
+
.web_engine = web_engine,
|
|
813
|
+
.app_info = app_info,
|
|
814
|
+
.dock_visible = app_info.dock_visible,
|
|
815
|
+
};
|
|
806
816
|
}
|
|
807
817
|
|
|
808
818
|
/// Heap-allocate the wrapper (process allocator) and initialize it
|
|
@@ -1152,6 +1162,8 @@ pub const NullPlatform = struct {
|
|
|
1152
1162
|
self.windows[self.window_count] = info;
|
|
1153
1163
|
self.window_resizable[self.window_count] = options.resizable;
|
|
1154
1164
|
self.window_titlebar[self.window_count] = options.titlebar;
|
|
1165
|
+
self.window_placement[self.window_count] = options.initial_placement;
|
|
1166
|
+
self.window_restore_policy[self.window_count] = options.restore_policy;
|
|
1155
1167
|
self.window_transparent[self.window_count] = options.transparent;
|
|
1156
1168
|
self.window_always_on_top[self.window_count] = options.always_on_top;
|
|
1157
1169
|
self.window_click_through[self.window_count] = options.click_through;
|
|
@@ -2415,11 +2427,11 @@ pub const NullPlatform = struct {
|
|
|
2415
2427
|
/// Deterministic decode seam for tests (see `image_decode`): parses
|
|
2416
2428
|
/// the strict PNG subset the canvas writer emits. Off by default so
|
|
2417
2429
|
/// the null platform models codec-less hosts.
|
|
2418
|
-
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!types.DecodedImage {
|
|
2430
|
+
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!types.DecodedImage {
|
|
2419
2431
|
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
2420
2432
|
if (!self.image_decode) return error.UnsupportedService;
|
|
2421
2433
|
self.image_decode_count += 1;
|
|
2422
|
-
const decoded = canvas.png.
|
|
2434
|
+
const decoded = canvas.png.decodeRgba8Fitted(bytes, buffer, max_pixels, types.max_decoded_image_dimension) catch |err| return switch (err) {
|
|
2423
2435
|
error.PngPixelBufferTooSmall => error.ImageTooLarge,
|
|
2424
2436
|
else => error.ImageDecodeFailed,
|
|
2425
2437
|
};
|
|
@@ -2957,6 +2969,8 @@ pub const NullPlatform = struct {
|
|
|
2957
2969
|
self.windows[cursor] = self.windows[cursor + 1];
|
|
2958
2970
|
self.window_resizable[cursor] = self.window_resizable[cursor + 1];
|
|
2959
2971
|
self.window_titlebar[cursor] = self.window_titlebar[cursor + 1];
|
|
2972
|
+
self.window_placement[cursor] = self.window_placement[cursor + 1];
|
|
2973
|
+
self.window_restore_policy[cursor] = self.window_restore_policy[cursor + 1];
|
|
2960
2974
|
self.window_transparent[cursor] = self.window_transparent[cursor + 1];
|
|
2961
2975
|
self.window_always_on_top[cursor] = self.window_always_on_top[cursor + 1];
|
|
2962
2976
|
self.window_click_through[cursor] = self.window_click_through[cursor + 1];
|
|
@@ -187,6 +187,59 @@ test "null platform reports hidden startup state" {
|
|
|
187
187
|
try std.testing.expectEqual(true, recorder.startup_hidden.?);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
test "null platform captures fresh restored and explicit placement independently" {
|
|
191
|
+
var null_platform = NullPlatform.init(.{});
|
|
192
|
+
const services = null_platform.platform().services;
|
|
193
|
+
|
|
194
|
+
_ = try services.createWindow(.{
|
|
195
|
+
.id = 1,
|
|
196
|
+
.label = "fresh",
|
|
197
|
+
.restore_state = true,
|
|
198
|
+
.initial_placement = .default,
|
|
199
|
+
});
|
|
200
|
+
_ = try services.createWindow(.{
|
|
201
|
+
.id = 2,
|
|
202
|
+
.label = "restored",
|
|
203
|
+
.initial_placement = .restored,
|
|
204
|
+
});
|
|
205
|
+
_ = try services.createWindow(.{
|
|
206
|
+
.id = 3,
|
|
207
|
+
.label = "explicit",
|
|
208
|
+
.default_frame = geometry.RectF.init(80, 120, 640, 480),
|
|
209
|
+
.initial_placement = .explicit,
|
|
210
|
+
.restore_policy = .center_on_primary,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
try std.testing.expectEqual(types.WindowInitialPlacement.default, null_platform.window_placement[0]);
|
|
214
|
+
try std.testing.expectEqual(types.WindowInitialPlacement.restored, null_platform.window_placement[1]);
|
|
215
|
+
try std.testing.expectEqual(types.WindowInitialPlacement.explicit, null_platform.window_placement[2]);
|
|
216
|
+
try std.testing.expectEqual(types.WindowRestorePolicy.center_on_primary, null_platform.window_restore_policy[2]);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
test "window option conversion preserves legacy nonzero origins as explicit" {
|
|
220
|
+
const runtime_options: types.WindowCreateOptions = .{
|
|
221
|
+
.default_frame = geometry.RectF.init(32, 48, 640, 480),
|
|
222
|
+
};
|
|
223
|
+
try std.testing.expectEqual(types.WindowInitialPlacement.explicit, runtime_options.windowOptions(7, "runtime").initial_placement);
|
|
224
|
+
|
|
225
|
+
const app_info: types.AppInfo = .{
|
|
226
|
+
.main_window = .{ .default_frame = geometry.RectF.init(64, 96, 720, 480) },
|
|
227
|
+
};
|
|
228
|
+
try std.testing.expectEqual(types.WindowInitialPlacement.explicit, app_info.resolvedMainWindow().initial_placement);
|
|
229
|
+
try std.testing.expectEqual(types.WindowInitialPlacement.explicit, app_info.resolvedStartupWindow(0).initial_placement);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
test "null platform records accessory launch presence from app info" {
|
|
233
|
+
const null_platform = NullPlatform.initWithOptions(.{}, .system, .{
|
|
234
|
+
.app_name = "Menu Bar",
|
|
235
|
+
.dock_visible = false,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
try std.testing.expect(!null_platform.app_info.dock_visible);
|
|
239
|
+
try std.testing.expect(!null_platform.dock_visible);
|
|
240
|
+
try std.testing.expectEqual(@as(u32, 0), null_platform.dock_presence_count);
|
|
241
|
+
}
|
|
242
|
+
|
|
190
243
|
test "null platform focus reveals a hidden window" {
|
|
191
244
|
var null_platform = NullPlatform.init(.{});
|
|
192
245
|
const services = null_platform.platform().services;
|
|
@@ -720,10 +773,11 @@ test "gpu surface image upload bounds are honest per id namespace" {
|
|
|
720
773
|
defer std.testing.allocator.free(buffer);
|
|
721
774
|
@memset(buffer, 128);
|
|
722
775
|
|
|
723
|
-
// Ordinary registered-image ids
|
|
724
|
-
//
|
|
725
|
-
// an engine bug and refuses loudly.
|
|
726
|
-
|
|
776
|
+
// Ordinary registered-image ids accept the registry's configurable
|
|
777
|
+
// ceiling: exactly 8 MiB (2048x1024 RGBA8) passes, one pixel past it
|
|
778
|
+
// is an engine bug and refuses loudly. Apps on the default 1 MiB tier
|
|
779
|
+
// still refuse earlier, at registration.
|
|
780
|
+
try services.uploadGpuSurfaceImage(.{ .id = 7, .width = 2048, .height = 1024, .rgba8 = buffer[0..types.max_gpu_surface_image_pixel_bytes] });
|
|
727
781
|
try std.testing.expectError(error.InvalidGpuSurfaceImage, services.uploadGpuSurfaceImage(.{
|
|
728
782
|
.id = 7,
|
|
729
783
|
.width = types.max_gpu_surface_image_pixel_bytes / 4 + 1,
|
package/src/platform/root.zig
CHANGED
|
@@ -66,6 +66,7 @@ pub const max_widget_accessibility_nodes = types.max_widget_accessibility_nodes;
|
|
|
66
66
|
pub const max_gpu_surface_packet_json_bytes = types.max_gpu_surface_packet_json_bytes;
|
|
67
67
|
pub const max_gpu_surface_packet_binary_bytes = types.max_gpu_surface_packet_binary_bytes;
|
|
68
68
|
pub const max_gpu_present_fallback_detail_bytes = types.max_gpu_present_fallback_detail_bytes;
|
|
69
|
+
pub const max_decoded_image_dimension = types.max_decoded_image_dimension;
|
|
69
70
|
pub const max_gpu_surface_image_pixel_bytes = types.max_gpu_surface_image_pixel_bytes;
|
|
70
71
|
pub const max_gpu_surface_media_image_pixel_bytes = types.max_gpu_surface_media_image_pixel_bytes;
|
|
71
72
|
pub const max_gpu_surface_font_bytes = types.max_gpu_surface_font_bytes;
|
|
@@ -80,6 +81,7 @@ pub const validateMenuItem = types.validateMenuItem;
|
|
|
80
81
|
pub const isValidShortcutKey = types.isValidShortcutKey;
|
|
81
82
|
pub const isValidShortcutBinding = types.isValidShortcutBinding;
|
|
82
83
|
pub const WindowRestorePolicy = types.WindowRestorePolicy;
|
|
84
|
+
pub const WindowInitialPlacement = types.WindowInitialPlacement;
|
|
83
85
|
pub const WindowTitlebarStyle = types.WindowTitlebarStyle;
|
|
84
86
|
pub const WindowChrome = types.WindowChrome;
|
|
85
87
|
pub const FormFactor = types.FormFactor;
|
package/src/platform/types.zig
CHANGED
|
@@ -303,14 +303,20 @@ pub const max_gpu_surface_packet_binary_bytes: usize = 512 * 1024;
|
|
|
303
303
|
/// packet present falls back because a command is not representable
|
|
304
304
|
/// (fits every `CanvasCommand` tag name).
|
|
305
305
|
pub const max_gpu_present_fallback_detail_bytes: usize = 32;
|
|
306
|
+
/// Longest decoded-image side accepted by the registered-image codec seam.
|
|
307
|
+
/// Source metadata may exceed this: conforming platform codecs combine this
|
|
308
|
+
/// axis ceiling with the caller's `max_pixels` area target and downsample
|
|
309
|
+
/// during decode. Keeping the decoded side bounded protects codec and GPU
|
|
310
|
+
/// upload paths from pathological panoramas without refusing them outright.
|
|
311
|
+
pub const max_decoded_image_dimension: usize = 8192;
|
|
306
312
|
/// Per-image bound for the binary gpu-surface image upload side-channel;
|
|
307
|
-
/// matches the runtime registry's
|
|
308
|
-
/// (`canvas_limits.
|
|
309
|
-
/// ORDINARY registered-image ids only: the
|
|
310
|
-
///
|
|
311
|
-
///
|
|
312
|
-
/// copied into host allocations.
|
|
313
|
-
pub const max_gpu_surface_image_pixel_bytes: usize = 1024 * 1024;
|
|
313
|
+
/// matches the runtime registry's app-configurable ceiling
|
|
314
|
+
/// (`canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling`).
|
|
315
|
+
/// Applies to ORDINARY registered-image ids only: the runtime's frozen
|
|
316
|
+
/// app budget may be lower, but anything it accepts must remain uploadable
|
|
317
|
+
/// on packet hosts. An upload past the SDK ceiling is still an engine bug
|
|
318
|
+
/// and is refused loudly rather than copied into host allocations.
|
|
319
|
+
pub const max_gpu_surface_image_pixel_bytes: usize = 8 * 1024 * 1024;
|
|
314
320
|
/// Per-image bound for uploads in the media-surface texture namespace
|
|
315
321
|
/// (ids with `canvas.media_surface_image_id_bit` set — producer-pushed
|
|
316
322
|
/// dynamic textures, structurally disjoint from registered-image ids):
|
|
@@ -464,6 +470,16 @@ pub const WindowRestorePolicy = enum {
|
|
|
464
470
|
center_on_primary,
|
|
465
471
|
};
|
|
466
472
|
|
|
473
|
+
/// Why the host is receiving the window's initial frame. Persistence policy
|
|
474
|
+
/// (`restore_state`) is deliberately separate: only the state-store loader can
|
|
475
|
+
/// say `.restored`, while an authored x/y origin says `.explicit`; every other
|
|
476
|
+
/// fresh window uses `.default` platform placement.
|
|
477
|
+
pub const WindowInitialPlacement = enum {
|
|
478
|
+
restored,
|
|
479
|
+
explicit,
|
|
480
|
+
default,
|
|
481
|
+
};
|
|
482
|
+
|
|
467
483
|
/// How the window draws its titlebar chrome.
|
|
468
484
|
/// `.hidden_inset` is the modern editor-app shape: content extends under a
|
|
469
485
|
/// transparent titlebar with the title hidden (macOS:
|
|
@@ -621,6 +637,7 @@ pub const WindowOptions = struct {
|
|
|
621
637
|
resizable: bool = true,
|
|
622
638
|
restore_state: bool = true,
|
|
623
639
|
restore_policy: WindowRestorePolicy = .clamp_to_visible_screen,
|
|
640
|
+
initial_placement: WindowInitialPlacement = .default,
|
|
624
641
|
titlebar: WindowTitlebarStyle = .standard,
|
|
625
642
|
show: WindowShowMode = .immediate,
|
|
626
643
|
/// Make the top-level window and its rendering surface alpha-capable.
|
|
@@ -715,6 +732,7 @@ pub const WindowCreateOptions = struct {
|
|
|
715
732
|
resizable: bool = true,
|
|
716
733
|
restore_state: bool = true,
|
|
717
734
|
restore_policy: WindowRestorePolicy = .clamp_to_visible_screen,
|
|
735
|
+
initial_placement: WindowInitialPlacement = .default,
|
|
718
736
|
titlebar: WindowTitlebarStyle = .standard,
|
|
719
737
|
show: WindowShowMode = .immediate,
|
|
720
738
|
transparent: bool = false,
|
|
@@ -739,6 +757,15 @@ pub const WindowCreateOptions = struct {
|
|
|
739
757
|
.resizable = self.resizable,
|
|
740
758
|
.restore_state = self.restore_state,
|
|
741
759
|
.restore_policy = self.restore_policy,
|
|
760
|
+
// Preserve the historical direct-runtime shape where a non-zero
|
|
761
|
+
// `default_frame` origin meant explicit placement. Callers that
|
|
762
|
+
// intentionally need the visible-screen origin can state
|
|
763
|
+
// `.explicit`; optional-origin APIs already do so even at 0,0.
|
|
764
|
+
.initial_placement = if (self.initial_placement == .default and
|
|
765
|
+
(self.default_frame.x != 0 or self.default_frame.y != 0))
|
|
766
|
+
.explicit
|
|
767
|
+
else
|
|
768
|
+
self.initial_placement,
|
|
742
769
|
.titlebar = self.titlebar,
|
|
743
770
|
.show = self.show,
|
|
744
771
|
.transparent = self.transparent,
|
|
@@ -1263,9 +1290,14 @@ pub const AppInfo = struct {
|
|
|
1263
1290
|
/// built-in re-show affordance: hiding a window on windows removes
|
|
1264
1291
|
/// its taskbar entry and windows has no dock-reopen path, so only a
|
|
1265
1292
|
/// tray icon can bring the hidden window back. The Windows host
|
|
1266
|
-
/// folds this into its `window_hide_on_close` answer
|
|
1267
|
-
///
|
|
1293
|
+
/// folds this into its `window_hide_on_close` answer. On macOS the
|
|
1294
|
+
/// Dock is a reopen path only while `dock_visible` is true; manifest
|
|
1295
|
+
/// validation therefore requires a tray for accessory startup.
|
|
1268
1296
|
declares_tray: bool = false,
|
|
1297
|
+
/// Initial Dock/app-switcher presence. The macOS hosts translate
|
|
1298
|
+
/// false to Accessory before configuring the app or creating its
|
|
1299
|
+
/// startup window; `setDockPresence` can change it later.
|
|
1300
|
+
dock_visible: bool = true,
|
|
1269
1301
|
window_title: []const u8 = "",
|
|
1270
1302
|
bundle_id: []const u8 = "dev.native_sdk.app",
|
|
1271
1303
|
icon_path: []const u8 = "",
|
|
@@ -1289,6 +1321,7 @@ pub const AppInfo = struct {
|
|
|
1289
1321
|
pub fn resolvedMainWindow(self: AppInfo) WindowOptions {
|
|
1290
1322
|
var window = self.main_window;
|
|
1291
1323
|
if (window.title.len == 0) window.title = self.resolvedWindowTitle();
|
|
1324
|
+
inferLegacyExplicitOrigin(&window);
|
|
1292
1325
|
return window;
|
|
1293
1326
|
}
|
|
1294
1327
|
|
|
@@ -1303,8 +1336,17 @@ pub const AppInfo = struct {
|
|
|
1303
1336
|
}
|
|
1304
1337
|
if (window.label.len == 0) window.label = if (index == 0) "main" else "window";
|
|
1305
1338
|
if (window.title.len == 0) window.title = self.resolvedWindowTitle();
|
|
1339
|
+
inferLegacyExplicitOrigin(&window);
|
|
1306
1340
|
return window;
|
|
1307
1341
|
}
|
|
1342
|
+
|
|
1343
|
+
fn inferLegacyExplicitOrigin(window: *WindowOptions) void {
|
|
1344
|
+
if (window.initial_placement == .default and
|
|
1345
|
+
(window.default_frame.x != 0 or window.default_frame.y != 0))
|
|
1346
|
+
{
|
|
1347
|
+
window.initial_placement = .explicit;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1308
1350
|
};
|
|
1309
1351
|
|
|
1310
1352
|
pub const Surface = struct {
|
|
@@ -2348,6 +2390,7 @@ pub const WidgetAccessibilityRole = enum(c_int) {
|
|
|
2348
2390
|
slider = 18,
|
|
2349
2391
|
progressbar = 19,
|
|
2350
2392
|
radio = 20,
|
|
2393
|
+
radiogroup = 21,
|
|
2351
2394
|
};
|
|
2352
2395
|
|
|
2353
2396
|
pub const WidgetAccessibilityActions = struct {
|
|
@@ -2950,12 +2993,16 @@ pub const PlatformServices = struct {
|
|
|
2950
2993
|
/// framework bundles no image decoders: macOS decodes through
|
|
2951
2994
|
/// CGImageSource (ImageIO), GTK through gdk-pixbuf, Win32 through WIC.
|
|
2952
2995
|
/// Implementations may use `buffer` as decode scratch, so callers size
|
|
2953
|
-
/// it for their pixel bound, not the exact image.
|
|
2996
|
+
/// it for their pixel bound, not the exact image. `max_pixels` is a
|
|
2997
|
+
/// pixel-count cap, not a width/height box: codecs preserve aspect and
|
|
2998
|
+
/// decode down when source pixels exceed it or either decoded side would
|
|
2999
|
+
/// exceed `max_decoded_image_dimension`. Errors:
|
|
2954
3000
|
/// `error.ImageDecodeFailed` for undecodable bytes,
|
|
2955
|
-
/// `error.ImageTooLarge` when the
|
|
3001
|
+
/// `error.ImageTooLarge` when the fitted pixels violate either bound or
|
|
3002
|
+
/// do not fit `buffer`.
|
|
2956
3003
|
/// Null on platforms without a codec (the null platform by default),
|
|
2957
3004
|
/// which surfaces as `error.UnsupportedService`.
|
|
2958
|
-
decode_image_fn: ?*const fn (context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!DecodedImage = null,
|
|
3005
|
+
decode_image_fn: ?*const fn (context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!DecodedImage = null,
|
|
2959
3006
|
|
|
2960
3007
|
pub fn readClipboard(self: PlatformServices, buffer: []u8) anyerror![]const u8 {
|
|
2961
3008
|
const read_fn = self.read_clipboard_fn orelse return error.UnsupportedService;
|
|
@@ -3541,11 +3588,10 @@ pub const PlatformServices = struct {
|
|
|
3541
3588
|
// Two honest bounds, keyed by the id namespace: hosts copy every
|
|
3542
3589
|
// upload into host-owned allocations (AppKit's NSData + NSImage
|
|
3543
3590
|
// store), so each bound teaches the real cost of its id space.
|
|
3544
|
-
// Ordinary registered images
|
|
3545
|
-
//
|
|
3546
|
-
//
|
|
3547
|
-
//
|
|
3548
|
-
// producer staged can fail here.
|
|
3591
|
+
// Ordinary registered images use the registry's configurable
|
|
3592
|
+
// ceiling; media-surface textures (the reserved high-bit namespace)
|
|
3593
|
+
// use the producer channel's frame budget — the bound the producer
|
|
3594
|
+
// already enforced, so nothing either source accepted can fail here.
|
|
3549
3595
|
const bound = if ((image.id & canvas.media_surface_image_id_bit) != 0)
|
|
3550
3596
|
max_gpu_surface_media_image_pixel_bytes
|
|
3551
3597
|
else
|
|
@@ -3589,10 +3635,14 @@ pub const PlatformServices = struct {
|
|
|
3589
3635
|
|
|
3590
3636
|
/// Decode encoded image bytes through the platform codec into
|
|
3591
3637
|
/// straight-alpha RGBA8 (see `decode_image_fn`). Loop-thread only.
|
|
3592
|
-
pub fn decodeImage(self: PlatformServices, bytes: []const u8, buffer: []u8) anyerror!DecodedImage {
|
|
3638
|
+
pub fn decodeImage(self: PlatformServices, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!DecodedImage {
|
|
3593
3639
|
if (bytes.len == 0) return error.ImageDecodeFailed;
|
|
3640
|
+
if (max_pixels == 0) return error.ImageTooLarge;
|
|
3594
3641
|
const decode_fn = self.decode_image_fn orelse return error.UnsupportedService;
|
|
3595
|
-
|
|
3642
|
+
const decoded = try decode_fn(self.context, bytes, buffer, max_pixels);
|
|
3643
|
+
const pixels = std.math.mul(usize, decoded.width, decoded.height) catch return error.ImageTooLarge;
|
|
3644
|
+
if (decoded.width > max_decoded_image_dimension or decoded.height > max_decoded_image_dimension or pixels > max_pixels) return error.ImageTooLarge;
|
|
3645
|
+
return decoded;
|
|
3596
3646
|
}
|
|
3597
3647
|
};
|
|
3598
3648
|
|