@native-sdk/cli 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +41 -1
- package/build.zig +264 -3
- package/native-sdk.d.ts +17 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +138 -3
- package/packages/core/sdk/core.ts +225 -3
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +2625 -262
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +4 -2
- package/skill-data/ts-core/SKILL.md +9 -1
- package/src/app_runner/root.zig +106 -1
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +187 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/linux/gtk_host.c +112 -3
- package/src/platform/linux/root.zig +71 -0
- package/src/platform/macos/appkit_host.h +59 -2
- package/src/platform/macos/appkit_host.m +663 -34
- package/src/platform/macos/cef_host.mm +262 -10
- package/src/platform/macos/root.zig +126 -4
- package/src/platform/null_platform.zig +298 -5
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +36 -0
- package/src/platform/types.zig +247 -8
- package/src/platform/windows/root.zig +134 -0
- package/src/platform/windows/webview2_host.cpp +152 -40
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +25 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/ui.zig +46 -9
- package/src/primitives/canvas/ui_markup.zig +82 -34
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
- package/src/primitives/canvas/ui_markup_contract.zig +10 -1
- package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_tests.zig +55 -9
- package/src/primitives/canvas/ui_markup_view.zig +81 -14
- package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
- package/src/primitives/canvas/ui_schema.zig +29 -0
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
- package/src/primitives/canvas/widget_layout.zig +9 -4
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widgets.zig +16 -0
- package/src/root.zig +12 -0
- package/src/runtime/api.zig +15 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +64 -0
- package/src/runtime/bridge_payload.zig +7 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +711 -5
- package/src/runtime/canvas_fonts.zig +120 -25
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +221 -0
- package/src/runtime/canvas_images.zig +78 -19
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +24 -4
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +148 -9
- package/src/runtime/effects.zig +1664 -43
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_tests.zig +153 -0
- package/src/runtime/flow.zig +44 -0
- package/src/runtime/gpu_surface_events.zig +7 -0
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +20 -0
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +111 -20
- package/src/runtime/session_record.zig +27 -2
- package/src/runtime/session_replay.zig +168 -16
- package/src/runtime/session_tests.zig +2118 -4
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +3 -0
- package/src/runtime/ts_core_host.zig +439 -4
- package/src/runtime/ts_core_host_tests.zig +41 -0
- package/src/runtime/ts_ui_app.zig +63 -0
- package/src/runtime/ui_app.zig +169 -6
- package/src/runtime/ui_app_tests.zig +334 -0
- package/src/runtime/ui_app_window_tests.zig +468 -0
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +32 -0
- package/src/runtime/window_views.zig +61 -1
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +219 -1
package/src/embed/tests.zig
CHANGED
|
@@ -79,6 +79,193 @@ test "embedded app starts and loads source" {
|
|
|
79
79
|
try @import("std").testing.expectEqualStrings("<p>Embedded</p>", null_platform.loaded_source.?.bytes);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
test "embedded app deinit returns registered font bytes across create-destroy cycles" {
|
|
83
|
+
// A direct embedder that creates and destroys apps in one process:
|
|
84
|
+
// every cycle registers a face (font bytes are the embedded
|
|
85
|
+
// runtime's only heap ownership) and tears down through the public
|
|
86
|
+
// `deinit` — the lifecycle end the doc comment promises. The
|
|
87
|
+
// leak-checking test allocator behind the `Options.allocator` seam
|
|
88
|
+
// fails this test if any cycle strands the storage, which is
|
|
89
|
+
// exactly what a stop()-only teardown did.
|
|
90
|
+
var cycle: usize = 0;
|
|
91
|
+
while (cycle < 3) : (cycle += 1) {
|
|
92
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
93
|
+
var state: u8 = 0;
|
|
94
|
+
const embedded = try std.testing.allocator.create(EmbeddedApp);
|
|
95
|
+
defer std.testing.allocator.destroy(embedded);
|
|
96
|
+
embedded.initInPlace(.{
|
|
97
|
+
.context = &state,
|
|
98
|
+
.name = "embedded-font-cycle",
|
|
99
|
+
.source = platform.WebViewSource.html("<p>Fonts</p>"),
|
|
100
|
+
}, null_platform.platform());
|
|
101
|
+
defer embedded.deinit();
|
|
102
|
+
// Ownership is frozen at init (`Runtime.owned_allocator`;
|
|
103
|
+
// mutating `options.allocator` retargets nothing), so the test
|
|
104
|
+
// re-freezes the field itself — equivalent to constructing with
|
|
105
|
+
// the leak-checked allocator, safe while nothing is owned yet.
|
|
106
|
+
embedded.runtime.owned_allocator = std.testing.allocator;
|
|
107
|
+
|
|
108
|
+
try embedded.start();
|
|
109
|
+
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
110
|
+
try std.testing.expectEqual(@as(usize, 1), embedded.runtime.registeredCanvasFontCount());
|
|
111
|
+
try embedded.stop();
|
|
112
|
+
|
|
113
|
+
// Deinit returns BOTH sides of the registration: the Zig-side
|
|
114
|
+
// bytes (the leak-checking allocator above) and the host-side
|
|
115
|
+
// registration — the runtime must call the platform's
|
|
116
|
+
// font-unregister seam per registered id, the call a macOS host
|
|
117
|
+
// answers by dropping its CoreText descriptor and caches. The
|
|
118
|
+
// null platform records that call; the deferred second deinit
|
|
119
|
+
// stays the idempotence backstop.
|
|
120
|
+
embedded.deinit();
|
|
121
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.gpu_surface_font_unregister_count);
|
|
122
|
+
try std.testing.expectEqual(@as(u64, canvas.min_registered_font_id), null_platform.gpu_surface_font_unregister_id);
|
|
123
|
+
// The null platform's register seam is off by default, so the
|
|
124
|
+
// runtime captured ownership token 0 (nothing installed
|
|
125
|
+
// host-side) and the teardown call must carry exactly that.
|
|
126
|
+
try std.testing.expectEqual(@as(u64, 0), null_platform.gpu_surface_font_unregister_token);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
test "embedded app deinit leaves a newer runtime's re-registration of the same font id intact" {
|
|
131
|
+
// Host font state is per-process while font ids are only permanent
|
|
132
|
+
// per-runtime, so two live runtimes can pass the same id through one
|
|
133
|
+
// host: the later registration wins (the documented lifecycle), and
|
|
134
|
+
// the OLDER runtime's deinit must return only its own already-
|
|
135
|
+
// replaced registration — never the newer runtime's live face,
|
|
136
|
+
// which that runtime's engine still holds and draws through. The
|
|
137
|
+
// null platform's host-font mirror models the stateful host (the
|
|
138
|
+
// shape of macOS's descriptor and token tables): one instance
|
|
139
|
+
// stands in for the process, both runtimes register through it, and
|
|
140
|
+
// the per-registration ownership token is what the unregister guard
|
|
141
|
+
// matches. An id-keyed removal is exactly the regression this test
|
|
142
|
+
// catches — it would empty the mirror at A's deinit and fail the
|
|
143
|
+
// survives assertion below.
|
|
144
|
+
var host_platform = platform.NullPlatform.init(.{});
|
|
145
|
+
host_platform.gpu_surface_font_registrations = true;
|
|
146
|
+
var state_a: u8 = 0;
|
|
147
|
+
var state_b: u8 = 0;
|
|
148
|
+
const embedded_a = try std.testing.allocator.create(EmbeddedApp);
|
|
149
|
+
defer std.testing.allocator.destroy(embedded_a);
|
|
150
|
+
const embedded_b = try std.testing.allocator.create(EmbeddedApp);
|
|
151
|
+
defer std.testing.allocator.destroy(embedded_b);
|
|
152
|
+
embedded_a.initInPlace(.{
|
|
153
|
+
.context = &state_a,
|
|
154
|
+
.name = "embedded-font-owner-a",
|
|
155
|
+
.source = platform.WebViewSource.html("<p>A</p>"),
|
|
156
|
+
}, host_platform.platform());
|
|
157
|
+
defer embedded_a.deinit();
|
|
158
|
+
embedded_b.initInPlace(.{
|
|
159
|
+
.context = &state_b,
|
|
160
|
+
.name = "embedded-font-owner-b",
|
|
161
|
+
.source = platform.WebViewSource.html("<p>B</p>"),
|
|
162
|
+
}, host_platform.platform());
|
|
163
|
+
defer embedded_b.deinit();
|
|
164
|
+
embedded_a.runtime.owned_allocator = std.testing.allocator;
|
|
165
|
+
embedded_b.runtime.owned_allocator = std.testing.allocator;
|
|
166
|
+
|
|
167
|
+
// A registers first, B re-registers the same id: last wins, each
|
|
168
|
+
// runtime captured its own never-repeating ownership token.
|
|
169
|
+
try embedded_a.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
170
|
+
const token_a = embedded_a.runtime.canvas_font_entries[0].host_registration_token;
|
|
171
|
+
try embedded_b.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
172
|
+
const token_b = embedded_b.runtime.canvas_font_entries[0].host_registration_token;
|
|
173
|
+
try std.testing.expect(token_a != 0);
|
|
174
|
+
try std.testing.expect(token_b != 0);
|
|
175
|
+
try std.testing.expect(token_a != token_b);
|
|
176
|
+
const live = host_platform.gpuSurfaceFont(canvas.min_registered_font_id) orelse return error.TestUnexpectedResult;
|
|
177
|
+
try std.testing.expectEqual(token_b, live.token);
|
|
178
|
+
|
|
179
|
+
// A's deinit presents its stale token: recorded and accepted (the
|
|
180
|
+
// registration it owned is already gone), and provably removing
|
|
181
|
+
// nothing — B's registration is still the one the host resolves.
|
|
182
|
+
embedded_a.deinit();
|
|
183
|
+
try std.testing.expectEqual(@as(usize, 1), host_platform.gpu_surface_font_unregister_count);
|
|
184
|
+
try std.testing.expectEqual(@as(u64, canvas.min_registered_font_id), host_platform.gpu_surface_font_unregister_id);
|
|
185
|
+
try std.testing.expectEqual(token_a, host_platform.gpu_surface_font_unregister_token);
|
|
186
|
+
const survivor = host_platform.gpuSurfaceFont(canvas.min_registered_font_id) orelse return error.TestUnexpectedResult;
|
|
187
|
+
try std.testing.expectEqual(token_b, survivor.token);
|
|
188
|
+
|
|
189
|
+
// B's deinit presents the live token and the host state comes out —
|
|
190
|
+
// the guard blocks the wrong owner, not teardown itself.
|
|
191
|
+
embedded_b.deinit();
|
|
192
|
+
try std.testing.expectEqual(@as(usize, 2), host_platform.gpu_surface_font_unregister_count);
|
|
193
|
+
try std.testing.expectEqual(token_b, host_platform.gpu_surface_font_unregister_token);
|
|
194
|
+
try std.testing.expect(host_platform.gpuSurfaceFont(canvas.min_registered_font_id) == null);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
test "embedded app deinit is idempotent" {
|
|
198
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
199
|
+
var state: u8 = 0;
|
|
200
|
+
const embedded = try std.testing.allocator.create(EmbeddedApp);
|
|
201
|
+
defer std.testing.allocator.destroy(embedded);
|
|
202
|
+
embedded.initInPlace(.{
|
|
203
|
+
.context = &state,
|
|
204
|
+
.name = "embedded-deinit-twice",
|
|
205
|
+
.source = platform.WebViewSource.html("<p>Fonts</p>"),
|
|
206
|
+
}, null_platform.platform());
|
|
207
|
+
embedded.runtime.owned_allocator = std.testing.allocator;
|
|
208
|
+
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
209
|
+
|
|
210
|
+
// The documented idiom is `defer embedded.deinit()`, which must
|
|
211
|
+
// compose with an explicit early teardown: the second call is a
|
|
212
|
+
// no-op, never a double free — and never a double host unregister
|
|
213
|
+
// (the first deinit already returned the host-side registration).
|
|
214
|
+
embedded.deinit();
|
|
215
|
+
try std.testing.expectEqual(@as(usize, 0), embedded.runtime.registeredCanvasFontCount());
|
|
216
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.gpu_surface_font_unregister_count);
|
|
217
|
+
embedded.deinit();
|
|
218
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.gpu_surface_font_unregister_count);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
test "embedded app deinit returns the font registration to the platform that received it" {
|
|
222
|
+
// `Runtime.options` is public and mutable, and embedders genuinely
|
|
223
|
+
// swap the platform on a live runtime (tests in this repo do it
|
|
224
|
+
// constantly). The host-side registration must still come back to
|
|
225
|
+
// the host that RECEIVED it: each font entry captures its
|
|
226
|
+
// unregistration owner at registration time (the allocator-identity
|
|
227
|
+
// freeze, applied to the host seam), so a swap between registration
|
|
228
|
+
// and teardown retargets nothing. A deinit reading the live options
|
|
229
|
+
// instead would unregister against the swapped-in platform — the
|
|
230
|
+
// wrong host, or a null seam — and strand the original host's
|
|
231
|
+
// descriptor and caches for the process lifetime.
|
|
232
|
+
var platform_a = platform.NullPlatform.init(.{});
|
|
233
|
+
var platform_b = platform.NullPlatform.init(.{});
|
|
234
|
+
var state: u8 = 0;
|
|
235
|
+
const embedded = try std.testing.allocator.create(EmbeddedApp);
|
|
236
|
+
defer std.testing.allocator.destroy(embedded);
|
|
237
|
+
embedded.initInPlace(.{
|
|
238
|
+
.context = &state,
|
|
239
|
+
.name = "embedded-font-platform-swap",
|
|
240
|
+
.source = platform.WebViewSource.html("<p>Fonts</p>"),
|
|
241
|
+
}, platform_a.platform());
|
|
242
|
+
embedded.runtime.owned_allocator = std.testing.allocator;
|
|
243
|
+
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
244
|
+
|
|
245
|
+
// The swap under test: platform B holds the option by teardown time,
|
|
246
|
+
// but it never saw the registration.
|
|
247
|
+
embedded.runtime.options.platform = platform_b.platform();
|
|
248
|
+
embedded.deinit();
|
|
249
|
+
try std.testing.expectEqual(@as(usize, 1), platform_a.gpu_surface_font_unregister_count);
|
|
250
|
+
try std.testing.expectEqual(@as(u64, canvas.min_registered_font_id), platform_a.gpu_surface_font_unregister_id);
|
|
251
|
+
try std.testing.expectEqual(@as(usize, 0), platform_b.gpu_surface_font_unregister_count);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
test "mobile C ABI destroy returns registered font bytes through the embedded deinit" {
|
|
255
|
+
const app = native_sdk_app_create() orelse return error.TestUnexpectedResult;
|
|
256
|
+
errdefer native_sdk_app_destroy(app);
|
|
257
|
+
|
|
258
|
+
const self = mobileApp(app).?;
|
|
259
|
+
self.embedded.runtime.owned_allocator = std.testing.allocator;
|
|
260
|
+
try self.embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
261
|
+
try std.testing.expectEqual(@as(usize, 1), self.embedded.runtime.registeredCanvasFontCount());
|
|
262
|
+
|
|
263
|
+
// `native_sdk_app_destroy` is the shim's whole teardown: it routes
|
|
264
|
+
// through `EmbeddedApp.deinit` (one lifecycle owner), so the
|
|
265
|
+
// leak-checked font bytes must come back here.
|
|
266
|
+
native_sdk_app_destroy(app);
|
|
267
|
+
}
|
|
268
|
+
|
|
82
269
|
test "mobile C ABI can load packaged asset source" {
|
|
83
270
|
const app = native_sdk_app_create() orelse return error.TestUnexpectedResult;
|
|
84
271
|
defer native_sdk_app_destroy(app);
|
package/src/embed/ui_host.zig
CHANGED
|
@@ -174,6 +174,10 @@ pub fn UiAppHost(comptime AppDef: type) type {
|
|
|
174
174
|
host.disableAutomation(self);
|
|
175
175
|
self.render_memo.deinit();
|
|
176
176
|
self.ui.deinit();
|
|
177
|
+
// One lifecycle owner: the embedded app's own deinit returns
|
|
178
|
+
// its heap-owned registrations (registered canvas font
|
|
179
|
+
// bytes) before the host storage goes.
|
|
180
|
+
self.embedded.deinit();
|
|
177
181
|
std.heap.page_allocator.destroy(self);
|
|
178
182
|
}
|
|
179
183
|
|
|
@@ -24,8 +24,17 @@
|
|
|
24
24
|
* NATIVE_SDK_ALLOW_WEBVIEW2_STUB. */
|
|
25
25
|
#if defined(NATIVE_SDK_ALLOW_WEBKITGTK_STUB)
|
|
26
26
|
#define NATIVE_SDK_HAS_WEBKITGTK 0
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/* Deliberately NO compiler diagnostic in this branch — not even an
|
|
28
|
+
* informational #pragma message. The stub is the expected, configured
|
|
29
|
+
* state of every native-only Linux build, and zig renders every clang
|
|
30
|
+
* diagnostic of a failing translation unit as `error:` (its serialized
|
|
31
|
+
* clang diagnostics carry no severity into the error bundle), so an
|
|
32
|
+
* informational note here masquerades as the build-killing error the
|
|
33
|
+
* moment any unrelated real error appears anywhere in this file. The
|
|
34
|
+
* teaching lives where it is actionable instead: a stubbed host
|
|
35
|
+
* reports WebViewNotFound the moment an app actually uses a WebView.
|
|
36
|
+
*
|
|
37
|
+
* The stubbed web layer keeps the window/webview bookkeeping SHAPE so
|
|
29
38
|
* every GTK-only path (overlay reordering, focus lookups, window
|
|
30
39
|
* teardown) compiles unchanged: the web-view pointers below are opaque
|
|
31
40
|
* and permanently NULL — every path that could create one is compiled
|
|
@@ -43,6 +52,18 @@ typedef struct native_sdk_absent_content_manager WebKitUserContentManager;
|
|
|
43
52
|
#error "webkit/webkit.h not found: install the WebKitGTK 6.0 development package (libwebkitgtk-6.0-dev on Debian/Ubuntu), or define NATIVE_SDK_ALLOW_WEBKITGTK_STUB to build without the embedded web layer"
|
|
44
53
|
#endif
|
|
45
54
|
|
|
55
|
+
/* G_APPLICATION_DEFAULT_FLAGS arrived in GLib 2.74 as the
|
|
56
|
+
* non-deprecated spelling of "no flags". This host's GTK floor is 4.10
|
|
57
|
+
* (the GtkFileDialog family below), and GTK 4.10's own GLib floor is
|
|
58
|
+
* 2.72 — distros that backport GTK 4.10 onto a GLib 2.72 base (Ubuntu
|
|
59
|
+
* 22.04 derivatives) must still compile this file. Same value, gated to
|
|
60
|
+
* older GLib only; the pre-2.74 name G_APPLICATION_FLAGS_NONE is not
|
|
61
|
+
* used because it is deprecated from 2.74 on and would emit a warning
|
|
62
|
+
* exactly where the newer name exists. */
|
|
63
|
+
#if !GLIB_CHECK_VERSION(2, 74, 0)
|
|
64
|
+
#define G_APPLICATION_DEFAULT_FLAGS ((GApplicationFlags) 0)
|
|
65
|
+
#endif
|
|
66
|
+
|
|
46
67
|
#define NATIVE_SDK_MAX_WINDOWS 16
|
|
47
68
|
#define NATIVE_SDK_MAX_WEBVIEWS 16
|
|
48
69
|
#define NATIVE_SDK_MAX_TIMERS 64
|
|
@@ -326,6 +347,13 @@ struct native_sdk_gtk_host {
|
|
|
326
347
|
int did_shutdown;
|
|
327
348
|
int app_active;
|
|
328
349
|
guint frame_timer;
|
|
350
|
+
/* The quit verb's queued stop turn (native_sdk_gtk_stop), tracked
|
|
351
|
+
* like frame_timer so it can be coalesced while pending and
|
|
352
|
+
* removed at destroy — a bare g_idle_add would leave a second stop
|
|
353
|
+
* request (the shutdown handler's error path can make one) holding
|
|
354
|
+
* a freed host after the loop quits. Zero while none is queued;
|
|
355
|
+
* the idle clears it as its first act. */
|
|
356
|
+
guint stop_idle_source;
|
|
329
357
|
|
|
330
358
|
char **allowed_origins;
|
|
331
359
|
int allowed_origins_count;
|
|
@@ -523,6 +551,39 @@ static int native_sdk_valid_native_view_frame(double x, double y, double width,
|
|
|
523
551
|
return x >= 0 && y >= 0 && width >= 0 && height >= 0;
|
|
524
552
|
}
|
|
525
553
|
|
|
554
|
+
/* String-parameter byte caps for the native-view calls, mirroring the
|
|
555
|
+
* runtime's platform limits (types.zig: max_view_label_bytes 64,
|
|
556
|
+
* max_view_role_bytes 64, max_view_accessibility_label_bytes 256,
|
|
557
|
+
* max_view_text_bytes 1024, and the command-id cap 128). The runtime
|
|
558
|
+
* validates the same bounds before ever calling in, so a length past
|
|
559
|
+
* them at THIS boundary means the arguments were corrupted in transit —
|
|
560
|
+
* a caller compiled with a broken C ABI hands over shifted stack slots
|
|
561
|
+
* where a pointer poses as a length. Refuse loudly and name the field
|
|
562
|
+
* instead of memcpy-ing from a garbage pointer and faulting. */
|
|
563
|
+
#define NATIVE_SDK_MAX_VIEW_LABEL_BYTES 64
|
|
564
|
+
#define NATIVE_SDK_MAX_VIEW_ROLE_BYTES 64
|
|
565
|
+
#define NATIVE_SDK_MAX_VIEW_ACCESSIBILITY_LABEL_BYTES 256
|
|
566
|
+
#define NATIVE_SDK_MAX_VIEW_TEXT_BYTES 1024
|
|
567
|
+
#define NATIVE_SDK_MAX_VIEW_COMMAND_BYTES 128
|
|
568
|
+
|
|
569
|
+
static int native_sdk_valid_native_view_string(const char *what, size_t len, size_t max_len) {
|
|
570
|
+
if (len <= max_len) return 1;
|
|
571
|
+
g_warning("native view %s length %zu exceeds the platform cap %zu; refusing the call - "
|
|
572
|
+
"the runtime never sends this, so the arguments likely arrived corrupted "
|
|
573
|
+
"(a miscompiled C-ABI boundary hands the host shifted stack slots)",
|
|
574
|
+
what, len, max_len);
|
|
575
|
+
return 0;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
static int native_sdk_valid_native_view_strings(size_t label_len, size_t parent_len, size_t role_len, size_t accessibility_label_len, size_t text_len, size_t command_len) {
|
|
579
|
+
return native_sdk_valid_native_view_string("label", label_len, NATIVE_SDK_MAX_VIEW_LABEL_BYTES) &&
|
|
580
|
+
native_sdk_valid_native_view_string("parent", parent_len, NATIVE_SDK_MAX_VIEW_LABEL_BYTES) &&
|
|
581
|
+
native_sdk_valid_native_view_string("role", role_len, NATIVE_SDK_MAX_VIEW_ROLE_BYTES) &&
|
|
582
|
+
native_sdk_valid_native_view_string("accessibility_label", accessibility_label_len, NATIVE_SDK_MAX_VIEW_ACCESSIBILITY_LABEL_BYTES) &&
|
|
583
|
+
native_sdk_valid_native_view_string("text", text_len, NATIVE_SDK_MAX_VIEW_TEXT_BYTES) &&
|
|
584
|
+
native_sdk_valid_native_view_string("command", command_len, NATIVE_SDK_MAX_VIEW_COMMAND_BYTES);
|
|
585
|
+
}
|
|
586
|
+
|
|
526
587
|
static int native_sdk_native_extent(double value) {
|
|
527
588
|
return value > 0 ? (int)(value + 0.5) : 0;
|
|
528
589
|
}
|
|
@@ -2791,6 +2852,12 @@ void native_sdk_gtk_destroy(native_sdk_gtk_host_t *host) {
|
|
|
2791
2852
|
* anything else goes away; everything runs on this thread. */
|
|
2792
2853
|
native_sdk_audio_release(host, 1);
|
|
2793
2854
|
if (host->frame_timer) g_source_remove(host->frame_timer);
|
|
2855
|
+
/* A stop turn still queued at teardown (the loop quit before the
|
|
2856
|
+
* idle ran) must not fire into freed memory. */
|
|
2857
|
+
if (host->stop_idle_source) {
|
|
2858
|
+
g_source_remove(host->stop_idle_source);
|
|
2859
|
+
host->stop_idle_source = 0;
|
|
2860
|
+
}
|
|
2794
2861
|
for (int i = 0; i < NATIVE_SDK_MAX_TIMERS; i++) {
|
|
2795
2862
|
if (host->timers[i].in_use && host->timers[i].source) g_source_remove(host->timers[i].source);
|
|
2796
2863
|
host->timers[i].in_use = 0;
|
|
@@ -2819,7 +2886,15 @@ void native_sdk_gtk_run(native_sdk_gtk_host_t *host, native_sdk_gtk_event_callba
|
|
|
2819
2886
|
g_application_run(G_APPLICATION(host->app), 0, NULL);
|
|
2820
2887
|
}
|
|
2821
2888
|
|
|
2822
|
-
|
|
2889
|
+
/* Runs on the GLib main loop: the quit verb's deferred stop turn. The
|
|
2890
|
+
* same emitShutdown-then-quit the last window's close-request runs,
|
|
2891
|
+
* just one loop turn later (see native_sdk_gtk_stop). */
|
|
2892
|
+
static gboolean native_sdk_stop_idle(gpointer data) {
|
|
2893
|
+
native_sdk_gtk_host_t *host = data;
|
|
2894
|
+
/* This turn is running: clear the tracked id FIRST, so the source
|
|
2895
|
+
* cannot be double-removed (destroy) or wrongly treated as still
|
|
2896
|
+
* pending (a re-quit during the shutdown dispatch below). */
|
|
2897
|
+
host->stop_idle_source = 0;
|
|
2823
2898
|
if (!host->did_shutdown) {
|
|
2824
2899
|
host->did_shutdown = 1;
|
|
2825
2900
|
native_sdk_emit(host, (native_sdk_gtk_event_t){ .kind = NATIVE_SDK_GTK_EVENT_SHUTDOWN });
|
|
@@ -2829,6 +2904,33 @@ void native_sdk_gtk_stop(native_sdk_gtk_host_t *host) {
|
|
|
2829
2904
|
host->frame_timer = 0;
|
|
2830
2905
|
}
|
|
2831
2906
|
g_application_quit(G_APPLICATION(host->app));
|
|
2907
|
+
return G_SOURCE_REMOVE;
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
void native_sdk_gtk_stop(native_sdk_gtk_host_t *host) {
|
|
2911
|
+
/* Queued, never synchronous: this stop is the quit verb's landing
|
|
2912
|
+
* point, and the verb arrives MID DISPATCH (a menu command's
|
|
2913
|
+
* update returned it), so a synchronous SHUTDOWN emit would nest
|
|
2914
|
+
* the shutdown dispatch inside the requesting command's — the
|
|
2915
|
+
* session recorder commits nested events innermost-first and seals
|
|
2916
|
+
* the journal on shutdown, so the nested seal drops the command
|
|
2917
|
+
* record and replay diverges. The idle hop (the same seam the wake
|
|
2918
|
+
* and frame-request paths ride) emits the identical
|
|
2919
|
+
* emitShutdown + quit on the next loop turn, after the requesting
|
|
2920
|
+
* dispatch has committed; g_application_run keeps pumping until
|
|
2921
|
+
* the queued g_application_quit lands, so a quit that is the last
|
|
2922
|
+
* thing an app ever does still exits promptly.
|
|
2923
|
+
*
|
|
2924
|
+
* Exactly-once hygiene: once the shutdown has emitted there is
|
|
2925
|
+
* nothing left to stop, and while a stop turn is already queued a
|
|
2926
|
+
* second request coalesces into it — a second bare g_idle_add
|
|
2927
|
+
* (the shutdown handler's error path can request one) would leave
|
|
2928
|
+
* an untracked source holding this host after the loop quits and
|
|
2929
|
+
* the host is freed. The pending source id is tracked on the host
|
|
2930
|
+
* (stop_idle_source, cleared by the idle itself) and removed at
|
|
2931
|
+
* native_sdk_gtk_destroy. */
|
|
2932
|
+
if (host->did_shutdown || host->stop_idle_source) return;
|
|
2933
|
+
host->stop_idle_source = g_idle_add(native_sdk_stop_idle, host);
|
|
2832
2934
|
}
|
|
2833
2935
|
|
|
2834
2936
|
/* Runs on the GLib main loop: emit the wake event there, so the runtime
|
|
@@ -3433,6 +3535,7 @@ int native_sdk_gtk_create_view(native_sdk_gtk_host_t *host, uint64_t window_id,
|
|
|
3433
3535
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3434
3536
|
if (!win || !win->stack_root || label_len == 0 || !native_sdk_valid_native_view_frame(x, y, width, height)) return 0;
|
|
3435
3537
|
if (!native_sdk_is_supported_native_view_kind(kind)) return 0;
|
|
3538
|
+
if (!native_sdk_valid_native_view_strings(label_len, parent_len, role_len, accessibility_label_len, text_len, command_len)) return 0;
|
|
3436
3539
|
if (win->native_view_count >= NATIVE_SDK_MAX_NATIVE_VIEWS) return 0;
|
|
3437
3540
|
|
|
3438
3541
|
char *label_copy = native_sdk_strndup(label, label_len);
|
|
@@ -3620,6 +3723,12 @@ int native_sdk_gtk_present_gpu_surface_pixels(native_sdk_gtk_host_t *host, uint6
|
|
|
3620
3723
|
}
|
|
3621
3724
|
|
|
3622
3725
|
int native_sdk_gtk_update_view(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, int has_frame, double x, double y, double width, double height, int has_layer, int layer, int has_visible, int visible, int has_enabled, int enabled, int has_role, const char *role, size_t role_len, int has_accessibility_label, const char *accessibility_label, size_t accessibility_label_len, int has_text, const char *text, size_t text_len, int has_command, const char *command, size_t command_len) {
|
|
3726
|
+
if (!native_sdk_valid_native_view_strings(label_len,
|
|
3727
|
+
0,
|
|
3728
|
+
has_role ? role_len : 0,
|
|
3729
|
+
has_accessibility_label ? accessibility_label_len : 0,
|
|
3730
|
+
has_text ? text_len : 0,
|
|
3731
|
+
has_command ? command_len : 0)) return 0;
|
|
3623
3732
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3624
3733
|
char *label_copy = label_len > 0 ? native_sdk_strndup(label, label_len) : NULL;
|
|
3625
3734
|
native_sdk_gtk_native_view_t *view = native_sdk_find_native_view(win, label_copy);
|
|
@@ -9,6 +9,7 @@ pub const Error = error{
|
|
|
9
9
|
CreateFailed,
|
|
10
10
|
FocusFailed,
|
|
11
11
|
CloseFailed,
|
|
12
|
+
UnsupportedWindowClosePolicy,
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
const GtkHost = opaque {};
|
|
@@ -212,6 +213,20 @@ extern fn native_sdk_gtk_show_open_dialog(host: *GtkHost, opts: *const GtkOpenDi
|
|
|
212
213
|
extern fn native_sdk_gtk_show_save_dialog(host: *GtkHost, opts: *const GtkSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
|
|
213
214
|
extern fn native_sdk_gtk_show_message_dialog(host: *GtkHost, opts: *const GtkMessageDialogOpts) c_int;
|
|
214
215
|
|
|
216
|
+
/// The startup-window twin of the runtime's create-time `.hide` gate:
|
|
217
|
+
/// GTK reports `window_hide_on_close` false (no status item exists to
|
|
218
|
+
/// bring a hidden window back), and every seam that could accept the
|
|
219
|
+
/// declaration must refuse it loudly with the same teaching — the
|
|
220
|
+
/// generated runner refuses at comptime, the runtime refuses secondary
|
|
221
|
+
/// windows at create, and this refuses the platform-created main
|
|
222
|
+
/// window at init. Pure (no GTK externs), so the refusal is
|
|
223
|
+
/// unit-testable on every host.
|
|
224
|
+
fn refuseUnsupportedMainWindowClosePolicy(window_options: platform_mod.WindowOptions) Error!void {
|
|
225
|
+
if (window_options.close_policy != .hide) return;
|
|
226
|
+
std.debug.print("window close_policy \"hide\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \"quit\" (the default), or scope the .hide declaration to macos/windows builds\n", .{});
|
|
227
|
+
return error.UnsupportedWindowClosePolicy;
|
|
228
|
+
}
|
|
229
|
+
|
|
215
230
|
pub const LinuxPlatform = struct {
|
|
216
231
|
host: *GtkHost,
|
|
217
232
|
web_engine: platform_mod.WebEngine,
|
|
@@ -229,6 +244,14 @@ pub const LinuxPlatform = struct {
|
|
|
229
244
|
|
|
230
245
|
pub fn initWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!LinuxPlatform {
|
|
231
246
|
const window_options = app_info.resolvedMainWindow();
|
|
247
|
+
// The MAIN window is created right here, before any runtime
|
|
248
|
+
// exists, so the runtime's create-time `.hide` gate
|
|
249
|
+
// (window_storage's error.UnsupportedWindowClosePolicy) never
|
|
250
|
+
// sees it — without this twin refusal a direct-SDK or
|
|
251
|
+
// custom-runner user declaring `.hide` silently got
|
|
252
|
+
// quit-on-close. Same loud line as the generated runner's
|
|
253
|
+
// comptime check, at the last seam that can hold it.
|
|
254
|
+
try refuseUnsupportedMainWindowClosePolicy(window_options);
|
|
232
255
|
const window_title = window_options.resolvedTitle(app_info.app_name);
|
|
233
256
|
const frame = window_options.default_frame;
|
|
234
257
|
const host = native_sdk_gtk_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;
|
|
@@ -270,6 +293,8 @@ pub const LinuxPlatform = struct {
|
|
|
270
293
|
.focus_window_fn = focusWindow,
|
|
271
294
|
.close_window_fn = closeWindow,
|
|
272
295
|
.minimize_window_fn = minimizeWindow,
|
|
296
|
+
.show_window_fn = showWindow,
|
|
297
|
+
.quit_app_fn = quitApp,
|
|
273
298
|
.start_window_drag_fn = startWindowDrag,
|
|
274
299
|
.set_window_drag_regions_fn = setWindowDragRegions,
|
|
275
300
|
.window_chrome_fn = windowChrome,
|
|
@@ -355,6 +380,10 @@ pub const LinuxPlatform = struct {
|
|
|
355
380
|
// deck's glass rests honestly instead of dancing on fakes.
|
|
356
381
|
.audio_spectrum => self.web_engine == .system and audioSpectrumAvailable(self.host),
|
|
357
382
|
.tray => false,
|
|
383
|
+
// No tray means no affordance to bring a policy-hidden
|
|
384
|
+
// window back — reporting support would strand windows, so
|
|
385
|
+
// GTK refuses `close_policy = .hide` at create instead.
|
|
386
|
+
.window_hide_on_close => false,
|
|
358
387
|
// Native scroll drivers, native context menus, and app-owned
|
|
359
388
|
// view-surface adoption are macOS-only today; GTK keeps the
|
|
360
389
|
// engine's wheel physics and has no popover-menu presenter
|
|
@@ -672,6 +701,15 @@ fn requestFrame(context: ?*anyopaque) anyerror!void {
|
|
|
672
701
|
native_sdk_gtk_request_frame(self.host);
|
|
673
702
|
}
|
|
674
703
|
|
|
704
|
+
/// Headless image codec for session replay: the SAME gdk-pixbuf decode
|
|
705
|
+
/// a live host serves (see `decodeImage` below — a context-free
|
|
706
|
+
/// bytes-to-pixels call, no window, no run loop), so journaled image
|
|
707
|
+
/// bytes re-register the identical pixels under a headless replay on
|
|
708
|
+
/// the same platform.
|
|
709
|
+
pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {
|
|
710
|
+
services.decode_image_fn = decodeImage;
|
|
711
|
+
}
|
|
712
|
+
|
|
675
713
|
/// gdk-pixbuf-backed image decoding (PNG, JPEG, ... — whatever loaders
|
|
676
714
|
/// the system ships) into straight-alpha RGBA8.
|
|
677
715
|
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
|
|
@@ -731,6 +769,26 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
|
|
|
731
769
|
if (native_sdk_gtk_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
732
770
|
}
|
|
733
771
|
|
|
772
|
+
/// GTK has no hide-on-close (see `window_hide_on_close`), so show is
|
|
773
|
+
/// honestly the present verb: bring the window to the front and give
|
|
774
|
+
/// it focus — the same call the focus service makes.
|
|
775
|
+
fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
776
|
+
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
777
|
+
if (native_sdk_gtk_focus_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/// The graceful quit: the same emitShutdown + g_application_quit the
|
|
781
|
+
/// last window's close-request runs, queued to the NEXT loop turn —
|
|
782
|
+
/// this verb is requested mid dispatch (the command whose update
|
|
783
|
+
/// returned it is still being dispatched), and `app_shutdown` must
|
|
784
|
+
/// emit only after that dispatch returns, or a recording session
|
|
785
|
+
/// seals its journal before the requesting command commits (the
|
|
786
|
+
/// command record is lost and replay diverges).
|
|
787
|
+
fn quitApp(context: ?*anyopaque) anyerror!void {
|
|
788
|
+
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
789
|
+
native_sdk_gtk_stop(self.host);
|
|
790
|
+
}
|
|
791
|
+
|
|
734
792
|
fn startWindowDrag(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
735
793
|
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
736
794
|
if (native_sdk_gtk_start_window_drag(self.host, window_id) == 0) return error.WindowNotFound;
|
|
@@ -1517,3 +1575,16 @@ fn viewKindInt(kind: platform_mod.ViewKind) c_int {
|
|
|
1517
1575
|
test "linux platform module exports type" {
|
|
1518
1576
|
_ = LinuxPlatform;
|
|
1519
1577
|
}
|
|
1578
|
+
|
|
1579
|
+
test "linux refuses a .hide main window at platform init instead of a silent quit-on-close" {
|
|
1580
|
+
// The pre-created MAIN window never passes through the runtime's
|
|
1581
|
+
// create gate, so the platform's init gate must hold the same
|
|
1582
|
+
// line. The gate sees exactly the options `initWithOptions`
|
|
1583
|
+
// resolves from the caller's AppInfo.
|
|
1584
|
+
const hide_app: platform_mod.AppInfo = .{ .app_name = "player", .main_window = .{ .close_policy = .hide } };
|
|
1585
|
+
try std.testing.expectError(error.UnsupportedWindowClosePolicy, refuseUnsupportedMainWindowClosePolicy(hide_app.resolvedMainWindow()));
|
|
1586
|
+
// The default (.quit) and every other declaration pass untouched —
|
|
1587
|
+
// the refusal is the .hide declaration's, not the init path's.
|
|
1588
|
+
const quit_app: platform_mod.AppInfo = .{ .app_name = "player" };
|
|
1589
|
+
try refuseUnsupportedMainWindowClosePolicy(quit_app.resolvedMainWindow());
|
|
1590
|
+
}
|
|
@@ -76,6 +76,17 @@ typedef enum {
|
|
|
76
76
|
NATIVE_SDK_APPKIT_GPU_INPUT_IME_COMMIT_COMPOSITION = 9,
|
|
77
77
|
NATIVE_SDK_APPKIT_GPU_INPUT_IME_CANCEL_COMPOSITION = 10,
|
|
78
78
|
NATIVE_SDK_APPKIT_GPU_INPUT_POINTER_CANCEL = 11,
|
|
79
|
+
/* Trackpad pinch phases (magnifyWithEvent:). The event's `scale`
|
|
80
|
+
* field carries the per-event magnification DELTA on PINCH_CHANGE —
|
|
81
|
+
* raw NSEvent.magnification, which IS the multiplicative per-event
|
|
82
|
+
* delta per the browser-engine convention (see the doctrine note at
|
|
83
|
+
* magnifyWithEvent: in appkit_host.m); cumulative gesture scale is
|
|
84
|
+
* the product of (1 + delta); 0 on begin/end. The pointer anchor rides
|
|
85
|
+
* x/y (the event's locationInWindow — gesture events report the
|
|
86
|
+
* pointer location, not a midpoint between the fingers). */
|
|
87
|
+
NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_BEGIN = 12,
|
|
88
|
+
NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_CHANGE = 13,
|
|
89
|
+
NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_END = 14,
|
|
79
90
|
} native_sdk_appkit_gpu_input_kind_t;
|
|
80
91
|
|
|
81
92
|
typedef enum {
|
|
@@ -224,6 +235,10 @@ typedef struct {
|
|
|
224
235
|
double y;
|
|
225
236
|
int open;
|
|
226
237
|
int focused;
|
|
238
|
+
/* WINDOW_FRAME: nonzero while the window is alive but hidden by
|
|
239
|
+
* its close_policy (.hide intercepted a user close). open stays 1
|
|
240
|
+
* for the window's whole hidden stretch. */
|
|
241
|
+
int hidden;
|
|
227
242
|
const char *label;
|
|
228
243
|
size_t label_len;
|
|
229
244
|
const char *shortcut_id;
|
|
@@ -331,7 +346,20 @@ void native_sdk_appkit_set_dock_icon_rgba(native_sdk_appkit_host_t *host, const
|
|
|
331
346
|
// keeping the pre-masking behavior (icon shown unshaped) as the floor.
|
|
332
347
|
void native_sdk_appkit_set_dock_icon_file(native_sdk_appkit_host_t *host, const char *path, size_t path_len);
|
|
333
348
|
void native_sdk_appkit_run(native_sdk_appkit_host_t *host, native_sdk_appkit_event_callback_t callback, void *context);
|
|
349
|
+
// The host-side shutdown request: a failed event emit asks the host to
|
|
350
|
+
// deliver SHUTDOWN and stop. While the run loop is live the delivery is
|
|
351
|
+
// queued to the next turn; before [NSApp run] it happens inline (the
|
|
352
|
+
// failed-START precedent — runWithCallback's didShutdown check honors
|
|
353
|
+
// it before the loop would start).
|
|
334
354
|
void native_sdk_appkit_stop(native_sdk_appkit_host_t *host);
|
|
355
|
+
// The quit VERB's landing point (fx.quitApp): always deferred, never
|
|
356
|
+
// inline — the verb arrives mid dispatch, and the shutdown must emit
|
|
357
|
+
// only after the requesting dispatch has committed to the session
|
|
358
|
+
// recorder. While the run loop is live the deferral is a main-queue
|
|
359
|
+
// hop; before [NSApp run] the request parks as a pending flag that
|
|
360
|
+
// runWithCallback drains at top level after the pre-run dispatch that
|
|
361
|
+
// carried it returns.
|
|
362
|
+
void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host);
|
|
335
363
|
void native_sdk_appkit_load_webview(native_sdk_appkit_host_t *host, const char *source, size_t source_len, int source_kind, const char *asset_root, size_t asset_root_len, const char *asset_entry, size_t asset_entry_len, const char *asset_origin, size_t asset_origin_len, int spa_fallback);
|
|
336
364
|
void native_sdk_appkit_load_window_webview(native_sdk_appkit_host_t *host, uint64_t window_id, const char *source, size_t source_len, int source_kind, const char *asset_root, size_t asset_root_len, const char *asset_entry, size_t asset_entry_len, const char *asset_origin, size_t asset_origin_len, int spa_fallback);
|
|
337
365
|
void native_sdk_appkit_set_bridge_callback(native_sdk_appkit_host_t *host, native_sdk_appkit_bridge_callback_t callback, void *context);
|
|
@@ -353,6 +381,17 @@ int native_sdk_appkit_close_window(native_sdk_appkit_host_t *host, uint64_t wind
|
|
|
353
381
|
// window controls on chromeless windows. Returns 0 when the window id
|
|
354
382
|
// is unknown.
|
|
355
383
|
int native_sdk_appkit_minimize_window(native_sdk_appkit_host_t *host, uint64_t window_id);
|
|
384
|
+
// The show verb: bring the window back to the glass and activate the
|
|
385
|
+
// app (deminiaturize + makeKeyAndOrderFront) — the counterpart to a
|
|
386
|
+
// close_policy .hide hide, and the tray-menu "Open" consequence.
|
|
387
|
+
// Returns 0 when the window id is unknown.
|
|
388
|
+
int native_sdk_appkit_show_window(native_sdk_appkit_host_t *host, uint64_t window_id);
|
|
389
|
+
// What the user's close affordance does to this window: 0 = quit (the
|
|
390
|
+
// default: really close; last close follows app exit semantics),
|
|
391
|
+
// 1 = hide (order out and keep running — the menu-bar-app shape).
|
|
392
|
+
// Applied right after create, like the content min-size floor.
|
|
393
|
+
// Returns 0 when the window id is unknown.
|
|
394
|
+
int native_sdk_appkit_set_window_close_policy(native_sdk_appkit_host_t *host, uint64_t window_id, int close_policy);
|
|
356
395
|
// Window-drag region channel: called during dispatch of the pointer-down
|
|
357
396
|
// that starts the gesture. Single click hands the event to
|
|
358
397
|
// -[NSWindow performWindowDragWithEvent:] (moves only on actual
|
|
@@ -475,8 +514,26 @@ int native_sdk_appkit_measure_text_advances(uint64_t font_id, double size, const
|
|
|
475
514
|
|
|
476
515
|
// Register engine-validated TrueType bytes under a canvas font id so
|
|
477
516
|
// measurement and packet text drawing resolve the id to this exact face.
|
|
478
|
-
// Returns 1 on success, 0 when CoreText rejects the data.
|
|
479
|
-
|
|
517
|
+
// Returns 1 on success, 0 when CoreText rejects the data. On success
|
|
518
|
+
// `*out_token` is the registration's ownership token — the handle the
|
|
519
|
+
// caller must present to native_sdk_appkit_unregister_font, so teardown
|
|
520
|
+
// removes exactly this registration (font ids are per-runtime while
|
|
521
|
+
// host font state is per-process: a later runtime may re-register the
|
|
522
|
+
// id, and its live face must survive the older owner's teardown). Hosts
|
|
523
|
+
// that retain no font state (the Chromium engine's stateless accept)
|
|
524
|
+
// write 0: nothing installed, nothing a token could own.
|
|
525
|
+
int native_sdk_appkit_register_font(uint64_t font_id, const uint8_t *bytes, size_t bytes_len, uint64_t *out_token);
|
|
526
|
+
// Drop the per-id state a registration installed (the descriptor and its
|
|
527
|
+
// caches) — the teardown twin Runtime.deinit calls, because font ids are
|
|
528
|
+
// per-runtime while this host's font state is per-process. `token` must
|
|
529
|
+
// be the value the matching register call reported: state is removed
|
|
530
|
+
// only while the id's current registration still carries it, so an
|
|
531
|
+
// older runtime's deinit never tears down a newer runtime's live face
|
|
532
|
+
// under a shared id. A stale token — like an id with no installed
|
|
533
|
+
// descriptor — is a no-op accept: the registration the token owned is
|
|
534
|
+
// already gone, which is the state the caller asked for. Returns 1 on
|
|
535
|
+
// accept, 0 only for the invalid id 0.
|
|
536
|
+
int native_sdk_appkit_unregister_font(uint64_t font_id, uint64_t token);
|
|
480
537
|
/* Decode encoded image bytes (PNG, JPEG, ... — whatever ImageIO supports)
|
|
481
538
|
* through CGImageSource into tightly packed, row-major, straight-alpha
|
|
482
539
|
* (non-premultiplied) RGBA8 written into `pixels`. Returns 1 on success
|