@native-sdk/cli 0.6.1 → 0.6.3
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.zig +8 -0
- package/native-sdk.d.ts +16 -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/text.ts +62 -21
- package/src/app_runner/root.zig +19 -0
- package/src/platform/linux/gtk_host.c +167 -8
- package/src/platform/linux/gtk_host.h +3 -2
- package/src/platform/linux/root.zig +198 -9
- package/src/platform/macos/appkit_host.h +4 -2
- package/src/platform/macos/appkit_host.m +137 -38
- package/src/platform/macos/cef_host.mm +46 -11
- package/src/platform/macos/root.zig +150 -6
- package/src/platform/null_platform.zig +32 -4
- package/src/platform/types.zig +31 -4
- package/src/platform/windows/root.zig +220 -10
- package/src/platform/windows/webview2_host.cpp +330 -31
- package/src/primitives/app_manifest/comptime_scene.zig +4 -0
- package/src/primitives/app_manifest/types.zig +16 -0
- package/src/primitives/canvas/equality.zig +3 -1
- package/src/primitives/canvas/events.zig +4 -0
- package/src/primitives/canvas/root.zig +11 -0
- package/src/primitives/canvas/text.zig +10 -0
- package/src/primitives/canvas/text_interaction.zig +164 -22
- package/src/primitives/canvas/text_layout.zig +107 -21
- package/src/primitives/canvas/text_tests.zig +86 -0
- package/src/primitives/canvas/ui.zig +21 -16
- package/src/primitives/canvas/ui_markup_reflect.zig +20 -3
- package/src/primitives/canvas/ui_markup_view_tests.zig +16 -0
- package/src/primitives/canvas/ui_tests.zig +6 -0
- package/src/primitives/canvas/widget_render.zig +21 -2
- package/src/primitives/canvas/widget_runtime.zig +1 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +51 -0
- package/src/primitives/canvas/widget_text_input.zig +23 -11
- package/src/runtime/api.zig +9 -0
- package/src/runtime/bridge_payload.zig +9 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +10 -0
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_limits.zig +7 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +27 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +16 -0
- package/src/runtime/canvas_widget_display.zig +15 -1
- package/src/runtime/canvas_widget_events.zig +43 -19
- package/src/runtime/canvas_widget_floating_tests.zig +3 -3
- package/src/runtime/canvas_widget_runtime.zig +67 -10
- package/src/runtime/canvas_widget_state.zig +1 -0
- package/src/runtime/canvas_widget_text_tests.zig +1878 -70
- package/src/runtime/effects.zig +5 -6
- package/src/runtime/flow.zig +45 -7
- package/src/runtime/gpu_surface_events.zig +46 -1
- package/src/runtime/runtime_event_tests.zig +9 -6
- package/src/runtime/shell_layout.zig +25 -11
- package/src/runtime/shell_layout_tests.zig +184 -0
- package/src/runtime/shell_view_tests.zig +9 -7
- package/src/runtime/state.zig +6 -0
- package/src/runtime/ui_app.zig +61 -14
- package/src/runtime/ui_app_window_tests.zig +107 -2
- package/src/runtime/view.zig +30 -0
- package/src/runtime/view_widget_text.zig +1048 -10
- package/src/runtime/view_widget_tree.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +82 -6
- package/src/runtime/window_storage.zig +14 -3
- package/src/runtime/window_views.zig +12 -11
- package/src/tooling/manifest.zig +38 -2
- package/src/tooling/raw_manifest.zig +8 -0
- package/src/tooling/templates.zig +17 -0
package/src/runtime/effects.zig
CHANGED
|
@@ -7775,12 +7775,11 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
7775
7775
|
_ = binding.minimize_fn(binding.context, window_label);
|
|
7776
7776
|
}
|
|
7777
7777
|
|
|
7778
|
-
/// Show a window by its declared label: unhide +
|
|
7779
|
-
///
|
|
7780
|
-
///
|
|
7781
|
-
///
|
|
7782
|
-
///
|
|
7783
|
-
/// merely backgrounded window. Fire-and-forget, same contract
|
|
7778
|
+
/// Show a window by its declared label: unhide + order front,
|
|
7779
|
+
/// activating by default and remaining passive for an
|
|
7780
|
+
/// `activate_on_show = false` overlay. It is the counterpart to
|
|
7781
|
+
/// a `close_policy = .hide` hide and also brings back a minimized
|
|
7782
|
+
/// or merely backgrounded window. Fire-and-forget, same contract
|
|
7784
7783
|
/// as `closeWindow`: no event echoes beyond the window's own
|
|
7785
7784
|
/// frame event, an unknown label is a no-op, and the fake
|
|
7786
7785
|
/// executor only records the request in the mirror.
|
package/src/runtime/flow.zig
CHANGED
|
@@ -10,6 +10,7 @@ const runtime_automation_widget_dispatch = @import("automation_widget_dispatch.z
|
|
|
10
10
|
const automation_commands = @import("automation_commands.zig");
|
|
11
11
|
const launch_timing = @import("launch_timing.zig");
|
|
12
12
|
const runtime_clock = @import("clock.zig");
|
|
13
|
+
const runtime_state = @import("state.zig");
|
|
13
14
|
const shell_layout = @import("shell_layout.zig");
|
|
14
15
|
const runtime_builtin_bridge = @import("builtin_bridge.zig");
|
|
15
16
|
const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
|
|
@@ -28,6 +29,8 @@ const security = @import("../security/root.zig");
|
|
|
28
29
|
|
|
29
30
|
const validateCommandName = validation.validateCommandName;
|
|
30
31
|
const sceneNeedsMainWebView = shell_layout.sceneNeedsMainWebView;
|
|
32
|
+
const shellWindowNeedsMainWebView = shell_layout.shellWindowNeedsMainWebView;
|
|
33
|
+
const shellWindowUsesSourcelessCanvas = shell_layout.shellWindowUsesSourcelessCanvas;
|
|
31
34
|
const nowNanoseconds = runtime_clock.nowNanoseconds;
|
|
32
35
|
const canvasWidgetAccessibilityActionKindFromPlatform = widget_bridge.canvasWidgetAccessibilityActionKindFromPlatform;
|
|
33
36
|
const parseAutomationCommandName = automation_commands.parseAutomationCommandName;
|
|
@@ -179,7 +182,10 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
179
182
|
const window = app_info.resolvedStartupWindow(0);
|
|
180
183
|
if (WindowViewMethods().findWindowIndexById(self, window.id) != null) return;
|
|
181
184
|
|
|
182
|
-
const runtime_index = try WindowViewMethods().reserveWindow(self, window.id, window.label, window.resolvedTitle(app_info.app_name), null, true);
|
|
185
|
+
const runtime_index = try WindowViewMethods().reserveWindow(self, window.id, window.label, window.resolvedTitle(app_info.app_name), null, true, .allow_source_less);
|
|
186
|
+
self.windows[runtime_index].activate_on_show = window.activate_on_show;
|
|
187
|
+
self.windows[runtime_index].info.focused = window.activate_on_show and window.show == .immediate;
|
|
188
|
+
self.windows[runtime_index].main_focused = self.windows[runtime_index].info.focused;
|
|
183
189
|
self.windows[runtime_index].info.frame = window.default_frame;
|
|
184
190
|
self.windows[runtime_index].main_frame = geometry.RectF.init(0, 0, window.default_frame.width, window.default_frame.height);
|
|
185
191
|
self.next_window_id = @max(self.next_window_id, window.id + 1);
|
|
@@ -630,14 +636,18 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
630
636
|
const window = app_info.resolvedStartupWindow(index);
|
|
631
637
|
const runtime_index = if (WindowViewMethods().findWindowIndexById(self, window.id)) |runtime_index| blk: {
|
|
632
638
|
self.windows[runtime_index].source = try WindowViewMethods().copySource(self, runtime_index, source);
|
|
639
|
+
self.windows[runtime_index].source_policy = .require_source;
|
|
633
640
|
break :blk runtime_index;
|
|
634
641
|
} else blk: {
|
|
635
|
-
const runtime_index = try WindowViewMethods().reserveWindow(self, window.id, window.label, window.resolvedTitle(app_info.app_name), source, true);
|
|
642
|
+
const runtime_index = try WindowViewMethods().reserveWindow(self, window.id, window.label, window.resolvedTitle(app_info.app_name), source, true, .require_source);
|
|
636
643
|
self.windows[runtime_index].info.frame = window.default_frame;
|
|
637
644
|
self.windows[runtime_index].main_frame = geometry.RectF.init(0, 0, window.default_frame.width, window.default_frame.height);
|
|
638
645
|
break :blk runtime_index;
|
|
639
646
|
};
|
|
640
647
|
self.windows[runtime_index].source_reloads_from_app = true;
|
|
648
|
+
self.windows[runtime_index].activate_on_show = window.activate_on_show;
|
|
649
|
+
self.windows[runtime_index].info.focused = index == 0 and window.activate_on_show and window.show == .immediate;
|
|
650
|
+
self.windows[runtime_index].main_focused = self.windows[runtime_index].info.focused;
|
|
641
651
|
if (index > 0) {
|
|
642
652
|
// The same `.hide` gate as the runtime create path
|
|
643
653
|
// (window_storage): secondary startup windows reach
|
|
@@ -656,7 +666,8 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
656
666
|
if (window.close_policy == .hide and !self.options.platform.supports(.window_hide_on_close)) {
|
|
657
667
|
return error.UnsupportedWindowClosePolicy;
|
|
658
668
|
}
|
|
659
|
-
|
|
669
|
+
const native_info = try self.options.platform.services.createWindow(window);
|
|
670
|
+
try WindowViewMethods().applyNativeInfo(self, runtime_index, native_info);
|
|
660
671
|
}
|
|
661
672
|
try self.options.platform.services.loadWindowWebView(window.id, self.windows[runtime_index].source.?);
|
|
662
673
|
try applyMainWebViewState(self, window.id);
|
|
@@ -675,16 +686,27 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
675
686
|
return;
|
|
676
687
|
}
|
|
677
688
|
|
|
678
|
-
const
|
|
689
|
+
const uses_default_empty_source = appUsesDefaultEmptyWebViewSource(App, app);
|
|
690
|
+
const source = if (sceneNeedsMainWebView(scene) or !uses_default_empty_source)
|
|
679
691
|
try WindowViewMethods().copyLoadedSource(self, try app.webViewSource())
|
|
680
692
|
else
|
|
681
693
|
null;
|
|
682
694
|
if (source != null and !self.options.web_layer) return error.WebViewLayerNotBuilt;
|
|
683
695
|
self.loaded_source = source;
|
|
684
696
|
|
|
685
|
-
|
|
697
|
+
const startup_uses_source = sceneWindowUsesAppSource(scene.windows[0], uses_default_empty_source);
|
|
698
|
+
try loadStartupSceneWindow(
|
|
699
|
+
self,
|
|
700
|
+
scene.windows[0],
|
|
701
|
+
if (startup_uses_source) source else null,
|
|
702
|
+
if (startup_uses_source) .allow_source_less else .never_source,
|
|
703
|
+
);
|
|
686
704
|
for (scene.windows[1..]) |window| {
|
|
687
|
-
|
|
705
|
+
if (sceneWindowUsesAppSource(window, uses_default_empty_source)) {
|
|
706
|
+
_ = try WindowViewMethods().createShellWindowWithSourceMode(self, window, source, source != null);
|
|
707
|
+
} else {
|
|
708
|
+
_ = try WindowViewMethods().createSourcelessShellWindow(self, window);
|
|
709
|
+
}
|
|
688
710
|
}
|
|
689
711
|
|
|
690
712
|
log(self, "scene.load", "loaded app scene", &.{
|
|
@@ -693,7 +715,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
693
715
|
});
|
|
694
716
|
}
|
|
695
717
|
|
|
696
|
-
fn loadStartupSceneWindow(self: *Runtime, shell_window: app_manifest.ShellWindow, source: ?platform.WebViewSource) anyerror!void {
|
|
718
|
+
fn loadStartupSceneWindow(self: *Runtime, shell_window: app_manifest.ShellWindow, source: ?platform.WebViewSource, source_policy: runtime_state.WindowSourcePolicy) anyerror!void {
|
|
697
719
|
const app_info = self.options.platform.app_info;
|
|
698
720
|
const startup_window = app_info.resolvedStartupWindow(0);
|
|
699
721
|
const window_id = startup_window.id;
|
|
@@ -712,6 +734,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
712
734
|
shell_window.title orelse app_info.resolvedWindowTitle(),
|
|
713
735
|
null,
|
|
714
736
|
true,
|
|
737
|
+
source_policy,
|
|
715
738
|
);
|
|
716
739
|
if (WindowViewMethods().findWindowIndexByLabel(self, shell_window.label)) |label_index| {
|
|
717
740
|
if (label_index != runtime_index) return error.DuplicateWindowLabel;
|
|
@@ -722,6 +745,14 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
722
745
|
self.windows[runtime_index].info.frame = startup_frame;
|
|
723
746
|
self.windows[runtime_index].source = if (source) |source_value| try WindowViewMethods().copySource(self, runtime_index, source_value) else null;
|
|
724
747
|
self.windows[runtime_index].source_reloads_from_app = source != null;
|
|
748
|
+
self.windows[runtime_index].source_policy = source_policy;
|
|
749
|
+
// The host created this startup window from AppInfo before
|
|
750
|
+
// the scene loaded. Overlay presentation is immutable host
|
|
751
|
+
// state, so runtime bookkeeping must retain that same source
|
|
752
|
+
// of truth even when the scene descriptor differs.
|
|
753
|
+
self.windows[runtime_index].activate_on_show = startup_window.activate_on_show;
|
|
754
|
+
self.windows[runtime_index].info.focused = startup_window.activate_on_show and startup_window.show == .immediate;
|
|
755
|
+
self.windows[runtime_index].main_focused = self.windows[runtime_index].info.focused;
|
|
725
756
|
if (!self.windows[runtime_index].main_frame_set) {
|
|
726
757
|
self.windows[runtime_index].main_frame = geometry.RectF.init(0, 0, startup_frame.width, startup_frame.height);
|
|
727
758
|
}
|
|
@@ -766,6 +797,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
766
797
|
return;
|
|
767
798
|
}
|
|
768
799
|
for (self.windows[0..self.window_count], 0..) |*window, index| {
|
|
800
|
+
if (window.source_policy == .never_source) continue;
|
|
769
801
|
if (window.source == null or window.source_reloads_from_app) {
|
|
770
802
|
window.source = try WindowViewMethods().copySource(self, index, source);
|
|
771
803
|
}
|
|
@@ -1269,3 +1301,9 @@ fn appUsesDefaultEmptyWebViewSource(comptime App: type, app: App) bool {
|
|
|
1269
1301
|
app.source.bytes.len == 0 and
|
|
1270
1302
|
app.source.asset_options == null;
|
|
1271
1303
|
}
|
|
1304
|
+
|
|
1305
|
+
fn sceneWindowUsesAppSource(shell_window: app_manifest.ShellWindow, app_uses_default_empty_source: bool) bool {
|
|
1306
|
+
if (shellWindowNeedsMainWebView(shell_window)) return true;
|
|
1307
|
+
if (shellWindowUsesSourcelessCanvas(shell_window)) return false;
|
|
1308
|
+
return !app_uses_default_empty_source;
|
|
1309
|
+
}
|
|
@@ -106,7 +106,6 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
106
106
|
self.views[index].gpu_backend = frame_event.backend;
|
|
107
107
|
self.views[index].gpu_pixel_format = frame_event.pixel_format;
|
|
108
108
|
self.views[index].gpu_present_mode = frame_event.present_mode;
|
|
109
|
-
self.views[index].gpu_alpha_mode = frame_event.alpha_mode;
|
|
110
109
|
self.views[index].gpu_color_space = frame_event.color_space;
|
|
111
110
|
self.views[index].gpu_vsync = frame_event.vsync;
|
|
112
111
|
self.views[index].gpu_status = frame_event.status;
|
|
@@ -119,6 +118,14 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
119
118
|
// the rebuild so the app sees it honestly.
|
|
120
119
|
enriched_frame_event.occluded = frame_event.occluded;
|
|
121
120
|
}
|
|
121
|
+
// Alpha mode is immutable surface configuration, not a
|
|
122
|
+
// completion-time measurement. The desktop ABIs predate
|
|
123
|
+
// premultiplied surfaces and stamp their legacy opaque
|
|
124
|
+
// default on every completion, while their actual pixel
|
|
125
|
+
// presenters already preserve/premultiply alpha. Keep the
|
|
126
|
+
// create-time mode authoritative and normalize the event
|
|
127
|
+
// delivered to the app in both diagnostics tiers.
|
|
128
|
+
enriched_frame_event.alpha_mode = self.views[index].gpu_alpha_mode;
|
|
122
129
|
// Native scroll drivers reconcile against live host state
|
|
123
130
|
// on every presented frame (the relayout-stomp lesson: a
|
|
124
131
|
// one-shot frame patch races shell relayout): frames,
|
|
@@ -630,6 +637,44 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
630
637
|
if (widget_keyboard_event) |keyboard_event| {
|
|
631
638
|
try CanvasWidgetEventMethods().dispatchCanvasWidgetCommandFromKeyboard(self, app, keyboard_event);
|
|
632
639
|
try self.dispatchEvent(app, .{ .canvas_widget_keyboard = keyboard_event });
|
|
640
|
+
// A logical undo/redo can require select -> replace ->
|
|
641
|
+
// restore-selection. Apply and dispatch each continuation
|
|
642
|
+
// only after the previous on-input Msg rebuilt the
|
|
643
|
+
// controlled tree, keeping runtime and model lockstep at
|
|
644
|
+
// every intermediate state. These synthetic edit carriers
|
|
645
|
+
// are key_down-shaped (not committed text), so a target
|
|
646
|
+
// removed, hidden, or replaced with another editor kind by
|
|
647
|
+
// the rebuild can never receive stale replacement bytes.
|
|
648
|
+
// The route and focus-target snapshot are tree-relative too:
|
|
649
|
+
// re-resolve both after every rebuild so custom event
|
|
650
|
+
// consumers never observe ancestors, indices, bounds, or
|
|
651
|
+
// state from the tree that handled the previous step.
|
|
652
|
+
for (0..2) |_| {
|
|
653
|
+
if (keyboard_event.history_replay_serial == 0) break;
|
|
654
|
+
const view_index = runtimeFindViewIndex(self, keyboard_event.window_id, keyboard_event.view_label) orelse break;
|
|
655
|
+
const target = keyboard_event.target orelse break;
|
|
656
|
+
if (self.views[view_index].kind != .gpu_surface) break;
|
|
657
|
+
const edit = self.views[view_index].canvasWidgetTextHistoryReplayNext(
|
|
658
|
+
target,
|
|
659
|
+
keyboard_event.history_replay_serial,
|
|
660
|
+
keyboard_event.history_replay_redo,
|
|
661
|
+
) orelse break;
|
|
662
|
+
var followup = keyboard_event;
|
|
663
|
+
followup.keyboard = .{
|
|
664
|
+
.phase = .key_down,
|
|
665
|
+
.focused_id = keyboard_event.keyboard.focused_id,
|
|
666
|
+
.edit = edit,
|
|
667
|
+
};
|
|
668
|
+
const route = try self.views[view_index].widgetLayoutTree().routeKeyboardEvent(
|
|
669
|
+
followup.keyboard,
|
|
670
|
+
&self.widget_event_route_entries,
|
|
671
|
+
);
|
|
672
|
+
followup.target = route.target orelse break;
|
|
673
|
+
followup.route = route.entries;
|
|
674
|
+
followup.history_replay = true;
|
|
675
|
+
try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, &followup);
|
|
676
|
+
try self.dispatchEvent(app, .{ .canvas_widget_keyboard = followup });
|
|
677
|
+
}
|
|
633
678
|
} else if ((input_event.kind == .key_down or input_event.kind == .key_up) and
|
|
634
679
|
!widget_surface_dismissed and !terminal_key_lifetime_suppressed)
|
|
635
680
|
{
|
|
@@ -309,20 +309,21 @@ test "runtime dispatches GPU surface events" {
|
|
|
309
309
|
.label = "canvas",
|
|
310
310
|
.kind = .gpu_surface,
|
|
311
311
|
.frame = geometry.RectF.init(0, 0, 640, 360),
|
|
312
|
+
.gpu_surface = .{ .alpha_mode = .premultiplied },
|
|
312
313
|
});
|
|
313
314
|
const initial_frame = try harness.runtime.gpuSurfaceFrame(1, "canvas");
|
|
314
315
|
try std.testing.expectEqual(created.id, initial_frame.surface_id);
|
|
315
316
|
try std.testing.expectEqual(platform.GpuSurfaceBackend.metal, created.gpu_backend);
|
|
316
317
|
try std.testing.expectEqual(platform.GpuSurfacePixelFormat.bgra8_unorm, created.gpu_pixel_format);
|
|
317
318
|
try std.testing.expectEqual(platform.GpuSurfacePresentMode.timer, created.gpu_present_mode);
|
|
318
|
-
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode
|
|
319
|
+
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.premultiplied, created.gpu_alpha_mode);
|
|
319
320
|
try std.testing.expectEqual(platform.GpuSurfaceColorSpace.srgb, created.gpu_color_space);
|
|
320
321
|
try std.testing.expect(created.gpu_vsync);
|
|
321
322
|
try std.testing.expectEqual(platform.GpuSurfaceStatus.ready, created.gpu_status);
|
|
322
323
|
try std.testing.expectEqual(platform.GpuSurfaceBackend.metal, initial_frame.backend);
|
|
323
324
|
try std.testing.expectEqual(platform.GpuSurfacePixelFormat.bgra8_unorm, initial_frame.pixel_format);
|
|
324
325
|
try std.testing.expectEqual(platform.GpuSurfacePresentMode.timer, initial_frame.present_mode);
|
|
325
|
-
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode
|
|
326
|
+
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.premultiplied, initial_frame.alpha_mode);
|
|
326
327
|
try std.testing.expectEqual(platform.GpuSurfaceColorSpace.srgb, initial_frame.color_space);
|
|
327
328
|
try std.testing.expect(initial_frame.vsync);
|
|
328
329
|
try std.testing.expectEqual(platform.GpuSurfaceStatus.ready, initial_frame.status);
|
|
@@ -389,7 +390,9 @@ test "runtime dispatches GPU surface events" {
|
|
|
389
390
|
try std.testing.expectEqual(platform.GpuSurfaceBackend.metal, app_state.last_gpu_backend);
|
|
390
391
|
try std.testing.expectEqual(platform.GpuSurfacePixelFormat.bgra8_unorm, app_state.last_gpu_pixel_format);
|
|
391
392
|
try std.testing.expectEqual(platform.GpuSurfacePresentMode.timer, app_state.last_gpu_present_mode);
|
|
392
|
-
|
|
393
|
+
// Desktop hosts still stamp their legacy opaque completion value;
|
|
394
|
+
// runtime delivery preserves the surface's create-time contract.
|
|
395
|
+
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.premultiplied, app_state.last_gpu_alpha_mode);
|
|
393
396
|
try std.testing.expectEqual(platform.GpuSurfaceColorSpace.srgb, app_state.last_gpu_color_space);
|
|
394
397
|
try std.testing.expect(app_state.last_gpu_vsync);
|
|
395
398
|
try std.testing.expectEqual(platform.GpuSurfaceStatus.ready, app_state.last_gpu_status);
|
|
@@ -444,7 +447,7 @@ test "runtime dispatches GPU surface events" {
|
|
|
444
447
|
try std.testing.expectEqual(platform.GpuSurfaceBackend.metal, frame.backend);
|
|
445
448
|
try std.testing.expectEqual(platform.GpuSurfacePixelFormat.bgra8_unorm, frame.pixel_format);
|
|
446
449
|
try std.testing.expectEqual(platform.GpuSurfacePresentMode.timer, frame.present_mode);
|
|
447
|
-
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode
|
|
450
|
+
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.premultiplied, frame.alpha_mode);
|
|
448
451
|
try std.testing.expectEqual(platform.GpuSurfaceColorSpace.srgb, frame.color_space);
|
|
449
452
|
try std.testing.expect(frame.vsync);
|
|
450
453
|
try std.testing.expectEqual(platform.GpuSurfaceStatus.ready, frame.status);
|
|
@@ -515,7 +518,7 @@ test "runtime dispatches GPU surface events" {
|
|
|
515
518
|
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuBackend\":\"metal\"") != null);
|
|
516
519
|
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuPixelFormat\":\"bgra8_unorm\"") != null);
|
|
517
520
|
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuPresentMode\":\"timer\"") != null);
|
|
518
|
-
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuAlphaMode\":\"
|
|
521
|
+
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuAlphaMode\":\"premultiplied\"") != null);
|
|
519
522
|
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuColorSpace\":\"srgb\"") != null);
|
|
520
523
|
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuVsync\":true") != null);
|
|
521
524
|
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"gpuStatus\":\"ready\"") != null);
|
|
@@ -586,7 +589,7 @@ test "runtime dispatches GPU surface events" {
|
|
|
586
589
|
try std.testing.expectEqual(platform.GpuSurfaceBackend.metal, preview_frame.backend);
|
|
587
590
|
try std.testing.expectEqual(platform.GpuSurfacePixelFormat.bgra8_unorm, preview_frame.pixel_format);
|
|
588
591
|
try std.testing.expectEqual(platform.GpuSurfacePresentMode.timer, preview_frame.present_mode);
|
|
589
|
-
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode
|
|
592
|
+
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.premultiplied, preview_frame.alpha_mode);
|
|
590
593
|
try std.testing.expectEqual(platform.GpuSurfaceColorSpace.srgb, preview_frame.color_space);
|
|
591
594
|
try std.testing.expect(preview_frame.vsync);
|
|
592
595
|
try std.testing.expectEqual(platform.GpuSurfaceStatus.ready, preview_frame.status);
|
|
@@ -239,19 +239,33 @@ pub fn shellWindowShowMode(shell_window: app_manifest.ShellWindow) platform.Wind
|
|
|
239
239
|
return .immediate;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
/// Whether
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
242
|
+
/// Whether this window declares the app source as its `main` WebView.
|
|
243
|
+
pub fn shellWindowNeedsMainWebView(window: app_manifest.ShellWindow) bool {
|
|
244
|
+
for (window.views) |view| {
|
|
245
|
+
if (view.kind == .webview and validation.isMainWebViewLabel(view.label)) return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/// A canvas-owned window has no WebView content of its own. It must stay
|
|
251
|
+
/// sourceless even when another scene window loads the app source: otherwise
|
|
252
|
+
/// the source silently materializes a full-window main WebView behind the
|
|
253
|
+
/// canvas (and transparent Windows windows reject creation altogether).
|
|
254
|
+
pub fn shellWindowUsesSourcelessCanvas(window: app_manifest.ShellWindow) bool {
|
|
255
|
+
var has_gpu_surface = false;
|
|
256
|
+
for (window.views) |view| {
|
|
257
|
+
if (view.kind == .webview) return false;
|
|
258
|
+
if (view.kind == .gpu_surface) has_gpu_surface = true;
|
|
259
|
+
}
|
|
260
|
+
return has_gpu_surface;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/// Whether loading this scene must copy the app's WebView source at all.
|
|
264
|
+
/// Per-window routing happens in `loadScene`: a scene may need the source
|
|
265
|
+
/// for one WebView window while keeping a canvas overlay sourceless.
|
|
250
266
|
pub fn sceneNeedsMainWebView(scene: app_manifest.ShellConfig) bool {
|
|
251
267
|
for (scene.windows) |window| {
|
|
252
|
-
|
|
253
|
-
if (view.kind == .webview and validation.isMainWebViewLabel(view.label)) return true;
|
|
254
|
-
}
|
|
268
|
+
if (shellWindowNeedsMainWebView(window)) return true;
|
|
255
269
|
}
|
|
256
270
|
return false;
|
|
257
271
|
}
|
|
@@ -662,6 +662,55 @@ test "canvas shell windows present before they become visible" {
|
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
664
|
|
|
665
|
+
test "overlay window presentation reaches create and passive show preserves focus" {
|
|
666
|
+
const TestApp = struct {
|
|
667
|
+
fn app(self: *@This()) App {
|
|
668
|
+
return .{ .context = self, .name = "overlay-window", .source = platform.WebViewSource.html("<h1>Host</h1>") };
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
673
|
+
defer harness.destroy(std.testing.allocator);
|
|
674
|
+
var app_state: TestApp = .{};
|
|
675
|
+
try harness.start(app_state.app());
|
|
676
|
+
|
|
677
|
+
const views = [_]app_manifest.ShellView{
|
|
678
|
+
.{ .label = "overlay-content", .kind = .webview, .url = "zero://app/overlay.html", .fill = true },
|
|
679
|
+
};
|
|
680
|
+
const info = try harness.runtime.createShellWindow(.{
|
|
681
|
+
.label = "overlay",
|
|
682
|
+
.title = "Overlay",
|
|
683
|
+
.titlebar = .chromeless,
|
|
684
|
+
.transparent = true,
|
|
685
|
+
.always_on_top = true,
|
|
686
|
+
.click_through = true,
|
|
687
|
+
.activate_on_show = false,
|
|
688
|
+
.views = &views,
|
|
689
|
+
}, platform.WebViewSource.html("<h1>Overlay</h1>"));
|
|
690
|
+
const index = for (harness.null_platform.windows[0..harness.null_platform.window_count], 0..) |window, i| {
|
|
691
|
+
if (window.id == info.id) break i;
|
|
692
|
+
} else return error.WindowNotFound;
|
|
693
|
+
|
|
694
|
+
try std.testing.expect(harness.null_platform.window_transparent[index]);
|
|
695
|
+
try std.testing.expect(harness.null_platform.window_always_on_top[index]);
|
|
696
|
+
try std.testing.expect(harness.null_platform.window_click_through[index]);
|
|
697
|
+
try std.testing.expect(!harness.null_platform.window_activate_on_show[index]);
|
|
698
|
+
|
|
699
|
+
const runtime_index = for (harness.runtime.windows[0..harness.runtime.window_count], 0..) |window, i| {
|
|
700
|
+
if (window.info.id == info.id) break i;
|
|
701
|
+
} else return error.WindowNotFound;
|
|
702
|
+
const focused_before = harness.runtime.windows[0].info.id;
|
|
703
|
+
try harness.runtime.showWindow(info.id);
|
|
704
|
+
try std.testing.expect(harness.runtime.windows[0].info.focused);
|
|
705
|
+
try std.testing.expectEqual(focused_before, harness.runtime.windows[0].info.id);
|
|
706
|
+
try std.testing.expect(!harness.runtime.windows[runtime_index].info.focused);
|
|
707
|
+
|
|
708
|
+
// Explicit focus is still deliberate activation, even for a window
|
|
709
|
+
// whose implicit creation/show policy is passive.
|
|
710
|
+
try harness.runtime.focusWindow(info.id);
|
|
711
|
+
try std.testing.expect(harness.runtime.windows[runtime_index].info.focused);
|
|
712
|
+
}
|
|
713
|
+
|
|
665
714
|
test "runtime lays out created shell windows with native returned bounds" {
|
|
666
715
|
const ShellCreatePlatform = struct {
|
|
667
716
|
create_count: usize = 0,
|
|
@@ -825,6 +874,77 @@ test "runtime lays out startup shell windows with native configured bounds" {
|
|
|
825
874
|
try std.testing.expectEqual(@as(f32, 1200), statusbar.frame.width);
|
|
826
875
|
}
|
|
827
876
|
|
|
877
|
+
test "startup scene adoption preserves manifest passive show policy" {
|
|
878
|
+
const TestApp = struct {
|
|
879
|
+
const scene_windows = [_]app_manifest.ShellWindow{.{
|
|
880
|
+
.label = "main",
|
|
881
|
+
.title = "Scene title",
|
|
882
|
+
.width = 640,
|
|
883
|
+
.height = 480,
|
|
884
|
+
// Deliberately leave activate_on_show at its true default:
|
|
885
|
+
// the already-created startup host still owns this
|
|
886
|
+
// create-time setting through AppInfo below.
|
|
887
|
+
}};
|
|
888
|
+
|
|
889
|
+
fn scene(context: *anyopaque) anyerror!app_manifest.ShellConfig {
|
|
890
|
+
_ = context;
|
|
891
|
+
return .{ .windows = &scene_windows };
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
fn app(self: *@This()) App {
|
|
895
|
+
return .{
|
|
896
|
+
.context = self,
|
|
897
|
+
.name = "passive-startup-adoption",
|
|
898
|
+
.scene_fn = scene,
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
const app_info: platform.AppInfo = .{
|
|
904
|
+
.app_name = "Passive Startup",
|
|
905
|
+
.main_window = .{
|
|
906
|
+
.label = "main",
|
|
907
|
+
.title = "Manifest title",
|
|
908
|
+
.default_frame = geometry.RectF.init(0, 0, 640, 480),
|
|
909
|
+
.activate_on_show = false,
|
|
910
|
+
},
|
|
911
|
+
};
|
|
912
|
+
var null_platform = platform.NullPlatform.initWithOptions(
|
|
913
|
+
.{ .id = 1, .size = geometry.SizeF.init(640, 480), .scale_factor = 1 },
|
|
914
|
+
.system,
|
|
915
|
+
app_info,
|
|
916
|
+
);
|
|
917
|
+
// Model the host-created main window. Its passive flag is fixed
|
|
918
|
+
// before Runtime receives app_start and loads the scene.
|
|
919
|
+
null_platform.windows[0] = .{
|
|
920
|
+
.id = 1,
|
|
921
|
+
.label = "main",
|
|
922
|
+
.title = "Manifest title",
|
|
923
|
+
.frame = geometry.RectF.init(0, 0, 640, 480),
|
|
924
|
+
.scale_factor = 1,
|
|
925
|
+
.open = true,
|
|
926
|
+
.focused = false,
|
|
927
|
+
};
|
|
928
|
+
null_platform.window_count = 1;
|
|
929
|
+
null_platform.window_activate_on_show[0] = false;
|
|
930
|
+
null_platform.window_visible[0] = true;
|
|
931
|
+
|
|
932
|
+
const runtime = try std.testing.allocator.create(Runtime);
|
|
933
|
+
defer std.testing.allocator.destroy(runtime);
|
|
934
|
+
Runtime.initAt(runtime, .{ .platform = null_platform.platform() });
|
|
935
|
+
defer runtime.deinit();
|
|
936
|
+
var app_state: TestApp = .{};
|
|
937
|
+
|
|
938
|
+
try runtime.dispatchPlatformEvent(app_state.app(), .app_start);
|
|
939
|
+
|
|
940
|
+
try std.testing.expect(!runtime.windows[0].activate_on_show);
|
|
941
|
+
try std.testing.expect(!runtime.windows[0].info.focused);
|
|
942
|
+
try runtime.showWindow(1);
|
|
943
|
+
try std.testing.expectEqual(@as(u32, 1), null_platform.window_show_count[0]);
|
|
944
|
+
try std.testing.expect(!null_platform.windows[0].focused);
|
|
945
|
+
try std.testing.expect(!runtime.windows[0].info.focused);
|
|
946
|
+
}
|
|
947
|
+
|
|
828
948
|
test "runtime loads canvas-only startup shell without implicit main webview" {
|
|
829
949
|
const TestApp = struct {
|
|
830
950
|
const scene_views = [_]app_manifest.ShellView{.{
|
|
@@ -876,6 +996,70 @@ test "runtime loads canvas-only startup shell without implicit main webview" {
|
|
|
876
996
|
try std.testing.expectEqualStrings("canvas", snapshot.views[0].label);
|
|
877
997
|
}
|
|
878
998
|
|
|
999
|
+
test "hybrid scenes keep transparent canvas overlay windows sourceless" {
|
|
1000
|
+
const TestApp = struct {
|
|
1001
|
+
const main_views = [_]app_manifest.ShellView{.{
|
|
1002
|
+
.label = "main",
|
|
1003
|
+
.kind = .webview,
|
|
1004
|
+
.url = "zero://inline",
|
|
1005
|
+
.fill = true,
|
|
1006
|
+
}};
|
|
1007
|
+
const overlay_views = [_]app_manifest.ShellView{.{
|
|
1008
|
+
.label = "overlay-canvas",
|
|
1009
|
+
.kind = .gpu_surface,
|
|
1010
|
+
.fill = true,
|
|
1011
|
+
}};
|
|
1012
|
+
const scene_windows = [_]app_manifest.ShellWindow{
|
|
1013
|
+
.{
|
|
1014
|
+
.label = "main",
|
|
1015
|
+
.title = "Main",
|
|
1016
|
+
.width = 800,
|
|
1017
|
+
.height = 600,
|
|
1018
|
+
.views = &main_views,
|
|
1019
|
+
},
|
|
1020
|
+
.{
|
|
1021
|
+
.label = "overlay",
|
|
1022
|
+
.title = "Overlay",
|
|
1023
|
+
.width = 320,
|
|
1024
|
+
.height = 180,
|
|
1025
|
+
.transparent = true,
|
|
1026
|
+
.views = &overlay_views,
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
fn scene(context: *anyopaque) anyerror!app_manifest.ShellConfig {
|
|
1031
|
+
_ = context;
|
|
1032
|
+
return .{ .windows = &scene_windows };
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
fn app(self: *@This()) App {
|
|
1036
|
+
return .{
|
|
1037
|
+
.context = self,
|
|
1038
|
+
.name = "hybrid-overlay",
|
|
1039
|
+
.source = platform.WebViewSource.html("<h1>Main content</h1>"),
|
|
1040
|
+
.scene_fn = scene,
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
const harness = try TestHarness().create(std.testing.allocator, .{ .id = 1, .size = geometry.SizeF.init(800, 600) });
|
|
1046
|
+
defer harness.destroy(std.testing.allocator);
|
|
1047
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1048
|
+
var app_state: TestApp = .{};
|
|
1049
|
+
const app = app_state.app();
|
|
1050
|
+
try harness.start(app);
|
|
1051
|
+
|
|
1052
|
+
try std.testing.expect(harness.null_platform.window_sources[0] != null);
|
|
1053
|
+
try std.testing.expect(harness.null_platform.window_sources[1] == null);
|
|
1054
|
+
try std.testing.expect(harness.runtime.windows[0].source != null);
|
|
1055
|
+
try std.testing.expect(harness.runtime.windows[1].source == null);
|
|
1056
|
+
|
|
1057
|
+
// Hot reload must not turn the canvas overlay into a WebView window.
|
|
1058
|
+
try reloadWindows(&harness.runtime, app);
|
|
1059
|
+
try std.testing.expect(harness.null_platform.window_sources[1] == null);
|
|
1060
|
+
try std.testing.expect(harness.runtime.windows[1].source == null);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
879
1063
|
test "runtime relayouts shell views attached to startup window" {
|
|
880
1064
|
const TestApp = struct {
|
|
881
1065
|
fn app(self: *@This()) App {
|
|
@@ -562,13 +562,6 @@ test "runtime rejects unsupported GPU surface configuration" {
|
|
|
562
562
|
.frame = geometry.RectF.init(0, 0, 320, 240),
|
|
563
563
|
.gpu_surface = .{ .backend = .none },
|
|
564
564
|
}));
|
|
565
|
-
try std.testing.expectError(error.UnsupportedViewKind, harness.runtime.createView(.{
|
|
566
|
-
.window_id = 1,
|
|
567
|
-
.label = "transparent-canvas",
|
|
568
|
-
.kind = .gpu_surface,
|
|
569
|
-
.frame = geometry.RectF.init(0, 0, 320, 240),
|
|
570
|
-
.gpu_surface = .{ .alpha_mode = .premultiplied },
|
|
571
|
-
}));
|
|
572
565
|
try std.testing.expectError(error.UnsupportedViewKind, harness.runtime.createView(.{
|
|
573
566
|
.window_id = 1,
|
|
574
567
|
.label = "wide-color-canvas",
|
|
@@ -601,4 +594,13 @@ test "runtime rejects unsupported GPU surface configuration" {
|
|
|
601
594
|
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.@"opaque", supported.gpu_alpha_mode);
|
|
602
595
|
try std.testing.expectEqual(platform.GpuSurfaceColorSpace.srgb, supported.gpu_color_space);
|
|
603
596
|
try std.testing.expect(supported.gpu_vsync);
|
|
597
|
+
|
|
598
|
+
const transparent = try harness.runtime.createView(.{
|
|
599
|
+
.window_id = 1,
|
|
600
|
+
.label = "transparent-canvas",
|
|
601
|
+
.kind = .gpu_surface,
|
|
602
|
+
.frame = geometry.RectF.init(0, 0, 320, 240),
|
|
603
|
+
.gpu_surface = .{ .alpha_mode = .premultiplied },
|
|
604
|
+
});
|
|
605
|
+
try std.testing.expectEqual(platform.GpuSurfaceAlphaMode.premultiplied, transparent.gpu_alpha_mode);
|
|
604
606
|
}
|
package/src/runtime/state.zig
CHANGED
|
@@ -27,6 +27,12 @@ pub const RuntimeWindow = struct {
|
|
|
27
27
|
main_view_id: platform.ViewId = 0,
|
|
28
28
|
source: ?platform.WebViewSource = null,
|
|
29
29
|
source_reloads_from_app: bool = false,
|
|
30
|
+
/// Retained so hot reload never materializes an app WebView in a
|
|
31
|
+
/// deliberately sourceless canvas window.
|
|
32
|
+
source_policy: WindowSourcePolicy = .allow_source_less,
|
|
33
|
+
/// Creation-time show policy retained so Runtime.showWindow mirrors
|
|
34
|
+
/// whether the native host passively orders front or activates.
|
|
35
|
+
activate_on_show: bool = true,
|
|
30
36
|
main_frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
|
|
31
37
|
main_frame_set: bool = false,
|
|
32
38
|
main_layer: i32 = 0,
|