@native-sdk/cli 0.5.3 → 0.6.0
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 +91 -2
- package/build.zig +756 -5
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +19 -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 +416 -9
- package/packages/core/sdk/core.ts +706 -5
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +3187 -264
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +42 -4
- package/skill-data/ts-core/SKILL.md +13 -3
- package/src/app_runner/root.zig +112 -10
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/tests.zig +119 -1
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +639 -16
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +351 -7
- package/src/platform/macos/appkit_host.h +152 -8
- package/src/platform/macos/appkit_host.m +1816 -100
- package/src/platform/macos/cef_host.mm +372 -11
- package/src/platform/macos/root.zig +379 -11
- package/src/platform/null_platform.zig +696 -9
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +42 -0
- package/src/platform/types.zig +524 -18
- package/src/platform/windows/root.zig +432 -9
- package/src/platform/windows/webview2_host.cpp +482 -45
- 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/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +535 -12
- package/src/primitives/canvas/ui_markup.zig +253 -36
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
- package/src/primitives/canvas/ui_markup_contract.zig +89 -6
- package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +178 -9
- package/src/primitives/canvas/ui_markup_view.zig +220 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
- package/src/primitives/canvas/ui_schema.zig +110 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -10
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +23 -0
- package/src/runtime/api.zig +76 -5
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +8 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +131 -13
- package/src/runtime/effects.zig +8136 -180
- package/src/runtime/effects_channel_tests.zig +3519 -0
- 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_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +167 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +42 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +36 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +432 -62
- package/src/runtime/session_record.zig +43 -2
- package/src/runtime/session_replay.zig +556 -20
- package/src/runtime/session_tests.zig +2087 -1
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -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 +8 -0
- package/src/runtime/ts_core_host.zig +1320 -45
- package/src/runtime/ts_core_host_tests.zig +1100 -1
- package/src/runtime/ts_ui_app.zig +23 -5
- package/src/runtime/ui_app.zig +2444 -69
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +736 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +77 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +62 -1
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +244 -8
|
@@ -29,6 +29,8 @@ typedef enum {
|
|
|
29
29
|
NATIVE_SDK_GTK_EVENT_TIMER = 15,
|
|
30
30
|
NATIVE_SDK_GTK_EVENT_APPEARANCE = 16,
|
|
31
31
|
NATIVE_SDK_GTK_EVENT_AUDIO = 17,
|
|
32
|
+
NATIVE_SDK_GTK_EVENT_CONTEXT_MENU_ACTION = 18,
|
|
33
|
+
NATIVE_SDK_GTK_EVENT_VIEW_FOCUSED = 19,
|
|
32
34
|
} native_sdk_gtk_event_kind_t;
|
|
33
35
|
|
|
34
36
|
typedef struct {
|
|
@@ -89,8 +91,23 @@ typedef struct {
|
|
|
89
91
|
* 50 Hz..16 kHz buckets, each linear-in-dB from -60 dBFS at 0 to
|
|
90
92
|
* full scale at 255. All zeros on every other event kind. */
|
|
91
93
|
uint8_t audio_bands[32];
|
|
94
|
+
/* CONTEXT_MENU_ACTION payload (the macOS host's field names):
|
|
95
|
+
* widget_id echoes the request's correlation token, menu_item_id is
|
|
96
|
+
* the selected item's id (0 = dismissed without a selection). */
|
|
97
|
+
uint64_t widget_id;
|
|
98
|
+
uint32_t menu_item_id;
|
|
92
99
|
} native_sdk_gtk_event_t;
|
|
93
100
|
|
|
101
|
+
/* One context-menu entry crossing the C ABI (the same shape the macOS
|
|
102
|
+
* and Windows hosts take). */
|
|
103
|
+
typedef struct {
|
|
104
|
+
uint32_t item_id;
|
|
105
|
+
const char *label;
|
|
106
|
+
size_t label_len;
|
|
107
|
+
int enabled;
|
|
108
|
+
int separator;
|
|
109
|
+
} native_sdk_gtk_context_menu_item_t;
|
|
110
|
+
|
|
94
111
|
typedef void (*native_sdk_gtk_event_callback_t)(void *context, const native_sdk_gtk_event_t *event);
|
|
95
112
|
typedef void (*native_sdk_gtk_bridge_callback_t)(void *context, uint64_t window_id, const char *webview_label, size_t webview_label_len, const char *message, size_t message_len, const char *origin, size_t origin_len);
|
|
96
113
|
|
|
@@ -211,6 +228,14 @@ int native_sdk_gtk_set_view_visible(native_sdk_gtk_host_t *host, uint64_t window
|
|
|
211
228
|
int native_sdk_gtk_focus_view(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len);
|
|
212
229
|
int native_sdk_gtk_close_view(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len);
|
|
213
230
|
int native_sdk_gtk_request_gpu_surface_frame(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len);
|
|
231
|
+
/* Present a native context menu (GtkPopoverMenu) pointing at the given
|
|
232
|
+
* view-local LOGICAL x/y — the same coordinate space the gpu-surface
|
|
233
|
+
* input path reports pointer events in, which is the pointing-rect space
|
|
234
|
+
* GTK expects (widget-local logical coordinates of the popover's
|
|
235
|
+
* parent). The selection (or dismissal) is reported asynchronously as a
|
|
236
|
+
* CONTEXT_MENU_ACTION event echoing `token`. Returns 0 when the window
|
|
237
|
+
* is unknown or `count` is 0. */
|
|
238
|
+
int native_sdk_gtk_show_context_menu(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, double x, double y, uint64_t token, const native_sdk_gtk_context_menu_item_t *items, size_t count);
|
|
214
239
|
int native_sdk_gtk_present_gpu_surface_pixels(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, size_t width, size_t height, double scale, int has_dirty_rect, double dirty_x, double dirty_y, double dirty_width, double dirty_height, const uint8_t *rgba8, size_t rgba8_len);
|
|
215
240
|
int native_sdk_gtk_create_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, const char *url, size_t url_len, double x, double y, double width, double height, int layer, int transparent, int bridge_enabled);
|
|
216
241
|
int native_sdk_gtk_set_webview_frame(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, double x, double y, double width, double height);
|
|
@@ -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 {};
|
|
@@ -32,6 +33,8 @@ const GtkEventKind = enum(c_int) {
|
|
|
32
33
|
timer = 15,
|
|
33
34
|
appearance = 16,
|
|
34
35
|
audio = 17,
|
|
36
|
+
context_menu_action = 18,
|
|
37
|
+
view_focused = 19,
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
const GtkEvent = extern struct {
|
|
@@ -91,6 +94,12 @@ const GtkEvent = extern struct {
|
|
|
91
94
|
/// documented scale (log-spaced 50 Hz..16 kHz buckets, linear-in-dB
|
|
92
95
|
/// from -60 dBFS at 0 to full scale at 255). Zeros elsewhere.
|
|
93
96
|
audio_bands: [platform_mod.audio_spectrum_band_count]u8,
|
|
97
|
+
/// CONTEXT_MENU_ACTION payload (same field names as the macOS and
|
|
98
|
+
/// Windows hosts): `widget_id` echoes the request's correlation
|
|
99
|
+
/// token and `menu_item_id` is the selected item's id (0 = dismissed
|
|
100
|
+
/// without a selection).
|
|
101
|
+
widget_id: u64,
|
|
102
|
+
menu_item_id: u32,
|
|
94
103
|
};
|
|
95
104
|
|
|
96
105
|
const GtkCallback = *const fn (context: ?*anyopaque, event: *const GtkEvent) callconv(.c) void;
|
|
@@ -164,6 +173,18 @@ extern fn native_sdk_gtk_clipboard_read(host: *GtkHost, buffer: [*]u8, buffer_le
|
|
|
164
173
|
extern fn native_sdk_gtk_clipboard_write(host: *GtkHost, text: [*]const u8, text_len: usize) void;
|
|
165
174
|
extern fn native_sdk_gtk_clipboard_read_data(host: *GtkHost, mime_type: [*]const u8, mime_type_len: usize, buffer: [*]u8, buffer_len: usize) usize;
|
|
166
175
|
extern fn native_sdk_gtk_clipboard_write_data(host: *GtkHost, mime_type: [*]const u8, mime_type_len: usize, bytes: [*]const u8, bytes_len: usize) c_int;
|
|
176
|
+
extern fn native_sdk_gtk_show_context_menu(host: *GtkHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, token: u64, items: [*]const GtkContextMenuItem, count: usize) c_int;
|
|
177
|
+
|
|
178
|
+
/// One context-menu entry crossing the C ABI (the same shape the macOS
|
|
179
|
+
/// and Windows hosts take): labels ride as pointer+length, flags as
|
|
180
|
+
/// ints.
|
|
181
|
+
const GtkContextMenuItem = extern struct {
|
|
182
|
+
item_id: u32,
|
|
183
|
+
label: [*]const u8,
|
|
184
|
+
label_len: usize,
|
|
185
|
+
enabled: c_int,
|
|
186
|
+
separator: c_int,
|
|
187
|
+
};
|
|
167
188
|
|
|
168
189
|
const GtkOpenDialogOpts = extern struct {
|
|
169
190
|
title: [*]const u8,
|
|
@@ -212,12 +233,38 @@ extern fn native_sdk_gtk_show_open_dialog(host: *GtkHost, opts: *const GtkOpenDi
|
|
|
212
233
|
extern fn native_sdk_gtk_show_save_dialog(host: *GtkHost, opts: *const GtkSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
|
|
213
234
|
extern fn native_sdk_gtk_show_message_dialog(host: *GtkHost, opts: *const GtkMessageDialogOpts) c_int;
|
|
214
235
|
|
|
236
|
+
/// The startup-window twin of the runtime's create-time `.hide` gate:
|
|
237
|
+
/// GTK reports `window_hide_on_close` false (no status item exists to
|
|
238
|
+
/// bring a hidden window back), and every seam that could accept the
|
|
239
|
+
/// declaration must refuse it loudly with the same teaching — the
|
|
240
|
+
/// generated runner refuses at comptime, the runtime refuses secondary
|
|
241
|
+
/// windows at create, and this refuses the platform-created main
|
|
242
|
+
/// window at init. Pure (no GTK externs), so the refusal is
|
|
243
|
+
/// unit-testable on every host.
|
|
244
|
+
fn refuseUnsupportedMainWindowClosePolicy(window_options: platform_mod.WindowOptions) Error!void {
|
|
245
|
+
if (window_options.close_policy != .hide) return;
|
|
246
|
+
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", .{});
|
|
247
|
+
return error.UnsupportedWindowClosePolicy;
|
|
248
|
+
}
|
|
249
|
+
|
|
215
250
|
pub const LinuxPlatform = struct {
|
|
216
251
|
host: *GtkHost,
|
|
217
252
|
web_engine: platform_mod.WebEngine,
|
|
218
253
|
app_info: platform_mod.AppInfo,
|
|
219
254
|
surface_value: platform_mod.Surface,
|
|
220
255
|
state: RunState = .{},
|
|
256
|
+
/// Latched when the runtime's effects teardown abandons an
|
|
257
|
+
/// in-flight channel `wake_fn` call (see
|
|
258
|
+
/// `PlatformServices.note_channel_wake_abandoned_fn`): the stale
|
|
259
|
+
/// call still holds this platform as its context and may execute
|
|
260
|
+
/// into it at any later time, so `deinit` must skip destruction
|
|
261
|
+
/// and leak the host, process-lived — and the wrapper struct the
|
|
262
|
+
/// context actually points at (the wake thunk casts to
|
|
263
|
+
/// `*LinuxPlatform` before reaching the host) must outlive the
|
|
264
|
+
/// call too, which is why runners allocate it through
|
|
265
|
+
/// `createWithOptions` and retire it through `destroy`, the
|
|
266
|
+
/// latch-gated free.
|
|
267
|
+
channel_wake_abandoned: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
221
268
|
|
|
222
269
|
pub fn init(title: []const u8, size: geometry.SizeF) Error!LinuxPlatform {
|
|
223
270
|
return initWithEngine(title, size, .system);
|
|
@@ -229,6 +276,14 @@ pub const LinuxPlatform = struct {
|
|
|
229
276
|
|
|
230
277
|
pub fn initWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!LinuxPlatform {
|
|
231
278
|
const window_options = app_info.resolvedMainWindow();
|
|
279
|
+
// The MAIN window is created right here, before any runtime
|
|
280
|
+
// exists, so the runtime's create-time `.hide` gate
|
|
281
|
+
// (window_storage's error.UnsupportedWindowClosePolicy) never
|
|
282
|
+
// sees it — without this twin refusal a direct-SDK or
|
|
283
|
+
// custom-runner user declaring `.hide` silently got
|
|
284
|
+
// quit-on-close. Same loud line as the generated runner's
|
|
285
|
+
// comptime check, at the last seam that can hold it.
|
|
286
|
+
try refuseUnsupportedMainWindowClosePolicy(window_options);
|
|
232
287
|
const window_title = window_options.resolvedTitle(app_info.app_name);
|
|
233
288
|
const frame = window_options.default_frame;
|
|
234
289
|
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;
|
|
@@ -244,7 +299,44 @@ pub const LinuxPlatform = struct {
|
|
|
244
299
|
};
|
|
245
300
|
}
|
|
246
301
|
|
|
302
|
+
/// Heap-allocate the wrapper (process allocator) and initialize it
|
|
303
|
+
/// in place. Runners must use this over a stack `initWithOptions`
|
|
304
|
+
/// value: `platform().services.context` is this wrapper's ADDRESS,
|
|
305
|
+
/// worker threads dereference it inside the channel wake path, and
|
|
306
|
+
/// a wake call teardown abandons may do so at any later time —
|
|
307
|
+
/// after a runner's stack frame would have unwound. Pair with
|
|
308
|
+
/// `destroy`, the latch-gated free.
|
|
309
|
+
pub fn createWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!*LinuxPlatform {
|
|
310
|
+
const self = std.heap.page_allocator.create(LinuxPlatform) catch return error.CreateFailed;
|
|
311
|
+
errdefer std.heap.page_allocator.destroy(self);
|
|
312
|
+
self.* = try initWithOptions(size, web_engine, app_info);
|
|
313
|
+
return self;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/// `deinit` plus the wrapper's own storage, gated by the same
|
|
317
|
+
/// latch: an abandoned channel wake call dereferences this wrapper
|
|
318
|
+
/// (its context) BEFORE it reaches the native host, so on abandon
|
|
319
|
+
/// both are leaked, process-lived — deinit-gating extended to
|
|
320
|
+
/// lifetime-gating, the honest completion of the abandoned-worker
|
|
321
|
+
/// idiom. No cross-thread race on the gate: the latch is set
|
|
322
|
+
/// synchronously on the loop thread during effects teardown, which
|
|
323
|
+
/// runs before the runner's deferred destroy.
|
|
324
|
+
pub fn destroy(self: *LinuxPlatform) void {
|
|
325
|
+
self.deinit();
|
|
326
|
+
if (self.channel_wake_abandoned.load(.seq_cst)) return;
|
|
327
|
+
std.heap.page_allocator.destroy(self);
|
|
328
|
+
}
|
|
329
|
+
|
|
247
330
|
pub fn deinit(self: *LinuxPlatform) void {
|
|
331
|
+
// An abandoned channel wake call may still enter this host at
|
|
332
|
+
// any later time (see `channel_wake_abandoned`): destroying it
|
|
333
|
+
// would turn that stale call into a use-after-free, so the
|
|
334
|
+
// host is deliberately leaked, process-lived — the
|
|
335
|
+
// abandoned-worker idiom, applied to the platform itself.
|
|
336
|
+
if (self.channel_wake_abandoned.load(.seq_cst)) {
|
|
337
|
+
std.debug.print("linux platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it (and the wrapper it enters through), process-lived, so the stale call stays safe\n", .{});
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
248
340
|
native_sdk_gtk_destroy(self.host);
|
|
249
341
|
}
|
|
250
342
|
|
|
@@ -270,6 +362,8 @@ pub const LinuxPlatform = struct {
|
|
|
270
362
|
.focus_window_fn = focusWindow,
|
|
271
363
|
.close_window_fn = closeWindow,
|
|
272
364
|
.minimize_window_fn = minimizeWindow,
|
|
365
|
+
.show_window_fn = showWindow,
|
|
366
|
+
.quit_app_fn = quitApp,
|
|
273
367
|
.start_window_drag_fn = startWindowDrag,
|
|
274
368
|
.set_window_drag_regions_fn = setWindowDragRegions,
|
|
275
369
|
.window_chrome_fn = windowChrome,
|
|
@@ -281,6 +375,7 @@ pub const LinuxPlatform = struct {
|
|
|
281
375
|
.close_view_fn = closeView,
|
|
282
376
|
.request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
|
|
283
377
|
.present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
|
|
378
|
+
.show_context_menu_fn = showContextMenu,
|
|
284
379
|
.create_webview_fn = createWebView,
|
|
285
380
|
.set_webview_frame_fn = setWebViewFrame,
|
|
286
381
|
.navigate_webview_fn = navigateWebView,
|
|
@@ -305,6 +400,11 @@ pub const LinuxPlatform = struct {
|
|
|
305
400
|
.audio_stop_fn = audioStop,
|
|
306
401
|
.audio_seek_fn = audioSeek,
|
|
307
402
|
.audio_set_volume_fn = audioSetVolume,
|
|
403
|
+
// The video load verbs are teaching refusals (see
|
|
404
|
+
// `videoLoad`); the transport verbs stay null — the
|
|
405
|
+
// channel never activates without a successful load.
|
|
406
|
+
.video_load_fn = videoLoad,
|
|
407
|
+
.video_load_url_fn = videoLoadUrl,
|
|
308
408
|
.create_tray_fn = createTray,
|
|
309
409
|
.update_tray_menu_fn = updateTrayMenu,
|
|
310
410
|
.remove_tray_fn = removeTray,
|
|
@@ -315,6 +415,7 @@ pub const LinuxPlatform = struct {
|
|
|
315
415
|
.start_timer_fn = startTimer,
|
|
316
416
|
.cancel_timer_fn = cancelTimer,
|
|
317
417
|
.wake_fn = wake,
|
|
418
|
+
.note_channel_wake_abandoned_fn = noteChannelWakeAbandoned,
|
|
318
419
|
.request_frame_fn = requestFrame,
|
|
319
420
|
.decode_image_fn = decodeImage,
|
|
320
421
|
},
|
|
@@ -355,11 +456,26 @@ pub const LinuxPlatform = struct {
|
|
|
355
456
|
// deck's glass rests honestly instead of dancing on fakes.
|
|
356
457
|
.audio_spectrum => self.web_engine == .system and audioSpectrumAvailable(self.host),
|
|
357
458
|
.tray => false,
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
459
|
+
// No tray means no affordance to bring a policy-hidden
|
|
460
|
+
// window back — reporting support would strand windows, so
|
|
461
|
+
// GTK refuses `close_policy = .hide` at create instead.
|
|
462
|
+
.window_hide_on_close => false,
|
|
463
|
+
// Native context menus present through GtkPopoverMenu (a
|
|
464
|
+
// GMenu pointed at the click, dispatching through a
|
|
465
|
+
// per-invocation action group), riding the same
|
|
466
|
+
// system-engine gate as the other native surfaces.
|
|
467
|
+
.context_menus => self.web_engine == .system,
|
|
468
|
+
// Native scroll drivers and app-owned view-surface adoption
|
|
469
|
+
// are macOS-only today; GTK keeps the engine's wheel
|
|
470
|
+
// physics.
|
|
471
|
+
.gpu_surface_scroll_drivers, .view_surface_adoption => false,
|
|
472
|
+
// Video decode (a GStreamer appsink feeding the
|
|
473
|
+
// media-surface texture channel) is not implemented yet:
|
|
474
|
+
// an honest false rather than a half-implemented player.
|
|
475
|
+
// The load verbs teach and refuse (see `videoLoad`), so an
|
|
476
|
+
// app that skips the capability check still learns exactly
|
|
477
|
+
// what is missing.
|
|
478
|
+
.video_playback => false,
|
|
363
479
|
};
|
|
364
480
|
}
|
|
365
481
|
|
|
@@ -456,6 +572,10 @@ fn gtkCallback(context: ?*anyopaque, event: *const GtkEvent) callconv(.c) void {
|
|
|
456
572
|
.focused = event.focused != 0,
|
|
457
573
|
} });
|
|
458
574
|
},
|
|
575
|
+
.view_focused => state.emit(.{ .view_focused = .{
|
|
576
|
+
.window_id = event.window_id,
|
|
577
|
+
.label = event.view_label[0..event.view_label_len],
|
|
578
|
+
} }),
|
|
459
579
|
.shortcut => state.emit(.{ .shortcut = .{
|
|
460
580
|
.id = event.shortcut_id[0..event.shortcut_id_len],
|
|
461
581
|
.key = event.shortcut_key[0..event.shortcut_key_len],
|
|
@@ -522,9 +642,24 @@ fn gtkCallback(context: ?*anyopaque, event: *const GtkEvent) callconv(.c) void {
|
|
|
522
642
|
.buffering = event.audio_buffering != 0,
|
|
523
643
|
.bands = event.audio_bands,
|
|
524
644
|
} }),
|
|
645
|
+
.context_menu_action => state.emit(.{ .context_menu_action = contextMenuActionEventFromGtkEvent(event) }),
|
|
525
646
|
}
|
|
526
647
|
}
|
|
527
648
|
|
|
649
|
+
/// Pure event mapping (no host calls), unit-testable on every build
|
|
650
|
+
/// host: the C event's `widget_id` is the request's correlation token
|
|
651
|
+
/// and `menu_item_id` the selected item (0 = dismissed) — the same
|
|
652
|
+
/// payload contract as the macOS and Windows hosts, so replay is
|
|
653
|
+
/// shape-identical.
|
|
654
|
+
fn contextMenuActionEventFromGtkEvent(event: *const GtkEvent) platform_mod.ContextMenuActionEvent {
|
|
655
|
+
return .{
|
|
656
|
+
.window_id = event.window_id,
|
|
657
|
+
.view_label = event.view_label[0..event.view_label_len],
|
|
658
|
+
.token = event.widget_id,
|
|
659
|
+
.item_id = event.menu_item_id,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
528
663
|
/// Ordinals match the audio report kinds in gtk_host.c (the same set the
|
|
529
664
|
/// macOS and Windows hosts use); anything unknown degrades to `.failed`
|
|
530
665
|
/// so a host/SDK skew is loud in the app instead of undefined behavior
|
|
@@ -656,13 +791,23 @@ fn emitWindowEvent(context: ?*anyopaque, window_id: platform_mod.WindowId, name:
|
|
|
656
791
|
native_sdk_gtk_emit_window_event(self.host, window_id, name.ptr, name.len, detail_json.ptr, detail_json.len);
|
|
657
792
|
}
|
|
658
793
|
|
|
659
|
-
/// Thread-safe: schedules an idle source on the GLib main loop
|
|
660
|
-
///
|
|
794
|
+
/// Thread-safe: schedules an idle source on the GLib main loop
|
|
795
|
+
/// (`g_idle_add` — the enqueue-only shape the wake contract requires),
|
|
796
|
+
/// which emits `.wake` there. One of the two services worker threads
|
|
797
|
+
/// may call.
|
|
661
798
|
fn wake(context: ?*anyopaque) anyerror!void {
|
|
662
799
|
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
663
800
|
native_sdk_gtk_wake(self.host);
|
|
664
801
|
}
|
|
665
802
|
|
|
803
|
+
/// Teardown abandoned an in-flight channel wake call: latch the flag
|
|
804
|
+
/// `deinit` consults so this host is leaked rather than destroyed (see
|
|
805
|
+
/// `LinuxPlatform.channel_wake_abandoned`).
|
|
806
|
+
fn noteChannelWakeAbandoned(context: ?*anyopaque) void {
|
|
807
|
+
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
808
|
+
self.channel_wake_abandoned.store(true, .seq_cst);
|
|
809
|
+
}
|
|
810
|
+
|
|
666
811
|
/// Thread-safe like `wake`: schedules an idle source on the GLib main
|
|
667
812
|
/// loop, which emits one `.frame` event there. The automation arrival
|
|
668
813
|
/// watcher calls this when a command lands so consumption never depends
|
|
@@ -672,6 +817,15 @@ fn requestFrame(context: ?*anyopaque) anyerror!void {
|
|
|
672
817
|
native_sdk_gtk_request_frame(self.host);
|
|
673
818
|
}
|
|
674
819
|
|
|
820
|
+
/// Headless image codec for session replay: the SAME gdk-pixbuf decode
|
|
821
|
+
/// a live host serves (see `decodeImage` below — a context-free
|
|
822
|
+
/// bytes-to-pixels call, no window, no run loop), so journaled image
|
|
823
|
+
/// bytes re-register the identical pixels under a headless replay on
|
|
824
|
+
/// the same platform.
|
|
825
|
+
pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {
|
|
826
|
+
services.decode_image_fn = decodeImage;
|
|
827
|
+
}
|
|
828
|
+
|
|
675
829
|
/// gdk-pixbuf-backed image decoding (PNG, JPEG, ... — whatever loaders
|
|
676
830
|
/// the system ships) into straight-alpha RGBA8.
|
|
677
831
|
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
|
|
@@ -731,6 +885,26 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
|
|
|
731
885
|
if (native_sdk_gtk_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
732
886
|
}
|
|
733
887
|
|
|
888
|
+
/// GTK has no hide-on-close (see `window_hide_on_close`), so show is
|
|
889
|
+
/// honestly the present verb: bring the window to the front and give
|
|
890
|
+
/// it focus — the same call the focus service makes.
|
|
891
|
+
fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
892
|
+
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
893
|
+
if (native_sdk_gtk_focus_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/// The graceful quit: the same emitShutdown + g_application_quit the
|
|
897
|
+
/// last window's close-request runs, queued to the NEXT loop turn —
|
|
898
|
+
/// this verb is requested mid dispatch (the command whose update
|
|
899
|
+
/// returned it is still being dispatched), and `app_shutdown` must
|
|
900
|
+
/// emit only after that dispatch returns, or a recording session
|
|
901
|
+
/// seals its journal before the requesting command commits (the
|
|
902
|
+
/// command record is lost and replay diverges).
|
|
903
|
+
fn quitApp(context: ?*anyopaque) anyerror!void {
|
|
904
|
+
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
905
|
+
native_sdk_gtk_stop(self.host);
|
|
906
|
+
}
|
|
907
|
+
|
|
734
908
|
fn startWindowDrag(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
735
909
|
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
736
910
|
if (native_sdk_gtk_start_window_drag(self.host, window_id) == 0) return error.WindowNotFound;
|
|
@@ -926,6 +1100,71 @@ fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: platform_mod.GpuSurface
|
|
|
926
1100
|
) == 0) return error.ViewNotFound;
|
|
927
1101
|
}
|
|
928
1102
|
|
|
1103
|
+
/// GTK popover menus treat `_` in an item label as a mnemonic marker —
|
|
1104
|
+
/// GtkPopoverMenu eats the underscore and underlines the next character —
|
|
1105
|
+
/// so an app-authored label like "Save_As" must cross the ABI with the
|
|
1106
|
+
/// underscore doubled ("Save__As") to render literally. Labels without
|
|
1107
|
+
/// an underscore pass through uncopied; a label whose escaped form does
|
|
1108
|
+
/// not fit the remaining pool also passes through raw, because an
|
|
1109
|
+
/// accidental mnemonic on a pathological label beats dropping bytes.
|
|
1110
|
+
fn escapeMenuLabelUnderscores(label: []const u8, pool: []u8, used: *usize) []const u8 {
|
|
1111
|
+
const underscores = std.mem.count(u8, label, "_");
|
|
1112
|
+
if (underscores == 0) return label;
|
|
1113
|
+
if (label.len + underscores > pool.len - used.*) return label;
|
|
1114
|
+
const start = used.*;
|
|
1115
|
+
var out = start;
|
|
1116
|
+
for (label) |byte| {
|
|
1117
|
+
pool[out] = byte;
|
|
1118
|
+
out += 1;
|
|
1119
|
+
if (byte == '_') {
|
|
1120
|
+
pool[out] = '_';
|
|
1121
|
+
out += 1;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
used.* = out;
|
|
1125
|
+
return pool[start..out];
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/// Translate the request's items to the C ABI shape, escaping mnemonic
|
|
1129
|
+
/// underscores into `label_pool` (the host strndup-copies every label
|
|
1130
|
+
/// before returning, so a caller stack pool is safe). Pure (no host
|
|
1131
|
+
/// calls), so the separator/disabled/label mapping is unit-testable on
|
|
1132
|
+
/// every build host.
|
|
1133
|
+
fn contextMenuItemsToGtk(items: []const platform_mod.ContextMenuItem, buffer: []GtkContextMenuItem, label_pool: []u8) []const GtkContextMenuItem {
|
|
1134
|
+
const count = @min(items.len, buffer.len);
|
|
1135
|
+
var pool_used: usize = 0;
|
|
1136
|
+
for (items[0..count], 0..) |item, index| {
|
|
1137
|
+
const label = escapeMenuLabelUnderscores(item.label, label_pool, &pool_used);
|
|
1138
|
+
buffer[index] = .{
|
|
1139
|
+
.item_id = item.id,
|
|
1140
|
+
.label = label.ptr,
|
|
1141
|
+
.label_len = label.len,
|
|
1142
|
+
.enabled = if (item.enabled) 1 else 0,
|
|
1143
|
+
.separator = if (item.separator) 1 else 0,
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
return buffer[0..count];
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
fn showContextMenu(context: ?*anyopaque, request: platform_mod.ContextMenuRequest) anyerror!void {
|
|
1150
|
+
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
1151
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1152
|
+
var items: [platform_mod.max_context_menu_items]GtkContextMenuItem = undefined;
|
|
1153
|
+
var label_pool: [platform_mod.max_context_menu_items * 64]u8 = undefined;
|
|
1154
|
+
const translated = contextMenuItemsToGtk(request.items, &items, &label_pool);
|
|
1155
|
+
if (native_sdk_gtk_show_context_menu(
|
|
1156
|
+
self.host,
|
|
1157
|
+
request.window_id,
|
|
1158
|
+
request.view_label.ptr,
|
|
1159
|
+
request.view_label.len,
|
|
1160
|
+
request.point.x,
|
|
1161
|
+
request.point.y,
|
|
1162
|
+
request.token,
|
|
1163
|
+
translated.ptr,
|
|
1164
|
+
translated.len,
|
|
1165
|
+
) == 0) return error.WindowNotFound;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
929
1168
|
fn createWebView(context: ?*anyopaque, options: platform_mod.WebViewOptions) anyerror!void {
|
|
930
1169
|
const self: *LinuxPlatform = @ptrCast(@alignCast(context.?));
|
|
931
1170
|
if (self.web_engine == .chromium) return error.UnsupportedChildWebViews;
|
|
@@ -1182,6 +1421,26 @@ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
|
|
|
1182
1421
|
_ = native_sdk_gtk_audio_set_volume(self.host, volume);
|
|
1183
1422
|
}
|
|
1184
1423
|
|
|
1424
|
+
/// The video tier's teaching refusal: the load verbs exist so a video
|
|
1425
|
+
/// source fails with a NAMED explanation instead of a bare
|
|
1426
|
+
/// unsupported-service, while the transport verbs stay null — the
|
|
1427
|
+
/// channel never activates without a successful load. Pure (no GTK
|
|
1428
|
+
/// externs), so the teaching is unit-testable on every host.
|
|
1429
|
+
fn videoLoad(context: ?*anyopaque, path: []const u8, token: u64, sink: platform_mod.VideoFrameSink) anyerror!void {
|
|
1430
|
+
_ = context;
|
|
1431
|
+
_ = path;
|
|
1432
|
+
_ = token;
|
|
1433
|
+
_ = sink;
|
|
1434
|
+
std.debug.print("video playback is not implemented on linux yet: the GTK host has no GStreamer decode path into the media-surface texture channel - the app receives one failed video event (scope video sources to macos builds, or compose a media-surface with your own producer)\n", .{});
|
|
1435
|
+
return error.UnsupportedService;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/// The URL twin rides the same teaching — a stream would need the same
|
|
1439
|
+
/// missing decode path a file does.
|
|
1440
|
+
fn videoLoadUrl(context: ?*anyopaque, url: []const u8, token: u64, sink: platform_mod.VideoFrameSink) anyerror!void {
|
|
1441
|
+
return videoLoad(context, url, token, sink);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1185
1444
|
fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
|
|
1186
1445
|
_ = context;
|
|
1187
1446
|
_ = options;
|
|
@@ -1481,6 +1740,68 @@ test "linux audio event maps kinds and payload" {
|
|
|
1481
1740
|
try std.testing.expectEqual(platform_mod.AudioEventKind.failed, audioEventKindFromInt(99));
|
|
1482
1741
|
}
|
|
1483
1742
|
|
|
1743
|
+
test "linux context menus ride the system-engine gate" {
|
|
1744
|
+
var system = testPlatformWithEngine(.system);
|
|
1745
|
+
try std.testing.expect(LinuxPlatform.supportsFeature(&system, .context_menus));
|
|
1746
|
+
var chromium = testPlatformWithEngine(.chromium);
|
|
1747
|
+
try std.testing.expect(!LinuxPlatform.supportsFeature(&chromium, .context_menus));
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
test "linux context menu items translate separators, disabled flags, and labels" {
|
|
1751
|
+
const items = [_]platform_mod.ContextMenuItem{
|
|
1752
|
+
.{ .id = 1, .label = "Complete" },
|
|
1753
|
+
.{ .separator = true },
|
|
1754
|
+
.{ .id = 3, .label = "Delete", .enabled = false },
|
|
1755
|
+
.{ .id = 4, .label = "Move to Save_As" },
|
|
1756
|
+
};
|
|
1757
|
+
var buffer: [platform_mod.max_context_menu_items]GtkContextMenuItem = undefined;
|
|
1758
|
+
var label_pool: [platform_mod.max_context_menu_items * 64]u8 = undefined;
|
|
1759
|
+
const translated = contextMenuItemsToGtk(&items, &buffer, &label_pool);
|
|
1760
|
+
try std.testing.expectEqual(@as(usize, 4), translated.len);
|
|
1761
|
+
try std.testing.expectEqual(@as(u32, 1), translated[0].item_id);
|
|
1762
|
+
try std.testing.expectEqualStrings("Complete", translated[0].label[0..translated[0].label_len]);
|
|
1763
|
+
try std.testing.expectEqual(@as(c_int, 1), translated[0].enabled);
|
|
1764
|
+
try std.testing.expectEqual(@as(c_int, 0), translated[0].separator);
|
|
1765
|
+
try std.testing.expectEqual(@as(c_int, 1), translated[1].separator);
|
|
1766
|
+
try std.testing.expectEqual(@as(u32, 3), translated[2].item_id);
|
|
1767
|
+
try std.testing.expectEqual(@as(c_int, 0), translated[2].enabled);
|
|
1768
|
+
// A literal `_` doubles on the way to GtkPopoverMenu so GTK renders
|
|
1769
|
+
// it instead of eating it as a mnemonic marker; underscore-free
|
|
1770
|
+
// labels pass through pointing at the caller's bytes.
|
|
1771
|
+
try std.testing.expectEqualStrings("Move to Save__As", translated[3].label[0..translated[3].label_len]);
|
|
1772
|
+
try std.testing.expectEqual(items[0].label.ptr, translated[0].label);
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
test "linux menu label escape passes a label through raw when the pool cannot hold it" {
|
|
1776
|
+
var pool: [8]u8 = undefined;
|
|
1777
|
+
var used: usize = 0;
|
|
1778
|
+
const label = "Save_As";
|
|
1779
|
+
// Escaped form needs 8 bytes and fits exactly.
|
|
1780
|
+
try std.testing.expectEqualStrings("Save__As", escapeMenuLabelUnderscores(label, &pool, &used));
|
|
1781
|
+
// The pool is spent: the next underscore label rides unescaped
|
|
1782
|
+
// (accidental mnemonic) rather than truncated.
|
|
1783
|
+
const passed_through = escapeMenuLabelUnderscores(label, &pool, &used);
|
|
1784
|
+
try std.testing.expectEqualStrings("Save_As", passed_through);
|
|
1785
|
+
try std.testing.expectEqual(label.ptr, passed_through.ptr);
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
test "linux context menu action event maps token and item id" {
|
|
1789
|
+
const label = "canvas";
|
|
1790
|
+
var event = std.mem.zeroes(GtkEvent);
|
|
1791
|
+
event.kind = .context_menu_action;
|
|
1792
|
+
event.window_id = 7;
|
|
1793
|
+
event.view_label = label.ptr;
|
|
1794
|
+
event.view_label_len = label.len;
|
|
1795
|
+
event.widget_id = 42;
|
|
1796
|
+
event.menu_item_id = 3;
|
|
1797
|
+
|
|
1798
|
+
const action = contextMenuActionEventFromGtkEvent(&event);
|
|
1799
|
+
try std.testing.expectEqual(@as(platform_mod.WindowId, 7), action.window_id);
|
|
1800
|
+
try std.testing.expectEqualStrings("canvas", action.view_label);
|
|
1801
|
+
try std.testing.expectEqual(@as(u64, 42), action.token);
|
|
1802
|
+
try std.testing.expectEqual(@as(u32, 3), action.item_id);
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1484
1805
|
fn testPlatformWithEngine(web_engine: platform_mod.WebEngine) LinuxPlatform {
|
|
1485
1806
|
return .{
|
|
1486
1807
|
.host = undefined,
|
|
@@ -1517,3 +1838,26 @@ fn viewKindInt(kind: platform_mod.ViewKind) c_int {
|
|
|
1517
1838
|
test "linux platform module exports type" {
|
|
1518
1839
|
_ = LinuxPlatform;
|
|
1519
1840
|
}
|
|
1841
|
+
|
|
1842
|
+
test "linux webview presses report the focused child label" {
|
|
1843
|
+
// The capture-phase observer watches without claiming WebKit's
|
|
1844
|
+
// gesture; it exists solely to mirror the focus edge into runtime
|
|
1845
|
+
// state before the page handles the same press.
|
|
1846
|
+
const host_source = @embedFile("gtk_host.c");
|
|
1847
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "gtk_event_controller_set_propagation_phase(GTK_EVENT_CONTROLLER(click), GTK_PHASE_CAPTURE)") != null);
|
|
1848
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, ".kind = NATIVE_SDK_GTK_EVENT_VIEW_FOCUSED") != null);
|
|
1849
|
+
try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_watch_webview_pointer_focus(win, web_view);") != null);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
test "linux refuses a .hide main window at platform init instead of a silent quit-on-close" {
|
|
1853
|
+
// The pre-created MAIN window never passes through the runtime's
|
|
1854
|
+
// create gate, so the platform's init gate must hold the same
|
|
1855
|
+
// line. The gate sees exactly the options `initWithOptions`
|
|
1856
|
+
// resolves from the caller's AppInfo.
|
|
1857
|
+
const hide_app: platform_mod.AppInfo = .{ .app_name = "player", .main_window = .{ .close_policy = .hide } };
|
|
1858
|
+
try std.testing.expectError(error.UnsupportedWindowClosePolicy, refuseUnsupportedMainWindowClosePolicy(hide_app.resolvedMainWindow()));
|
|
1859
|
+
// The default (.quit) and every other declaration pass untouched —
|
|
1860
|
+
// the refusal is the .hide declaration's, not the init path's.
|
|
1861
|
+
const quit_app: platform_mod.AppInfo = .{ .app_name = "player" };
|
|
1862
|
+
try refuseUnsupportedMainWindowClosePolicy(quit_app.resolvedMainWindow());
|
|
1863
|
+
}
|