@native-sdk/cli 0.0.0 → 0.4.1
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/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,1521 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
3
|
+
const platform_mod = @import("../root.zig");
|
|
4
|
+
const policy_values = @import("../policy_values.zig");
|
|
5
|
+
const security = @import("../../security/root.zig");
|
|
6
|
+
|
|
7
|
+
pub const Error = error{
|
|
8
|
+
CallbackFailed,
|
|
9
|
+
CreateFailed,
|
|
10
|
+
FocusFailed,
|
|
11
|
+
CloseFailed,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const WindowsHost = opaque {};
|
|
15
|
+
|
|
16
|
+
const WindowsEventKind = enum(c_int) {
|
|
17
|
+
start = 0,
|
|
18
|
+
frame = 1,
|
|
19
|
+
shutdown = 2,
|
|
20
|
+
resize = 3,
|
|
21
|
+
window_frame = 4,
|
|
22
|
+
shortcut = 5,
|
|
23
|
+
native_command = 6,
|
|
24
|
+
app_activated = 7,
|
|
25
|
+
app_deactivated = 8,
|
|
26
|
+
files_dropped = 9,
|
|
27
|
+
menu_command = 10,
|
|
28
|
+
tray_action = 11,
|
|
29
|
+
gpu_surface_frame = 12,
|
|
30
|
+
gpu_surface_resize = 13,
|
|
31
|
+
gpu_surface_input = 14,
|
|
32
|
+
wake = 15,
|
|
33
|
+
timer = 16,
|
|
34
|
+
appearance = 17,
|
|
35
|
+
audio = 18,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const WindowsEvent = extern struct {
|
|
39
|
+
kind: WindowsEventKind,
|
|
40
|
+
window_id: u64,
|
|
41
|
+
width: f64,
|
|
42
|
+
height: f64,
|
|
43
|
+
scale: f64,
|
|
44
|
+
x: f64,
|
|
45
|
+
y: f64,
|
|
46
|
+
open: c_int,
|
|
47
|
+
focused: c_int,
|
|
48
|
+
label: [*]const u8,
|
|
49
|
+
label_len: usize,
|
|
50
|
+
title: [*]const u8,
|
|
51
|
+
title_len: usize,
|
|
52
|
+
shortcut_id: [*]const u8,
|
|
53
|
+
shortcut_id_len: usize,
|
|
54
|
+
shortcut_key: [*]const u8,
|
|
55
|
+
shortcut_key_len: usize,
|
|
56
|
+
shortcut_modifiers: u32,
|
|
57
|
+
command_name: [*]const u8,
|
|
58
|
+
command_name_len: usize,
|
|
59
|
+
view_label: [*]const u8,
|
|
60
|
+
view_label_len: usize,
|
|
61
|
+
drop_paths: [*]const u8,
|
|
62
|
+
drop_paths_len: usize,
|
|
63
|
+
tray_item_id: u32,
|
|
64
|
+
frame_index: u64,
|
|
65
|
+
timestamp_ns: u64,
|
|
66
|
+
frame_interval_ns: u64,
|
|
67
|
+
nonblank: c_int,
|
|
68
|
+
sample_color: u32,
|
|
69
|
+
/// Nonzero when the frame completed logically while the top-level
|
|
70
|
+
/// window was minimized (heartbeat pacing; nothing painted) — its
|
|
71
|
+
/// timestamp is pacing policy, never a latency endpoint.
|
|
72
|
+
occluded: c_int,
|
|
73
|
+
input_kind: c_int,
|
|
74
|
+
button: c_int,
|
|
75
|
+
delta_x: f64,
|
|
76
|
+
delta_y: f64,
|
|
77
|
+
key_text: [*]const u8,
|
|
78
|
+
key_text_len: usize,
|
|
79
|
+
input_text: [*]const u8,
|
|
80
|
+
input_text_len: usize,
|
|
81
|
+
has_composition_cursor: c_int,
|
|
82
|
+
composition_cursor: usize,
|
|
83
|
+
timer_id: u64,
|
|
84
|
+
color_scheme: c_int,
|
|
85
|
+
reduce_motion: c_int,
|
|
86
|
+
high_contrast: c_int,
|
|
87
|
+
/// Audio player report payload (`kind == .audio`): the report kind
|
|
88
|
+
/// ordinal plus the live transport readout. `audio_buffering` is the
|
|
89
|
+
/// honest stream-stall mirror (an un-paused stream waiting for
|
|
90
|
+
/// bytes), distinct from `audio_playing` (the transport intent).
|
|
91
|
+
audio_kind: c_int,
|
|
92
|
+
audio_position_ms: u64,
|
|
93
|
+
audio_duration_ms: u64,
|
|
94
|
+
audio_playing: c_int,
|
|
95
|
+
audio_buffering: c_int,
|
|
96
|
+
/// SPECTRUM report payload: the 32 band magnitude bytes on the
|
|
97
|
+
/// documented scale (log-spaced 50 Hz..16 kHz buckets, linear-in-dB
|
|
98
|
+
/// from -60 dBFS at 0 to full scale at 255). Zeros elsewhere.
|
|
99
|
+
audio_bands: [platform_mod.audio_spectrum_band_count]u8,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const WindowsCallback = *const fn (context: ?*anyopaque, event: *const WindowsEvent) callconv(.c) void;
|
|
103
|
+
const WindowsBridgeCallback = *const fn (context: ?*anyopaque, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, message: [*]const u8, message_len: usize, origin: [*]const u8, origin_len: usize) callconv(.c) void;
|
|
104
|
+
|
|
105
|
+
const shortcut_modifier_primary: u32 = 1 << 0;
|
|
106
|
+
const shortcut_modifier_command: u32 = 1 << 1;
|
|
107
|
+
const shortcut_modifier_control: u32 = 1 << 2;
|
|
108
|
+
const shortcut_modifier_option: u32 = 1 << 3;
|
|
109
|
+
const shortcut_modifier_shift: u32 = 1 << 4;
|
|
110
|
+
|
|
111
|
+
extern fn native_sdk_windows_create(app_name: [*]const u8, app_name_len: usize, window_title: [*]const u8, window_title_len: usize, bundle_id: [*]const u8, bundle_id_len: usize, icon_path: [*]const u8, icon_path_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64) ?*WindowsHost;
|
|
112
|
+
extern fn native_sdk_windows_destroy(host: *WindowsHost) void;
|
|
113
|
+
extern fn native_sdk_windows_run(host: *WindowsHost, callback: WindowsCallback, context: ?*anyopaque) void;
|
|
114
|
+
extern fn native_sdk_windows_stop(host: *WindowsHost) void;
|
|
115
|
+
extern fn native_sdk_windows_wake(host: *WindowsHost) void;
|
|
116
|
+
extern fn native_sdk_windows_request_frame(host: *WindowsHost) void;
|
|
117
|
+
extern fn native_sdk_windows_decode_image(bytes: [*]const u8, bytes_len: usize, pixels: [*]u8, pixels_len: usize, out_width: *usize, out_height: *usize) c_int;
|
|
118
|
+
extern fn native_sdk_windows_load_webview(host: *WindowsHost, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
|
|
119
|
+
extern fn native_sdk_windows_load_window_webview(host: *WindowsHost, window_id: u64, source: [*]const u8, source_len: usize, source_kind: c_int, asset_root: [*]const u8, asset_root_len: usize, asset_entry: [*]const u8, asset_entry_len: usize, asset_origin: [*]const u8, asset_origin_len: usize, spa_fallback: c_int) void;
|
|
120
|
+
extern fn native_sdk_windows_set_bridge_callback(host: *WindowsHost, callback: WindowsBridgeCallback, context: ?*anyopaque) void;
|
|
121
|
+
extern fn native_sdk_windows_bridge_respond(host: *WindowsHost, response: [*]const u8, response_len: usize) void;
|
|
122
|
+
extern fn native_sdk_windows_bridge_respond_window(host: *WindowsHost, window_id: u64, response: [*]const u8, response_len: usize) void;
|
|
123
|
+
extern fn native_sdk_windows_bridge_respond_webview(host: *WindowsHost, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, response: [*]const u8, response_len: usize) void;
|
|
124
|
+
extern fn native_sdk_windows_emit_window_event(host: *WindowsHost, window_id: u64, name: [*]const u8, name_len: usize, detail_json: [*]const u8, detail_json_len: usize) void;
|
|
125
|
+
extern fn native_sdk_windows_set_security_policy(host: *WindowsHost, allowed_origins: [*]const u8, allowed_origins_len: usize, external_urls: [*]const u8, external_urls_len: usize, external_action: c_int) void;
|
|
126
|
+
extern fn native_sdk_windows_set_menus(host: *WindowsHost, menu_titles: [*]const [*]const u8, menu_title_lens: [*]const usize, menu_count: usize, item_menu_indices: [*]const u32, item_labels: [*]const [*]const u8, item_label_lens: [*]const usize, item_commands: [*]const [*]const u8, item_command_lens: [*]const usize, item_keys: [*]const [*]const u8, item_key_lens: [*]const usize, item_modifiers: [*]const u32, item_separators: [*]const c_int, item_enabled: [*]const c_int, item_checked: [*]const c_int, item_count: usize) void;
|
|
127
|
+
extern fn native_sdk_windows_set_shortcuts(host: *WindowsHost, ids: [*]const [*]const u8, id_lens: [*]const usize, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) void;
|
|
128
|
+
extern fn native_sdk_windows_create_window(host: *WindowsHost, window_id: u64, window_title: [*]const u8, window_title_len: usize, window_label: [*]const u8, window_label_len: usize, x: f64, y: f64, width: f64, height: f64, restore_frame: c_int, resizable: c_int, titlebar_style: c_int, min_width: f64, min_height: f64) c_int;
|
|
129
|
+
extern fn native_sdk_windows_start_window_drag(host: *WindowsHost, window_id: u64) c_int;
|
|
130
|
+
extern fn native_sdk_windows_set_window_drag_regions(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, rects: [*]const f64, exclusions: [*]const c_int, count: usize) c_int;
|
|
131
|
+
extern fn native_sdk_windows_window_chrome(host: *WindowsHost, window_id: u64, top: *f64, left: *f64, bottom: *f64, right: *f64, buttons_x: *f64, buttons_y: *f64, buttons_width: *f64, buttons_height: *f64) c_int;
|
|
132
|
+
extern fn native_sdk_windows_start_timer(host: *WindowsHost, timer_id: u64, interval_ns: u64, repeats: c_int) void;
|
|
133
|
+
extern fn native_sdk_windows_cancel_timer(host: *WindowsHost, timer_id: u64) void;
|
|
134
|
+
extern fn native_sdk_windows_focus_window(host: *WindowsHost, window_id: u64) c_int;
|
|
135
|
+
extern fn native_sdk_windows_close_window(host: *WindowsHost, window_id: u64) c_int;
|
|
136
|
+
extern fn native_sdk_windows_minimize_window(host: *WindowsHost, window_id: u64) c_int;
|
|
137
|
+
extern fn native_sdk_windows_create_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, kind: c_int, parent: [*]const u8, parent_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, visible: c_int, enabled: c_int, role: [*]const u8, role_len: usize, accessibility_label: [*]const u8, accessibility_label_len: usize, text: [*]const u8, text_len: usize, command: [*]const u8, command_len: usize) c_int;
|
|
138
|
+
extern fn native_sdk_windows_update_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, has_frame: c_int, x: f64, y: f64, width: f64, height: f64, has_layer: c_int, layer: c_int, has_visible: c_int, visible: c_int, has_enabled: c_int, enabled: c_int, has_role: c_int, role: [*]const u8, role_len: usize, has_accessibility_label: c_int, accessibility_label: [*]const u8, accessibility_label_len: usize, has_text: c_int, text: [*]const u8, text_len: usize, has_command: c_int, command: [*]const u8, command_len: usize) c_int;
|
|
139
|
+
extern fn native_sdk_windows_set_view_frame(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, width: f64, height: f64) c_int;
|
|
140
|
+
extern fn native_sdk_windows_set_view_visible(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, visible: c_int) c_int;
|
|
141
|
+
extern fn native_sdk_windows_focus_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
|
|
142
|
+
extern fn native_sdk_windows_close_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
|
|
143
|
+
extern fn native_sdk_windows_request_gpu_surface_frame(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
|
|
144
|
+
extern fn native_sdk_windows_note_gpu_surface_input(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
|
|
145
|
+
extern fn native_sdk_windows_present_gpu_surface_pixels(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, width: usize, height: usize, scale: f64, has_dirty_rect: c_int, dirty_x: f64, dirty_y: f64, dirty_width: f64, dirty_height: f64, rgba8: [*]const u8, rgba8_len: usize) c_int;
|
|
146
|
+
extern fn native_sdk_windows_create_webview(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, url: [*]const u8, url_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, transparent: c_int, bridge_enabled: c_int) c_int;
|
|
147
|
+
extern fn native_sdk_windows_set_webview_frame(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, width: f64, height: f64) c_int;
|
|
148
|
+
extern fn native_sdk_windows_navigate_webview(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, url: [*]const u8, url_len: usize) c_int;
|
|
149
|
+
extern fn native_sdk_windows_set_webview_zoom(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, zoom: f64) c_int;
|
|
150
|
+
extern fn native_sdk_windows_set_webview_layer(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, layer: c_int) c_int;
|
|
151
|
+
extern fn native_sdk_windows_close_webview(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize) c_int;
|
|
152
|
+
extern fn native_sdk_windows_open_external_url(host: *WindowsHost, url: [*]const u8, url_len: usize) c_int;
|
|
153
|
+
extern fn native_sdk_windows_reveal_path(host: *WindowsHost, path: [*]const u8, path_len: usize) c_int;
|
|
154
|
+
extern fn native_sdk_windows_show_open_dialog(host: *WindowsHost, opts: *const WindowsOpenDialogOpts, buffer: [*]u8, buffer_len: usize) WindowsOpenDialogResult;
|
|
155
|
+
extern fn native_sdk_windows_show_save_dialog(host: *WindowsHost, opts: *const WindowsSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
|
|
156
|
+
extern fn native_sdk_windows_show_message_dialog(host: *WindowsHost, opts: *const WindowsMessageDialogOpts) c_int;
|
|
157
|
+
extern fn native_sdk_windows_show_notification(host: *WindowsHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize) c_int;
|
|
158
|
+
extern fn native_sdk_windows_create_tray(host: *WindowsHost, icon_path: [*]const u8, icon_path_len: usize, tooltip: [*]const u8, tooltip_len: usize) c_int;
|
|
159
|
+
extern fn native_sdk_windows_update_tray_menu(host: *WindowsHost, item_ids: [*]const u32, labels: [*]const [*]const u8, label_lens: [*]const usize, separators: [*]const c_int, enabled_flags: [*]const c_int, count: usize) c_int;
|
|
160
|
+
extern fn native_sdk_windows_remove_tray(host: *WindowsHost) void;
|
|
161
|
+
extern fn native_sdk_windows_add_recent_document(host: *WindowsHost, path: [*]const u8, path_len: usize) c_int;
|
|
162
|
+
extern fn native_sdk_windows_clear_recent_documents(host: *WindowsHost) c_int;
|
|
163
|
+
extern fn native_sdk_windows_set_credential(host: *WindowsHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, secret: [*]const u8, secret_len: usize) c_int;
|
|
164
|
+
extern fn native_sdk_windows_get_credential(host: *WindowsHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, buffer: [*]u8, buffer_len: usize) usize;
|
|
165
|
+
extern fn native_sdk_windows_delete_credential(host: *WindowsHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize) c_int;
|
|
166
|
+
extern fn native_sdk_windows_clipboard_read(host: *WindowsHost, buffer: [*]u8, buffer_len: usize) usize;
|
|
167
|
+
extern fn native_sdk_windows_clipboard_write(host: *WindowsHost, text: [*]const u8, text_len: usize) void;
|
|
168
|
+
extern fn native_sdk_windows_clipboard_read_data(host: *WindowsHost, mime_type: [*]const u8, mime_type_len: usize, buffer: [*]u8, buffer_len: usize) usize;
|
|
169
|
+
extern fn native_sdk_windows_clipboard_write_data(host: *WindowsHost, mime_type: [*]const u8, mime_type_len: usize, bytes: [*]const u8, bytes_len: usize) c_int;
|
|
170
|
+
extern fn native_sdk_windows_audio_load(host: *WindowsHost, path: [*]const u8, path_len: usize) c_int;
|
|
171
|
+
extern fn native_sdk_windows_audio_load_url(host: *WindowsHost, url: [*]const u8, url_len: usize, cache_path: [*]const u8, cache_path_len: usize, expected_bytes: u64) c_int;
|
|
172
|
+
extern fn native_sdk_windows_audio_play(host: *WindowsHost) c_int;
|
|
173
|
+
extern fn native_sdk_windows_audio_pause(host: *WindowsHost) c_int;
|
|
174
|
+
extern fn native_sdk_windows_audio_stop(host: *WindowsHost) c_int;
|
|
175
|
+
extern fn native_sdk_windows_audio_seek(host: *WindowsHost, position_ms: u64) c_int;
|
|
176
|
+
extern fn native_sdk_windows_audio_set_volume(host: *WindowsHost, volume: f64) c_int;
|
|
177
|
+
extern fn native_sdk_windows_audio_spectrum_supported(host: *WindowsHost) c_int;
|
|
178
|
+
|
|
179
|
+
const WindowsOpenDialogOpts = extern struct {
|
|
180
|
+
title: [*]const u8,
|
|
181
|
+
title_len: usize,
|
|
182
|
+
default_path: [*]const u8,
|
|
183
|
+
default_path_len: usize,
|
|
184
|
+
extensions: [*]const u8,
|
|
185
|
+
extensions_len: usize,
|
|
186
|
+
allow_directories: c_int,
|
|
187
|
+
allow_multiple: c_int,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const WindowsOpenDialogResult = extern struct {
|
|
191
|
+
count: usize,
|
|
192
|
+
bytes_written: usize,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const WindowsSaveDialogOpts = extern struct {
|
|
196
|
+
title: [*]const u8,
|
|
197
|
+
title_len: usize,
|
|
198
|
+
default_path: [*]const u8,
|
|
199
|
+
default_path_len: usize,
|
|
200
|
+
default_name: [*]const u8,
|
|
201
|
+
default_name_len: usize,
|
|
202
|
+
extensions: [*]const u8,
|
|
203
|
+
extensions_len: usize,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const WindowsMessageDialogOpts = extern struct {
|
|
207
|
+
style: c_int,
|
|
208
|
+
title: [*]const u8,
|
|
209
|
+
title_len: usize,
|
|
210
|
+
message: [*]const u8,
|
|
211
|
+
message_len: usize,
|
|
212
|
+
informative_text: [*]const u8,
|
|
213
|
+
informative_text_len: usize,
|
|
214
|
+
primary_button: [*]const u8,
|
|
215
|
+
primary_button_len: usize,
|
|
216
|
+
secondary_button: [*]const u8,
|
|
217
|
+
secondary_button_len: usize,
|
|
218
|
+
tertiary_button: [*]const u8,
|
|
219
|
+
tertiary_button_len: usize,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
pub const WindowsPlatform = struct {
|
|
223
|
+
host: *WindowsHost,
|
|
224
|
+
web_engine: platform_mod.WebEngine,
|
|
225
|
+
app_info: platform_mod.AppInfo,
|
|
226
|
+
surface_value: platform_mod.Surface,
|
|
227
|
+
state: RunState = .{},
|
|
228
|
+
|
|
229
|
+
pub fn init(title: []const u8, size: geometry.SizeF) Error!WindowsPlatform {
|
|
230
|
+
return initWithEngine(title, size, .system);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
pub fn initWithEngine(title: []const u8, size: geometry.SizeF, web_engine: platform_mod.WebEngine) Error!WindowsPlatform {
|
|
234
|
+
return initWithOptions(size, web_engine, .{ .app_name = title, .window_title = title });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
pub fn initWithOptions(size: geometry.SizeF, web_engine: platform_mod.WebEngine, app_info: platform_mod.AppInfo) Error!WindowsPlatform {
|
|
238
|
+
const window_options = app_info.resolvedMainWindow();
|
|
239
|
+
const window_title = window_options.resolvedTitle(app_info.app_name);
|
|
240
|
+
const frame = window_options.default_frame;
|
|
241
|
+
const host = native_sdk_windows_create(app_info.app_name.ptr, app_info.app_name.len, window_title.ptr, window_title.len, app_info.bundle_id.ptr, app_info.bundle_id.len, app_info.icon_path.ptr, app_info.icon_path.len, window_options.label.ptr, window_options.label.len, frame.x, frame.y, frame.width, frame.height, if (window_options.restore_state) 1 else 0, if (window_options.resizable) 1 else 0, titlebarStyleInt(window_options.titlebar), minSizeFloor(window_options.min_width), minSizeFloor(window_options.min_height)) orelse return error.CreateFailed;
|
|
242
|
+
return .{
|
|
243
|
+
.host = host,
|
|
244
|
+
.web_engine = web_engine,
|
|
245
|
+
.app_info = app_info,
|
|
246
|
+
.surface_value = .{
|
|
247
|
+
.id = 1,
|
|
248
|
+
.size = size,
|
|
249
|
+
.scale_factor = 1,
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
pub fn deinit(self: *WindowsPlatform) void {
|
|
255
|
+
native_sdk_windows_destroy(self.host);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
pub fn platform(self: *WindowsPlatform) platform_mod.Platform {
|
|
259
|
+
return .{
|
|
260
|
+
.context = self,
|
|
261
|
+
.name = "windows",
|
|
262
|
+
.surface_value = self.surface_value,
|
|
263
|
+
.run_fn = run,
|
|
264
|
+
.supports_fn = supportsFeature,
|
|
265
|
+
.services = .{
|
|
266
|
+
.context = self,
|
|
267
|
+
.read_clipboard_fn = readClipboard,
|
|
268
|
+
.write_clipboard_fn = writeClipboard,
|
|
269
|
+
.read_clipboard_data_fn = readClipboardData,
|
|
270
|
+
.write_clipboard_data_fn = writeClipboardData,
|
|
271
|
+
.load_webview_fn = loadWebView,
|
|
272
|
+
.load_window_webview_fn = loadWindowWebView,
|
|
273
|
+
.complete_bridge_fn = completeBridge,
|
|
274
|
+
.complete_window_bridge_fn = completeWindowBridge,
|
|
275
|
+
.complete_webview_bridge_fn = completeWebViewBridge,
|
|
276
|
+
.create_window_fn = createWindow,
|
|
277
|
+
.focus_window_fn = focusWindow,
|
|
278
|
+
.close_window_fn = closeWindow,
|
|
279
|
+
.minimize_window_fn = minimizeWindow,
|
|
280
|
+
.start_window_drag_fn = startWindowDrag,
|
|
281
|
+
.set_window_drag_regions_fn = setWindowDragRegions,
|
|
282
|
+
.window_chrome_fn = windowChrome,
|
|
283
|
+
.create_view_fn = createView,
|
|
284
|
+
.update_view_fn = updateView,
|
|
285
|
+
.set_view_frame_fn = setViewFrame,
|
|
286
|
+
.set_view_visible_fn = setViewVisible,
|
|
287
|
+
.focus_view_fn = focusView,
|
|
288
|
+
.close_view_fn = closeView,
|
|
289
|
+
.request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
|
|
290
|
+
.note_gpu_surface_input_fn = noteGpuSurfaceInput,
|
|
291
|
+
.present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
|
|
292
|
+
.create_webview_fn = createWebView,
|
|
293
|
+
.set_webview_frame_fn = setWebViewFrame,
|
|
294
|
+
.navigate_webview_fn = navigateWebView,
|
|
295
|
+
.set_webview_zoom_fn = setWebViewZoom,
|
|
296
|
+
.set_webview_layer_fn = setWebViewLayer,
|
|
297
|
+
.close_webview_fn = closeWebView,
|
|
298
|
+
.show_open_dialog_fn = showOpenDialog,
|
|
299
|
+
.show_save_dialog_fn = showSaveDialog,
|
|
300
|
+
.show_message_dialog_fn = showMessageDialog,
|
|
301
|
+
.show_notification_fn = showNotification,
|
|
302
|
+
.create_tray_fn = createTray,
|
|
303
|
+
.update_tray_menu_fn = updateTrayMenu,
|
|
304
|
+
.remove_tray_fn = removeTray,
|
|
305
|
+
.open_external_url_fn = openExternalUrl,
|
|
306
|
+
.reveal_path_fn = revealPath,
|
|
307
|
+
.add_recent_document_fn = addRecentDocument,
|
|
308
|
+
.clear_recent_documents_fn = clearRecentDocuments,
|
|
309
|
+
.set_credential_fn = setCredential,
|
|
310
|
+
.get_credential_fn = getCredential,
|
|
311
|
+
.delete_credential_fn = deleteCredential,
|
|
312
|
+
.audio_load_fn = audioLoad,
|
|
313
|
+
.audio_load_url_fn = audioLoadUrl,
|
|
314
|
+
.audio_play_fn = audioPlay,
|
|
315
|
+
.audio_pause_fn = audioPause,
|
|
316
|
+
.audio_stop_fn = audioStop,
|
|
317
|
+
.audio_seek_fn = audioSeek,
|
|
318
|
+
.audio_set_volume_fn = audioSetVolume,
|
|
319
|
+
.configure_security_policy_fn = configureSecurityPolicy,
|
|
320
|
+
.configure_menus_fn = configureMenus,
|
|
321
|
+
.configure_shortcuts_fn = configureShortcuts,
|
|
322
|
+
.emit_window_event_fn = emitWindowEvent,
|
|
323
|
+
.start_timer_fn = startTimer,
|
|
324
|
+
.cancel_timer_fn = cancelTimer,
|
|
325
|
+
.wake_fn = wake,
|
|
326
|
+
.request_frame_fn = requestFrame,
|
|
327
|
+
.decode_image_fn = decodeImage,
|
|
328
|
+
},
|
|
329
|
+
.app_info = self.app_info,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
fn supportsFeature(context: *anyopaque, feature: platform_mod.PlatformFeature) bool {
|
|
334
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context));
|
|
335
|
+
return switch (feature) {
|
|
336
|
+
.main_webview,
|
|
337
|
+
.child_webviews,
|
|
338
|
+
.native_views,
|
|
339
|
+
.native_control_commands,
|
|
340
|
+
.menus,
|
|
341
|
+
.tray,
|
|
342
|
+
.shortcuts,
|
|
343
|
+
.dialogs,
|
|
344
|
+
.clipboard_text,
|
|
345
|
+
.clipboard_rich_data,
|
|
346
|
+
.open_url,
|
|
347
|
+
.reveal_path,
|
|
348
|
+
.notifications,
|
|
349
|
+
.recent_documents,
|
|
350
|
+
.credentials,
|
|
351
|
+
.file_drops,
|
|
352
|
+
.app_activation_events,
|
|
353
|
+
.gpu_surfaces,
|
|
354
|
+
.audio_playback,
|
|
355
|
+
.audio_streaming,
|
|
356
|
+
=> self.web_engine == .system,
|
|
357
|
+
// Spectrum analysis captures the app's OWN audio session
|
|
358
|
+
// through process-scoped WASAPI loopback, which the OS grew
|
|
359
|
+
// in Windows 10 2004 — the host probes the activation
|
|
360
|
+
// support live instead of assuming the build.
|
|
361
|
+
.audio_spectrum => self.web_engine == .system and audioSpectrumAvailable(self.host),
|
|
362
|
+
// Native scroll drivers, native context menus, and app-owned
|
|
363
|
+
// view-surface adoption are macOS-only today; Win32 keeps
|
|
364
|
+
// the engine's wheel physics (TrackPopupMenu is the natural
|
|
365
|
+
// future context-menu seam — the tray already uses it).
|
|
366
|
+
.gpu_surface_scroll_drivers, .context_menus, .view_surface_adoption => false,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/// Live probe for process-scoped loopback capture (the host asks
|
|
371
|
+
/// the audio activation API rather than trusting a version check).
|
|
372
|
+
/// Test builds link no Win32 host, so they answer the honest floor.
|
|
373
|
+
fn audioSpectrumAvailable(host: *WindowsHost) bool {
|
|
374
|
+
if (comptime @import("builtin").is_test) return false;
|
|
375
|
+
if (@import("builtin").target.os.tag != .windows) return false;
|
|
376
|
+
return native_sdk_windows_audio_spectrum_supported(host) != 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
fn run(context: *anyopaque, handler: platform_mod.EventHandler, handler_context: *anyopaque) anyerror!void {
|
|
380
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context));
|
|
381
|
+
self.state = .{
|
|
382
|
+
.self = self,
|
|
383
|
+
.handler = handler,
|
|
384
|
+
.handler_context = handler_context,
|
|
385
|
+
};
|
|
386
|
+
native_sdk_windows_set_bridge_callback(self.host, windowsBridgeCallback, &self.state);
|
|
387
|
+
native_sdk_windows_run(self.host, windowsCallback, &self.state);
|
|
388
|
+
if (self.state.failed) return error.CallbackFailed;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
fn windowById(self: *const WindowsPlatform, window_id: platform_mod.WindowId) platform_mod.WindowOptions {
|
|
392
|
+
var index: usize = 0;
|
|
393
|
+
while (index < self.app_info.startupWindowCount()) : (index += 1) {
|
|
394
|
+
const window = self.app_info.resolvedStartupWindow(index);
|
|
395
|
+
if (window.id == window_id) return window;
|
|
396
|
+
}
|
|
397
|
+
return .{ .id = window_id, .label = "", .title = self.app_info.resolvedWindowTitle() };
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const RunState = struct {
|
|
402
|
+
self: ?*WindowsPlatform = null,
|
|
403
|
+
handler: ?platform_mod.EventHandler = null,
|
|
404
|
+
handler_context: ?*anyopaque = null,
|
|
405
|
+
failed: bool = false,
|
|
406
|
+
|
|
407
|
+
fn emit(self: *RunState, event: platform_mod.Event) void {
|
|
408
|
+
const handler = self.handler orelse return;
|
|
409
|
+
const context = self.handler_context orelse return;
|
|
410
|
+
handler(context, event) catch {
|
|
411
|
+
self.failed = true;
|
|
412
|
+
if (self.self) |windows| native_sdk_windows_stop(windows.host);
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c) void {
|
|
418
|
+
const state: *RunState = @ptrCast(@alignCast(context.?));
|
|
419
|
+
switch (event.kind) {
|
|
420
|
+
.start => state.emit(.app_start),
|
|
421
|
+
.frame => state.emit(.frame_requested),
|
|
422
|
+
.shutdown => state.emit(.app_shutdown),
|
|
423
|
+
.app_activated => state.emit(.app_activated),
|
|
424
|
+
.app_deactivated => state.emit(.app_deactivated),
|
|
425
|
+
.files_dropped => {
|
|
426
|
+
var paths_buffer: [platform_mod.max_drop_paths][]const u8 = undefined;
|
|
427
|
+
const paths = platform_mod.splitDropPaths(event.drop_paths[0..event.drop_paths_len], paths_buffer[0..]);
|
|
428
|
+
state.emit(.{ .files_dropped = .{
|
|
429
|
+
.window_id = event.window_id,
|
|
430
|
+
.paths = paths,
|
|
431
|
+
} });
|
|
432
|
+
},
|
|
433
|
+
.resize => {
|
|
434
|
+
const surface: platform_mod.Surface = .{
|
|
435
|
+
.id = event.window_id,
|
|
436
|
+
.size = geometry.SizeF.init(@floatCast(event.width), @floatCast(event.height)),
|
|
437
|
+
.scale_factor = @floatCast(event.scale),
|
|
438
|
+
};
|
|
439
|
+
if (state.self) |windows| windows.surface_value = surface;
|
|
440
|
+
state.emit(.{ .surface_resized = surface });
|
|
441
|
+
},
|
|
442
|
+
.window_frame => if (state.self) |windows| {
|
|
443
|
+
const event_label = event.label[0..event.label_len];
|
|
444
|
+
const event_title = event.title[0..event.title_len];
|
|
445
|
+
const window = if (event_label.len > 0)
|
|
446
|
+
platform_mod.WindowOptions{ .id = event.window_id, .label = event_label, .title = event_title }
|
|
447
|
+
else
|
|
448
|
+
windows.windowById(event.window_id);
|
|
449
|
+
state.emit(.{ .window_frame_changed = .{
|
|
450
|
+
.id = window.id,
|
|
451
|
+
.label = window.label,
|
|
452
|
+
.title = window.resolvedTitle(windows.app_info.app_name),
|
|
453
|
+
.frame = geometry.RectF.init(@floatCast(event.x), @floatCast(event.y), @floatCast(event.width), @floatCast(event.height)),
|
|
454
|
+
.scale_factor = @floatCast(event.scale),
|
|
455
|
+
.open = event.open != 0,
|
|
456
|
+
.focused = event.focused != 0,
|
|
457
|
+
} });
|
|
458
|
+
},
|
|
459
|
+
.shortcut => state.emit(.{ .shortcut = .{
|
|
460
|
+
.id = event.shortcut_id[0..event.shortcut_id_len],
|
|
461
|
+
.key = event.shortcut_key[0..event.shortcut_key_len],
|
|
462
|
+
.modifiers = shortcutModifiersFromFlags(event.shortcut_modifiers),
|
|
463
|
+
.window_id = event.window_id,
|
|
464
|
+
} }),
|
|
465
|
+
.native_command => state.emit(.{ .native_command = .{
|
|
466
|
+
.name = event.command_name[0..event.command_name_len],
|
|
467
|
+
.window_id = event.window_id,
|
|
468
|
+
.view_label = event.view_label[0..event.view_label_len],
|
|
469
|
+
} }),
|
|
470
|
+
.menu_command => state.emit(.{ .menu_command = .{
|
|
471
|
+
.name = event.command_name[0..event.command_name_len],
|
|
472
|
+
.window_id = event.window_id,
|
|
473
|
+
} }),
|
|
474
|
+
.tray_action => state.emit(.{ .tray_action = event.tray_item_id }),
|
|
475
|
+
.gpu_surface_frame => state.emit(.{ .gpu_surface_frame = .{
|
|
476
|
+
.window_id = event.window_id,
|
|
477
|
+
.label = event.view_label[0..event.view_label_len],
|
|
478
|
+
.size = geometry.SizeF.init(@floatCast(event.width), @floatCast(event.height)),
|
|
479
|
+
.scale_factor = @floatCast(event.scale),
|
|
480
|
+
.frame_index = event.frame_index,
|
|
481
|
+
.timestamp_ns = event.timestamp_ns,
|
|
482
|
+
.frame_interval_ns = event.frame_interval_ns,
|
|
483
|
+
.nonblank = event.nonblank != 0,
|
|
484
|
+
.sample_color = event.sample_color,
|
|
485
|
+
.occluded = event.occluded != 0,
|
|
486
|
+
.backend = .software,
|
|
487
|
+
.pixel_format = .bgra8_unorm,
|
|
488
|
+
.present_mode = .timer,
|
|
489
|
+
.alpha_mode = .@"opaque",
|
|
490
|
+
.color_space = .srgb,
|
|
491
|
+
.vsync = true,
|
|
492
|
+
.status = .ready,
|
|
493
|
+
} }),
|
|
494
|
+
.gpu_surface_resize => state.emit(.{ .gpu_surface_resized = .{
|
|
495
|
+
.window_id = event.window_id,
|
|
496
|
+
.label = event.view_label[0..event.view_label_len],
|
|
497
|
+
.frame = geometry.RectF.init(@floatCast(event.x), @floatCast(event.y), @floatCast(event.width), @floatCast(event.height)),
|
|
498
|
+
.scale_factor = @floatCast(event.scale),
|
|
499
|
+
} }),
|
|
500
|
+
.gpu_surface_input => state.emit(.{ .gpu_surface_input = gpuSurfaceInputEventFromWindowsEvent(event) }),
|
|
501
|
+
.wake => state.emit(.wake),
|
|
502
|
+
.timer => state.emit(.{ .timer = .{
|
|
503
|
+
.id = event.timer_id,
|
|
504
|
+
.timestamp_ns = event.timestamp_ns,
|
|
505
|
+
} }),
|
|
506
|
+
.appearance => state.emit(.{ .appearance_changed = .{
|
|
507
|
+
.color_scheme = if (event.color_scheme == 1) .dark else .light,
|
|
508
|
+
.reduce_motion = event.reduce_motion != 0,
|
|
509
|
+
.high_contrast = event.high_contrast != 0,
|
|
510
|
+
} }),
|
|
511
|
+
.audio => state.emit(.{ .audio = .{
|
|
512
|
+
.kind = audioEventKindFromInt(event.audio_kind),
|
|
513
|
+
.position_ms = event.audio_position_ms,
|
|
514
|
+
.duration_ms = event.audio_duration_ms,
|
|
515
|
+
.playing = event.audio_playing != 0,
|
|
516
|
+
.buffering = event.audio_buffering != 0,
|
|
517
|
+
.bands = event.audio_bands,
|
|
518
|
+
} }),
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/// Ordinals match the audio report kinds in webview2_host.cpp (the same
|
|
523
|
+
/// set the macOS host uses); anything unknown degrades to `.failed` so a
|
|
524
|
+
/// host/SDK skew is loud in the app instead of undefined behavior here.
|
|
525
|
+
fn audioEventKindFromInt(value: c_int) platform_mod.AudioEventKind {
|
|
526
|
+
return switch (value) {
|
|
527
|
+
0 => .loaded,
|
|
528
|
+
1 => .position,
|
|
529
|
+
2 => .completed,
|
|
530
|
+
4 => .spectrum,
|
|
531
|
+
else => .failed,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
fn gpuSurfaceInputEventFromWindowsEvent(event: *const WindowsEvent) platform_mod.GpuSurfaceInputEvent {
|
|
536
|
+
return .{
|
|
537
|
+
.window_id = event.window_id,
|
|
538
|
+
.label = event.view_label[0..event.view_label_len],
|
|
539
|
+
.kind = gpuSurfaceInputKindFromInt(event.input_kind),
|
|
540
|
+
.timestamp_ns = event.timestamp_ns,
|
|
541
|
+
.x = @floatCast(event.x),
|
|
542
|
+
.y = @floatCast(event.y),
|
|
543
|
+
.button = event.button,
|
|
544
|
+
.delta_x = @floatCast(event.delta_x),
|
|
545
|
+
.delta_y = @floatCast(event.delta_y),
|
|
546
|
+
.key = event.key_text[0..event.key_text_len],
|
|
547
|
+
.text = event.input_text[0..event.input_text_len],
|
|
548
|
+
.composition_cursor = if (event.has_composition_cursor != 0) event.composition_cursor else null,
|
|
549
|
+
.modifiers = shortcutModifiersFromFlags(event.shortcut_modifiers),
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
fn gpuSurfaceInputKindFromInt(value: c_int) platform_mod.GpuSurfaceInputKind {
|
|
554
|
+
return switch (value) {
|
|
555
|
+
0 => .pointer_down,
|
|
556
|
+
1 => .pointer_up,
|
|
557
|
+
2 => .pointer_move,
|
|
558
|
+
3 => .pointer_drag,
|
|
559
|
+
4 => .scroll,
|
|
560
|
+
5 => .key_down,
|
|
561
|
+
6 => .key_up,
|
|
562
|
+
7 => .text_input,
|
|
563
|
+
8 => .ime_set_composition,
|
|
564
|
+
9 => .ime_commit_composition,
|
|
565
|
+
10 => .ime_cancel_composition,
|
|
566
|
+
11 => .pointer_cancel,
|
|
567
|
+
else => .pointer_move,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
fn windowsBridgeCallback(context: ?*anyopaque, window_id: u64, webview_label: [*]const u8, webview_label_len: usize, message: [*]const u8, message_len: usize, origin: [*]const u8, origin_len: usize) callconv(.c) void {
|
|
572
|
+
const state: *RunState = @ptrCast(@alignCast(context.?));
|
|
573
|
+
state.emit(.{ .bridge_message = .{
|
|
574
|
+
.bytes = message[0..message_len],
|
|
575
|
+
.origin = origin[0..origin_len],
|
|
576
|
+
.window_id = window_id,
|
|
577
|
+
.webview_label = webview_label[0..webview_label_len],
|
|
578
|
+
} });
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
fn readClipboard(context: ?*anyopaque, buffer: []u8) anyerror![]const u8 {
|
|
582
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
583
|
+
const len = native_sdk_windows_clipboard_read(self.host, buffer.ptr, buffer.len);
|
|
584
|
+
if (len > buffer.len) return error.NoSpaceLeft;
|
|
585
|
+
return buffer[0..len];
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
fn writeClipboard(context: ?*anyopaque, text: []const u8) anyerror!void {
|
|
589
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
590
|
+
native_sdk_windows_clipboard_write(self.host, text.ptr, text.len);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
fn readClipboardData(context: ?*anyopaque, mime_type: []const u8, buffer: []u8) anyerror![]const u8 {
|
|
594
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
595
|
+
const len = native_sdk_windows_clipboard_read_data(self.host, mime_type.ptr, mime_type.len, buffer.ptr, buffer.len);
|
|
596
|
+
if (len > buffer.len) return error.NoSpaceLeft;
|
|
597
|
+
return buffer[0..len];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
fn writeClipboardData(context: ?*anyopaque, data: platform_mod.ClipboardData) anyerror!void {
|
|
601
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
602
|
+
if (native_sdk_windows_clipboard_write_data(self.host, data.mime_type.ptr, data.mime_type.len, data.bytes.ptr, data.bytes.len) == 0) return error.UnsupportedService;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
fn loadWebView(context: ?*anyopaque, source: platform_mod.WebViewSource) anyerror!void {
|
|
606
|
+
try loadWindowWebView(context, 1, source);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
fn loadWindowWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, source: platform_mod.WebViewSource) anyerror!void {
|
|
610
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
611
|
+
const assets: platform_mod.WebViewAssetSource = source.asset_options orelse .{ .root_path = "", .entry = "", .origin = "", .spa_fallback = false };
|
|
612
|
+
native_sdk_windows_load_window_webview(
|
|
613
|
+
self.host,
|
|
614
|
+
window_id,
|
|
615
|
+
source.bytes.ptr,
|
|
616
|
+
source.bytes.len,
|
|
617
|
+
switch (source.kind) {
|
|
618
|
+
.html => 0,
|
|
619
|
+
.url => 1,
|
|
620
|
+
.assets => 2,
|
|
621
|
+
},
|
|
622
|
+
assets.root_path.ptr,
|
|
623
|
+
assets.root_path.len,
|
|
624
|
+
assets.entry.ptr,
|
|
625
|
+
assets.entry.len,
|
|
626
|
+
assets.origin.ptr,
|
|
627
|
+
assets.origin.len,
|
|
628
|
+
if (assets.spa_fallback) 1 else 0,
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
fn completeBridge(context: ?*anyopaque, response: []const u8) anyerror!void {
|
|
633
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
634
|
+
native_sdk_windows_bridge_respond(self.host, response.ptr, response.len);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
fn completeWindowBridge(context: ?*anyopaque, window_id: platform_mod.WindowId, response: []const u8) anyerror!void {
|
|
638
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
639
|
+
native_sdk_windows_bridge_respond_window(self.host, window_id, response.ptr, response.len);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
fn completeWebViewBridge(context: ?*anyopaque, window_id: platform_mod.WindowId, webview_label: []const u8, response: []const u8) anyerror!void {
|
|
643
|
+
if (std.mem.eql(u8, webview_label, "main")) return completeWindowBridge(context, window_id, response);
|
|
644
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
645
|
+
native_sdk_windows_bridge_respond_webview(self.host, window_id, webview_label.ptr, webview_label.len, response.ptr, response.len);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
fn emitWindowEvent(context: ?*anyopaque, window_id: platform_mod.WindowId, name: []const u8, detail_json: []const u8) anyerror!void {
|
|
649
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
650
|
+
native_sdk_windows_emit_window_event(self.host, window_id, name.ptr, name.len, detail_json.ptr, detail_json.len);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/// Thread-safe: `PostMessage` into the existing message loop, whose
|
|
654
|
+
/// window procedure emits `.wake` on the loop thread.
|
|
655
|
+
fn wake(context: ?*anyopaque) anyerror!void {
|
|
656
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
657
|
+
native_sdk_windows_wake(self.host);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/// Thread-safe like `wake`: `PostMessage` into the message loop, whose
|
|
661
|
+
/// window procedure emits one `.frame` event on the loop thread. The
|
|
662
|
+
/// automation arrival watcher calls this when a command lands so
|
|
663
|
+
/// consumption never depends on the host's own frame pump.
|
|
664
|
+
fn requestFrame(context: ?*anyopaque) anyerror!void {
|
|
665
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
666
|
+
native_sdk_windows_request_frame(self.host);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/// WIC-backed image decoding (PNG, JPEG, ... — every codec the OS
|
|
670
|
+
/// ships) into straight-alpha RGBA8.
|
|
671
|
+
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform_mod.DecodedImage {
|
|
672
|
+
_ = context;
|
|
673
|
+
var width: usize = 0;
|
|
674
|
+
var height: usize = 0;
|
|
675
|
+
return switch (native_sdk_windows_decode_image(bytes.ptr, bytes.len, buffer.ptr, buffer.len, &width, &height)) {
|
|
676
|
+
1 => .{ .width = width, .height = height, .rgba8 = buffer[0 .. width * height * 4] },
|
|
677
|
+
-1 => error.ImageTooLarge,
|
|
678
|
+
else => error.ImageDecodeFailed,
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
fn titlebarStyleInt(style: platform_mod.WindowTitlebarStyle) c_int {
|
|
683
|
+
return switch (style) {
|
|
684
|
+
.standard => 0,
|
|
685
|
+
.hidden_inset => 1,
|
|
686
|
+
.hidden_inset_tall => 2,
|
|
687
|
+
.chromeless => 3,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/// Zero/negative/non-finite floors are the "no floor" sentinel (the
|
|
692
|
+
/// host leaves that axis at its natural minimum).
|
|
693
|
+
fn minSizeFloor(value: f32) f64 {
|
|
694
|
+
return if (std.math.isFinite(value) and value > 0) value else 0;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyerror!platform_mod.WindowInfo {
|
|
698
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
699
|
+
const title = options.resolvedTitle(self.app_info.app_name);
|
|
700
|
+
const frame = options.default_frame;
|
|
701
|
+
if (native_sdk_windows_create_window(self.host, options.id, title.ptr, title.len, options.label.ptr, options.label.len, frame.x, frame.y, frame.width, frame.height, if (options.restore_state) 1 else 0, if (options.resizable) 1 else 0, titlebarStyleInt(options.titlebar), minSizeFloor(options.min_width), minSizeFloor(options.min_height)) == 0) return error.CreateFailed;
|
|
702
|
+
return .{
|
|
703
|
+
.id = options.id,
|
|
704
|
+
.label = options.label,
|
|
705
|
+
.title = title,
|
|
706
|
+
.frame = frame,
|
|
707
|
+
.scale_factor = 1,
|
|
708
|
+
.open = true,
|
|
709
|
+
.focused = false,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
fn focusWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
714
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
715
|
+
if (native_sdk_windows_focus_window(self.host, window_id) == 0) return error.FocusFailed;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
fn closeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
719
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
720
|
+
if (native_sdk_windows_close_window(self.host, window_id) == 0) return error.CloseFailed;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
724
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
725
|
+
if (native_sdk_windows_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
fn startWindowDrag(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
|
|
729
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
730
|
+
if (native_sdk_windows_start_window_drag(self.host, window_id) == 0) return error.WindowNotFound;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/// Drag-region mirror capacity per push: the runtime's own per-view cap
|
|
734
|
+
/// (`max_canvas_widget_window_drag_regions_per_view` = 32) bounds it in
|
|
735
|
+
/// practice; the flat buffers below are sized for that with headroom.
|
|
736
|
+
const max_drag_region_push: usize = 64;
|
|
737
|
+
|
|
738
|
+
/// Push the canvas view's window-drag region mirror to the host, which
|
|
739
|
+
/// answers `WM_NCHITTEST` with `HTCAPTION` inside a region (minus its
|
|
740
|
+
/// exclusions) so drag, double-click-maximize, and the right-click
|
|
741
|
+
/// system menu are the OS's own caption behavior on hidden-titlebar
|
|
742
|
+
/// windows.
|
|
743
|
+
fn setWindowDragRegions(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, regions: []const platform_mod.WindowDragRegion) anyerror!void {
|
|
744
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
745
|
+
if (regions.len > max_drag_region_push) return error.WindowLimitReached;
|
|
746
|
+
var rects: [max_drag_region_push * 4]f64 = undefined;
|
|
747
|
+
var exclusions: [max_drag_region_push]c_int = undefined;
|
|
748
|
+
for (regions, 0..) |region, index| {
|
|
749
|
+
rects[index * 4 + 0] = region.frame.x;
|
|
750
|
+
rects[index * 4 + 1] = region.frame.y;
|
|
751
|
+
rects[index * 4 + 2] = region.frame.width;
|
|
752
|
+
rects[index * 4 + 3] = region.frame.height;
|
|
753
|
+
exclusions[index] = if (region.exclusion) 1 else 0;
|
|
754
|
+
}
|
|
755
|
+
if (native_sdk_windows_set_window_drag_regions(self.host, window_id, label.ptr, label.len, &rects, &exclusions, regions.len) == 0) return error.ViewNotFound;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/// Chrome overlay geometry for hidden-titlebar windows: how far the
|
|
759
|
+
/// DWM-drawn caption-button band (top) and the min/max/close cluster
|
|
760
|
+
/// (trailing edge) overlay the content, plus the cluster's frame in
|
|
761
|
+
/// content coordinates — all in logical points. Standard-chrome windows
|
|
762
|
+
/// report zero.
|
|
763
|
+
fn windowChrome(context: ?*anyopaque, window_id: platform_mod.WindowId) platform_mod.WindowChrome {
|
|
764
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
765
|
+
var top: f64 = 0;
|
|
766
|
+
var left: f64 = 0;
|
|
767
|
+
var bottom: f64 = 0;
|
|
768
|
+
var right: f64 = 0;
|
|
769
|
+
var buttons_x: f64 = 0;
|
|
770
|
+
var buttons_y: f64 = 0;
|
|
771
|
+
var buttons_width: f64 = 0;
|
|
772
|
+
var buttons_height: f64 = 0;
|
|
773
|
+
if (native_sdk_windows_window_chrome(self.host, window_id, &top, &left, &bottom, &right, &buttons_x, &buttons_y, &buttons_width, &buttons_height) == 0) return .{};
|
|
774
|
+
return .{
|
|
775
|
+
.insets = .{
|
|
776
|
+
.top = @floatCast(top),
|
|
777
|
+
.left = @floatCast(left),
|
|
778
|
+
.bottom = @floatCast(bottom),
|
|
779
|
+
.right = @floatCast(right),
|
|
780
|
+
},
|
|
781
|
+
.buttons = geometry.RectF.init(@floatCast(buttons_x), @floatCast(buttons_y), @floatCast(buttons_width), @floatCast(buttons_height)),
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
fn startTimer(context: ?*anyopaque, id: u64, interval_ns: u64, repeats: bool) anyerror!void {
|
|
786
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
787
|
+
native_sdk_windows_start_timer(self.host, id, interval_ns, if (repeats) 1 else 0);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
fn cancelTimer(context: ?*anyopaque, id: u64) anyerror!void {
|
|
791
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
792
|
+
native_sdk_windows_cancel_timer(self.host, id);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
fn createView(context: ?*anyopaque, options: platform_mod.ViewOptions) anyerror!void {
|
|
796
|
+
if (options.kind == .webview) return createWebView(context, options.webViewOptions());
|
|
797
|
+
if (!isSupportedNativeViewKind(options.kind)) return error.UnsupportedViewKind;
|
|
798
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
799
|
+
if (self.web_engine != .system) return error.UnsupportedViewKind;
|
|
800
|
+
const frame = options.frame;
|
|
801
|
+
const parent = options.parent orelse "";
|
|
802
|
+
if (native_sdk_windows_create_view(
|
|
803
|
+
self.host,
|
|
804
|
+
options.window_id,
|
|
805
|
+
options.label.ptr,
|
|
806
|
+
options.label.len,
|
|
807
|
+
viewKindInt(options.kind),
|
|
808
|
+
parent.ptr,
|
|
809
|
+
parent.len,
|
|
810
|
+
frame.x,
|
|
811
|
+
frame.y,
|
|
812
|
+
frame.width,
|
|
813
|
+
frame.height,
|
|
814
|
+
options.layer,
|
|
815
|
+
if (options.visible) 1 else 0,
|
|
816
|
+
if (options.enabled) 1 else 0,
|
|
817
|
+
options.role.ptr,
|
|
818
|
+
options.role.len,
|
|
819
|
+
options.accessibility_label.ptr,
|
|
820
|
+
options.accessibility_label.len,
|
|
821
|
+
options.text.ptr,
|
|
822
|
+
options.text.len,
|
|
823
|
+
options.command.ptr,
|
|
824
|
+
options.command.len,
|
|
825
|
+
) == 0) return error.CreateFailed;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
fn updateView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, patch: platform_mod.ViewPatch) anyerror!void {
|
|
829
|
+
if (patch.url != null) return error.InvalidViewOptions;
|
|
830
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
831
|
+
if (self.web_engine != .system) return error.UnsupportedViewKind;
|
|
832
|
+
const frame = patch.frame orelse geometry.RectF.init(0, 0, 0, 0);
|
|
833
|
+
const role = patch.role orelse "";
|
|
834
|
+
const accessibility_label = patch.accessibility_label orelse "";
|
|
835
|
+
const text = patch.text orelse "";
|
|
836
|
+
const command = patch.command orelse "";
|
|
837
|
+
if (native_sdk_windows_update_view(
|
|
838
|
+
self.host,
|
|
839
|
+
window_id,
|
|
840
|
+
label.ptr,
|
|
841
|
+
label.len,
|
|
842
|
+
if (patch.frame != null) 1 else 0,
|
|
843
|
+
frame.x,
|
|
844
|
+
frame.y,
|
|
845
|
+
frame.width,
|
|
846
|
+
frame.height,
|
|
847
|
+
if (patch.layer != null) 1 else 0,
|
|
848
|
+
patch.layer orelse 0,
|
|
849
|
+
if (patch.visible != null) 1 else 0,
|
|
850
|
+
if (patch.visible orelse false) 1 else 0,
|
|
851
|
+
if (patch.enabled != null) 1 else 0,
|
|
852
|
+
if (patch.enabled orelse false) 1 else 0,
|
|
853
|
+
if (patch.role != null) 1 else 0,
|
|
854
|
+
role.ptr,
|
|
855
|
+
role.len,
|
|
856
|
+
if (patch.accessibility_label != null) 1 else 0,
|
|
857
|
+
accessibility_label.ptr,
|
|
858
|
+
accessibility_label.len,
|
|
859
|
+
if (patch.text != null) 1 else 0,
|
|
860
|
+
text.ptr,
|
|
861
|
+
text.len,
|
|
862
|
+
if (patch.command != null) 1 else 0,
|
|
863
|
+
command.ptr,
|
|
864
|
+
command.len,
|
|
865
|
+
) == 0) return error.ViewNotFound;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
fn setViewFrame(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
|
|
869
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
870
|
+
if (self.web_engine != .system) return error.UnsupportedViewKind;
|
|
871
|
+
if (native_sdk_windows_set_view_frame(self.host, window_id, label.ptr, label.len, frame.x, frame.y, frame.width, frame.height) == 0) return error.ViewNotFound;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
fn setViewVisible(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, visible: bool) anyerror!void {
|
|
875
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
876
|
+
if (self.web_engine != .system) return error.UnsupportedViewKind;
|
|
877
|
+
if (native_sdk_windows_set_view_visible(self.host, window_id, label.ptr, label.len, if (visible) 1 else 0) == 0) return error.ViewNotFound;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
fn focusView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
|
|
881
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
882
|
+
if (self.web_engine != .system) return error.UnsupportedViewFocus;
|
|
883
|
+
if (native_sdk_windows_focus_view(self.host, window_id, label.ptr, label.len) == 0) return error.UnsupportedViewFocus;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
fn closeView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
|
|
887
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
888
|
+
if (self.web_engine != .system) return error.UnsupportedViewKind;
|
|
889
|
+
if (native_sdk_windows_close_view(self.host, window_id, label.ptr, label.len) == 0) return error.ViewNotFound;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
fn requestGpuSurfaceFrame(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
|
|
893
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
894
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
895
|
+
if (native_sdk_windows_request_gpu_surface_frame(self.host, window_id, label.ptr, label.len) == 0) return error.ViewNotFound;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
fn noteGpuSurfaceInput(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
|
|
899
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
900
|
+
if (self.web_engine != .system) return;
|
|
901
|
+
_ = native_sdk_windows_note_gpu_surface_input(self.host, window_id, label.ptr, label.len);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: platform_mod.GpuSurfacePixels) anyerror!void {
|
|
905
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
906
|
+
if (self.web_engine != .system) return error.UnsupportedViewKind;
|
|
907
|
+
const dirty_bounds = if (pixels.dirty_bounds) |bounds| bounds.normalized() else geometry.RectF{};
|
|
908
|
+
if (native_sdk_windows_present_gpu_surface_pixels(
|
|
909
|
+
self.host,
|
|
910
|
+
pixels.window_id,
|
|
911
|
+
pixels.label.ptr,
|
|
912
|
+
pixels.label.len,
|
|
913
|
+
pixels.width,
|
|
914
|
+
pixels.height,
|
|
915
|
+
pixels.scale_factor,
|
|
916
|
+
if (pixels.dirty_bounds != null) 1 else 0,
|
|
917
|
+
dirty_bounds.x,
|
|
918
|
+
dirty_bounds.y,
|
|
919
|
+
dirty_bounds.width,
|
|
920
|
+
dirty_bounds.height,
|
|
921
|
+
pixels.rgba8.ptr,
|
|
922
|
+
pixels.rgba8.len,
|
|
923
|
+
) == 0) return error.ViewNotFound;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
fn createWebView(context: ?*anyopaque, options: platform_mod.WebViewOptions) anyerror!void {
|
|
927
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
928
|
+
const frame = options.frame;
|
|
929
|
+
if (native_sdk_windows_create_webview(self.host, options.window_id, options.label.ptr, options.label.len, options.url.ptr, options.url.len, frame.x, frame.y, frame.width, frame.height, options.layer, if (options.transparent) 1 else 0, if (options.bridge_enabled) 1 else 0) == 0) return error.CreateFailed;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
fn setWebViewFrame(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
|
|
933
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
934
|
+
if (native_sdk_windows_set_webview_frame(self.host, window_id, label.ptr, label.len, frame.x, frame.y, frame.width, frame.height) == 0) return error.WebViewNotFound;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
fn navigateWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, url: []const u8) anyerror!void {
|
|
938
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
939
|
+
if (std.mem.eql(u8, label, "main")) return error.InvalidWebViewOptions;
|
|
940
|
+
if (native_sdk_windows_navigate_webview(self.host, window_id, label.ptr, label.len, url.ptr, url.len) == 0) return error.WebViewNotFound;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
fn setWebViewZoom(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, zoom: f64) anyerror!void {
|
|
944
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
945
|
+
if (std.mem.eql(u8, label, "main")) return error.UnsupportedMainWebViewZoom;
|
|
946
|
+
if (native_sdk_windows_set_webview_zoom(self.host, window_id, label.ptr, label.len, zoom) == 0) return error.WebViewNotFound;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
fn setWebViewLayer(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8, layer: i32) anyerror!void {
|
|
950
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
951
|
+
if (self.web_engine != .system) {
|
|
952
|
+
if (std.mem.eql(u8, label, "main")) return error.UnsupportedMainWebViewLayer;
|
|
953
|
+
return error.UnsupportedChildWebViews;
|
|
954
|
+
}
|
|
955
|
+
if (native_sdk_windows_set_webview_layer(self.host, window_id, label.ptr, label.len, layer) == 0) return error.WebViewNotFound;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
fn closeWebView(context: ?*anyopaque, window_id: platform_mod.WindowId, label: []const u8) anyerror!void {
|
|
959
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
960
|
+
if (std.mem.eql(u8, label, "main")) return error.InvalidWebViewOptions;
|
|
961
|
+
if (native_sdk_windows_close_webview(self.host, window_id, label.ptr, label.len) == 0) return error.WebViewNotFound;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
fn showOpenDialog(context: ?*anyopaque, options: platform_mod.OpenDialogOptions, buffer: []u8) anyerror!platform_mod.OpenDialogResult {
|
|
965
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
966
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
967
|
+
var ext_buf: [1024]u8 = undefined;
|
|
968
|
+
const ext_str = flattenFilters(options.filters, &ext_buf);
|
|
969
|
+
const opts = WindowsOpenDialogOpts{
|
|
970
|
+
.title = options.title.ptr,
|
|
971
|
+
.title_len = options.title.len,
|
|
972
|
+
.default_path = options.default_path.ptr,
|
|
973
|
+
.default_path_len = options.default_path.len,
|
|
974
|
+
.extensions = ext_str.ptr,
|
|
975
|
+
.extensions_len = ext_str.len,
|
|
976
|
+
.allow_directories = if (options.allow_directories) 1 else 0,
|
|
977
|
+
.allow_multiple = if (options.allow_multiple) 1 else 0,
|
|
978
|
+
};
|
|
979
|
+
const result = native_sdk_windows_show_open_dialog(self.host, &opts, buffer.ptr, buffer.len);
|
|
980
|
+
if (result.bytes_written > buffer.len) return error.NoSpaceLeft;
|
|
981
|
+
return .{ .count = result.count, .paths = buffer[0..result.bytes_written] };
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
fn showSaveDialog(context: ?*anyopaque, options: platform_mod.SaveDialogOptions, buffer: []u8) anyerror!?[]const u8 {
|
|
985
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
986
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
987
|
+
var ext_buf: [1024]u8 = undefined;
|
|
988
|
+
const ext_str = flattenFilters(options.filters, &ext_buf);
|
|
989
|
+
const opts = WindowsSaveDialogOpts{
|
|
990
|
+
.title = options.title.ptr,
|
|
991
|
+
.title_len = options.title.len,
|
|
992
|
+
.default_path = options.default_path.ptr,
|
|
993
|
+
.default_path_len = options.default_path.len,
|
|
994
|
+
.default_name = options.default_name.ptr,
|
|
995
|
+
.default_name_len = options.default_name.len,
|
|
996
|
+
.extensions = ext_str.ptr,
|
|
997
|
+
.extensions_len = ext_str.len,
|
|
998
|
+
};
|
|
999
|
+
const written = native_sdk_windows_show_save_dialog(self.host, &opts, buffer.ptr, buffer.len);
|
|
1000
|
+
if (written > buffer.len) return error.NoSpaceLeft;
|
|
1001
|
+
if (written == 0) return null;
|
|
1002
|
+
return buffer[0..written];
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
fn showMessageDialog(context: ?*anyopaque, options: platform_mod.MessageDialogOptions) anyerror!platform_mod.MessageDialogResult {
|
|
1006
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1007
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1008
|
+
const opts = WindowsMessageDialogOpts{
|
|
1009
|
+
.style = @intFromEnum(options.style),
|
|
1010
|
+
.title = options.title.ptr,
|
|
1011
|
+
.title_len = options.title.len,
|
|
1012
|
+
.message = options.message.ptr,
|
|
1013
|
+
.message_len = options.message.len,
|
|
1014
|
+
.informative_text = options.informative_text.ptr,
|
|
1015
|
+
.informative_text_len = options.informative_text.len,
|
|
1016
|
+
.primary_button = options.primary_button.ptr,
|
|
1017
|
+
.primary_button_len = options.primary_button.len,
|
|
1018
|
+
.secondary_button = options.secondary_button.ptr,
|
|
1019
|
+
.secondary_button_len = options.secondary_button.len,
|
|
1020
|
+
.tertiary_button = options.tertiary_button.ptr,
|
|
1021
|
+
.tertiary_button_len = options.tertiary_button.len,
|
|
1022
|
+
};
|
|
1023
|
+
return @enumFromInt(native_sdk_windows_show_message_dialog(self.host, &opts));
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
fn showNotification(context: ?*anyopaque, options: platform_mod.NotificationOptions) anyerror!void {
|
|
1027
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1028
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1029
|
+
if (native_sdk_windows_show_notification(
|
|
1030
|
+
self.host,
|
|
1031
|
+
options.title.ptr,
|
|
1032
|
+
options.title.len,
|
|
1033
|
+
options.subtitle.ptr,
|
|
1034
|
+
options.subtitle.len,
|
|
1035
|
+
options.body.ptr,
|
|
1036
|
+
options.body.len,
|
|
1037
|
+
) == 0) return error.UnsupportedService;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
const max_tray_items: usize = 32;
|
|
1041
|
+
|
|
1042
|
+
fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
|
|
1043
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1044
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1045
|
+
if (native_sdk_windows_create_tray(self.host, options.icon_path.ptr, options.icon_path.len, options.tooltip.ptr, options.tooltip.len) == 0) return error.UnsupportedService;
|
|
1046
|
+
if (options.items.len > 0) {
|
|
1047
|
+
try updateTrayMenu(context, options.items);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem) anyerror!void {
|
|
1052
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1053
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1054
|
+
const count = @min(items.len, max_tray_items);
|
|
1055
|
+
var ids: [max_tray_items]u32 = undefined;
|
|
1056
|
+
var labels: [max_tray_items][*]const u8 = undefined;
|
|
1057
|
+
var label_lens: [max_tray_items]usize = undefined;
|
|
1058
|
+
var separators: [max_tray_items]c_int = undefined;
|
|
1059
|
+
var enabled_flags: [max_tray_items]c_int = undefined;
|
|
1060
|
+
for (items[0..count], 0..) |item, index| {
|
|
1061
|
+
ids[index] = item.id;
|
|
1062
|
+
labels[index] = item.label.ptr;
|
|
1063
|
+
label_lens[index] = item.label.len;
|
|
1064
|
+
separators[index] = if (item.separator) 1 else 0;
|
|
1065
|
+
enabled_flags[index] = if (item.enabled) 1 else 0;
|
|
1066
|
+
}
|
|
1067
|
+
if (native_sdk_windows_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, count) == 0) return error.UnsupportedService;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
fn removeTray(context: ?*anyopaque) anyerror!void {
|
|
1071
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1072
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1073
|
+
native_sdk_windows_remove_tray(self.host);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
fn openExternalUrl(context: ?*anyopaque, url: []const u8) anyerror!void {
|
|
1077
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1078
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1079
|
+
if (native_sdk_windows_open_external_url(self.host, url.ptr, url.len) == 0) return error.UnsupportedService;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
fn revealPath(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1083
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1084
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1085
|
+
if (native_sdk_windows_reveal_path(self.host, path.ptr, path.len) == 0) return error.UnsupportedService;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
fn addRecentDocument(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1089
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1090
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1091
|
+
if (native_sdk_windows_add_recent_document(self.host, path.ptr, path.len) == 0) return error.UnsupportedService;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
fn clearRecentDocuments(context: ?*anyopaque) anyerror!void {
|
|
1095
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1096
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1097
|
+
if (native_sdk_windows_clear_recent_documents(self.host) == 0) return error.UnsupportedService;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
fn setCredential(context: ?*anyopaque, credential: platform_mod.Credential) anyerror!void {
|
|
1101
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1102
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1103
|
+
if (native_sdk_windows_set_credential(
|
|
1104
|
+
self.host,
|
|
1105
|
+
credential.service.ptr,
|
|
1106
|
+
credential.service.len,
|
|
1107
|
+
credential.account.ptr,
|
|
1108
|
+
credential.account.len,
|
|
1109
|
+
credential.secret.ptr,
|
|
1110
|
+
credential.secret.len,
|
|
1111
|
+
) == 0) return error.UnsupportedService;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
fn getCredential(context: ?*anyopaque, key: platform_mod.CredentialKey, buffer: []u8) anyerror![]const u8 {
|
|
1115
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1116
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1117
|
+
const len = native_sdk_windows_get_credential(
|
|
1118
|
+
self.host,
|
|
1119
|
+
key.service.ptr,
|
|
1120
|
+
key.service.len,
|
|
1121
|
+
key.account.ptr,
|
|
1122
|
+
key.account.len,
|
|
1123
|
+
buffer.ptr,
|
|
1124
|
+
buffer.len,
|
|
1125
|
+
);
|
|
1126
|
+
if (len == 0) return error.CredentialNotFound;
|
|
1127
|
+
if (len > buffer.len) return error.NoSpaceLeft;
|
|
1128
|
+
return buffer[0..len];
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
fn deleteCredential(context: ?*anyopaque, key: platform_mod.CredentialKey) anyerror!void {
|
|
1132
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1133
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1134
|
+
if (native_sdk_windows_delete_credential(
|
|
1135
|
+
self.host,
|
|
1136
|
+
key.service.ptr,
|
|
1137
|
+
key.service.len,
|
|
1138
|
+
key.account.ptr,
|
|
1139
|
+
key.account.len,
|
|
1140
|
+
) == 0) return error.CredentialNotFound;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/// Map the audio host's synchronous load result: 0 loaded, 1 the file is
|
|
1144
|
+
/// missing/unreadable, anything else a decode failure. The asynchronous
|
|
1145
|
+
/// `.loaded` acknowledgment (with the decoded duration) follows as an
|
|
1146
|
+
/// `.audio` event on the message loop.
|
|
1147
|
+
fn audioLoad(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1148
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1149
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1150
|
+
return switch (native_sdk_windows_audio_load(self.host, path.ptr, path.len)) {
|
|
1151
|
+
0 => {},
|
|
1152
|
+
1 => error.AudioSourceNotFound,
|
|
1153
|
+
else => error.AudioDecodeFailed,
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/// Map the streaming host's synchronous result: 1 a verified cache entry
|
|
1158
|
+
/// is playing locally, 0 a progressive stream started (the `.loaded`
|
|
1159
|
+
/// acknowledgment follows when the topology is ready), anything else the
|
|
1160
|
+
/// URL itself was unusable. Network failures after this point are
|
|
1161
|
+
/// asynchronous and arrive as `.audio`/`.failed` events.
|
|
1162
|
+
fn audioLoadUrl(context: ?*anyopaque, url: []const u8, cache_path: []const u8, expected_bytes: u64) anyerror!platform_mod.AudioLoadResolution {
|
|
1163
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1164
|
+
if (self.web_engine != .system) return error.UnsupportedService;
|
|
1165
|
+
return switch (native_sdk_windows_audio_load_url(self.host, url.ptr, url.len, cache_path.ptr, cache_path.len, expected_bytes)) {
|
|
1166
|
+
0 => .stream,
|
|
1167
|
+
1 => .cache,
|
|
1168
|
+
else => error.InvalidAudioOptions,
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
fn audioPlay(context: ?*anyopaque) anyerror!void {
|
|
1173
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1174
|
+
if (native_sdk_windows_audio_play(self.host) == 0) return error.InvalidAudioOptions;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
fn audioPause(context: ?*anyopaque) anyerror!void {
|
|
1178
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1179
|
+
_ = native_sdk_windows_audio_pause(self.host);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
fn audioStop(context: ?*anyopaque) anyerror!void {
|
|
1183
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1184
|
+
_ = native_sdk_windows_audio_stop(self.host);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
fn audioSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
|
|
1188
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1189
|
+
if (native_sdk_windows_audio_seek(self.host, position_ms) == 0) return error.InvalidAudioOptions;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
|
|
1193
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1194
|
+
_ = native_sdk_windows_audio_set_volume(self.host, volume);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
fn configureSecurityPolicy(context: ?*anyopaque, policy: security.Policy) anyerror!void {
|
|
1198
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1199
|
+
var origins_buffer: [4096]u8 = undefined;
|
|
1200
|
+
var external_buffer: [4096]u8 = undefined;
|
|
1201
|
+
const origins = try policy_values.join(policy.navigation.allowed_origins, &origins_buffer);
|
|
1202
|
+
const external_urls = try policy_values.join(policy.navigation.external_links.allowed_urls, &external_buffer);
|
|
1203
|
+
native_sdk_windows_set_security_policy(
|
|
1204
|
+
self.host,
|
|
1205
|
+
origins.ptr,
|
|
1206
|
+
origins.len,
|
|
1207
|
+
external_urls.ptr,
|
|
1208
|
+
external_urls.len,
|
|
1209
|
+
@intFromEnum(policy.navigation.external_links.action),
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
fn configureMenus(context: ?*anyopaque, menus: []const platform_mod.Menu) anyerror!void {
|
|
1214
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1215
|
+
try platform_mod.validateMenus(menus);
|
|
1216
|
+
if (menus.len > 0 and self.web_engine != .system) return error.UnsupportedService;
|
|
1217
|
+
|
|
1218
|
+
var menu_titles: [platform_mod.max_menus][*]const u8 = undefined;
|
|
1219
|
+
var menu_title_lens: [platform_mod.max_menus]usize = undefined;
|
|
1220
|
+
var item_menu_indices: [platform_mod.max_menu_items]u32 = undefined;
|
|
1221
|
+
var item_labels: [platform_mod.max_menu_items][*]const u8 = undefined;
|
|
1222
|
+
var item_label_lens: [platform_mod.max_menu_items]usize = undefined;
|
|
1223
|
+
var item_commands: [platform_mod.max_menu_items][*]const u8 = undefined;
|
|
1224
|
+
var item_command_lens: [platform_mod.max_menu_items]usize = undefined;
|
|
1225
|
+
var item_keys: [platform_mod.max_menu_items][*]const u8 = undefined;
|
|
1226
|
+
var item_key_lens: [platform_mod.max_menu_items]usize = undefined;
|
|
1227
|
+
var item_modifiers: [platform_mod.max_menu_items]u32 = undefined;
|
|
1228
|
+
var item_separators: [platform_mod.max_menu_items]c_int = undefined;
|
|
1229
|
+
var item_enabled: [platform_mod.max_menu_items]c_int = undefined;
|
|
1230
|
+
var item_checked: [platform_mod.max_menu_items]c_int = undefined;
|
|
1231
|
+
|
|
1232
|
+
var item_count: usize = 0;
|
|
1233
|
+
for (menus, 0..) |menu, menu_index| {
|
|
1234
|
+
menu_titles[menu_index] = menu.title.ptr;
|
|
1235
|
+
menu_title_lens[menu_index] = menu.title.len;
|
|
1236
|
+
for (menu.items) |item| {
|
|
1237
|
+
item_menu_indices[item_count] = @intCast(menu_index);
|
|
1238
|
+
item_labels[item_count] = item.label.ptr;
|
|
1239
|
+
item_label_lens[item_count] = item.label.len;
|
|
1240
|
+
item_commands[item_count] = item.command.ptr;
|
|
1241
|
+
item_command_lens[item_count] = item.command.len;
|
|
1242
|
+
item_keys[item_count] = item.key.ptr;
|
|
1243
|
+
item_key_lens[item_count] = item.key.len;
|
|
1244
|
+
item_modifiers[item_count] = shortcutModifierFlags(item.modifiers);
|
|
1245
|
+
item_separators[item_count] = if (item.separator) 1 else 0;
|
|
1246
|
+
item_enabled[item_count] = if (item.enabled) 1 else 0;
|
|
1247
|
+
item_checked[item_count] = if (item.checked) 1 else 0;
|
|
1248
|
+
item_count += 1;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
native_sdk_windows_set_menus(
|
|
1253
|
+
self.host,
|
|
1254
|
+
menu_titles[0..menus.len].ptr,
|
|
1255
|
+
menu_title_lens[0..menus.len].ptr,
|
|
1256
|
+
menus.len,
|
|
1257
|
+
item_menu_indices[0..item_count].ptr,
|
|
1258
|
+
item_labels[0..item_count].ptr,
|
|
1259
|
+
item_label_lens[0..item_count].ptr,
|
|
1260
|
+
item_commands[0..item_count].ptr,
|
|
1261
|
+
item_command_lens[0..item_count].ptr,
|
|
1262
|
+
item_keys[0..item_count].ptr,
|
|
1263
|
+
item_key_lens[0..item_count].ptr,
|
|
1264
|
+
item_modifiers[0..item_count].ptr,
|
|
1265
|
+
item_separators[0..item_count].ptr,
|
|
1266
|
+
item_enabled[0..item_count].ptr,
|
|
1267
|
+
item_checked[0..item_count].ptr,
|
|
1268
|
+
item_count,
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
fn configureShortcuts(context: ?*anyopaque, shortcuts: []const platform_mod.Shortcut) anyerror!void {
|
|
1273
|
+
const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
|
|
1274
|
+
if (shortcuts.len > platform_mod.max_shortcuts) return error.InvalidShortcut;
|
|
1275
|
+
var ids: [platform_mod.max_shortcuts][*]const u8 = undefined;
|
|
1276
|
+
var id_lens: [platform_mod.max_shortcuts]usize = undefined;
|
|
1277
|
+
var keys: [platform_mod.max_shortcuts][*]const u8 = undefined;
|
|
1278
|
+
var key_lens: [platform_mod.max_shortcuts]usize = undefined;
|
|
1279
|
+
var modifiers: [platform_mod.max_shortcuts]u32 = undefined;
|
|
1280
|
+
for (shortcuts, 0..) |shortcut, index| {
|
|
1281
|
+
try platform_mod.validateShortcut(shortcut);
|
|
1282
|
+
ids[index] = shortcut.id.ptr;
|
|
1283
|
+
id_lens[index] = shortcut.id.len;
|
|
1284
|
+
keys[index] = shortcut.key.ptr;
|
|
1285
|
+
key_lens[index] = shortcut.key.len;
|
|
1286
|
+
modifiers[index] = shortcutModifierFlags(shortcut.modifiers);
|
|
1287
|
+
}
|
|
1288
|
+
native_sdk_windows_set_shortcuts(self.host, ids[0..shortcuts.len].ptr, id_lens[0..shortcuts.len].ptr, keys[0..shortcuts.len].ptr, key_lens[0..shortcuts.len].ptr, modifiers[0..shortcuts.len].ptr, shortcuts.len);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
fn shortcutModifierFlags(modifiers: platform_mod.ShortcutModifiers) u32 {
|
|
1292
|
+
var flags: u32 = 0;
|
|
1293
|
+
if (modifiers.primary) flags |= shortcut_modifier_primary;
|
|
1294
|
+
if (modifiers.command) flags |= shortcut_modifier_command;
|
|
1295
|
+
if (modifiers.control) flags |= shortcut_modifier_control;
|
|
1296
|
+
if (modifiers.option) flags |= shortcut_modifier_option;
|
|
1297
|
+
if (modifiers.shift) flags |= shortcut_modifier_shift;
|
|
1298
|
+
return flags;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
fn shortcutModifiersFromFlags(flags: u32) platform_mod.ShortcutModifiers {
|
|
1302
|
+
return .{
|
|
1303
|
+
.primary = (flags & shortcut_modifier_primary) != 0,
|
|
1304
|
+
.command = (flags & shortcut_modifier_command) != 0,
|
|
1305
|
+
.control = (flags & shortcut_modifier_control) != 0,
|
|
1306
|
+
.option = (flags & shortcut_modifier_option) != 0,
|
|
1307
|
+
.shift = (flags & shortcut_modifier_shift) != 0,
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
fn isSupportedNativeViewKind(kind: platform_mod.ViewKind) bool {
|
|
1312
|
+
return switch (kind) {
|
|
1313
|
+
.toolbar,
|
|
1314
|
+
.titlebar_accessory,
|
|
1315
|
+
.sidebar,
|
|
1316
|
+
.statusbar,
|
|
1317
|
+
.split,
|
|
1318
|
+
.stack,
|
|
1319
|
+
.button,
|
|
1320
|
+
.icon_button,
|
|
1321
|
+
.list_item,
|
|
1322
|
+
.checkbox,
|
|
1323
|
+
.toggle,
|
|
1324
|
+
.segmented_control,
|
|
1325
|
+
.text_field,
|
|
1326
|
+
.search_field,
|
|
1327
|
+
.label,
|
|
1328
|
+
.spacer,
|
|
1329
|
+
.progress_indicator,
|
|
1330
|
+
.gpu_surface,
|
|
1331
|
+
=> true,
|
|
1332
|
+
.webview,
|
|
1333
|
+
=> false,
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
test "windows supports native container and control kinds" {
|
|
1338
|
+
try std.testing.expect(isSupportedNativeViewKind(.split));
|
|
1339
|
+
try std.testing.expect(isSupportedNativeViewKind(.stack));
|
|
1340
|
+
try std.testing.expect(isSupportedNativeViewKind(.icon_button));
|
|
1341
|
+
try std.testing.expect(isSupportedNativeViewKind(.list_item));
|
|
1342
|
+
try std.testing.expect(isSupportedNativeViewKind(.gpu_surface));
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
test "windows gpu surface input preserves key and text" {
|
|
1346
|
+
const label = "canvas";
|
|
1347
|
+
const key = "enter";
|
|
1348
|
+
const text = "\n";
|
|
1349
|
+
var event = std.mem.zeroes(WindowsEvent);
|
|
1350
|
+
event.window_id = 7;
|
|
1351
|
+
event.view_label = label.ptr;
|
|
1352
|
+
event.view_label_len = label.len;
|
|
1353
|
+
event.input_kind = 5;
|
|
1354
|
+
event.timestamp_ns = 123_000_000;
|
|
1355
|
+
event.x = 12;
|
|
1356
|
+
event.y = 18;
|
|
1357
|
+
event.button = 1;
|
|
1358
|
+
event.delta_x = -2;
|
|
1359
|
+
event.delta_y = 4;
|
|
1360
|
+
event.key_text = key.ptr;
|
|
1361
|
+
event.key_text_len = key.len;
|
|
1362
|
+
event.input_text = text.ptr;
|
|
1363
|
+
event.input_text_len = text.len;
|
|
1364
|
+
event.shortcut_modifiers = shortcut_modifier_primary | shortcut_modifier_shift;
|
|
1365
|
+
|
|
1366
|
+
const input = gpuSurfaceInputEventFromWindowsEvent(&event);
|
|
1367
|
+
try std.testing.expectEqual(@as(platform_mod.WindowId, 7), input.window_id);
|
|
1368
|
+
try std.testing.expectEqualStrings("canvas", input.label);
|
|
1369
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.key_down, input.kind);
|
|
1370
|
+
try std.testing.expectEqual(@as(u64, 123_000_000), input.timestamp_ns);
|
|
1371
|
+
try std.testing.expectEqual(@as(f32, 12), input.x);
|
|
1372
|
+
try std.testing.expectEqual(@as(f32, 18), input.y);
|
|
1373
|
+
try std.testing.expectEqual(@as(i32, 1), input.button);
|
|
1374
|
+
try std.testing.expectEqual(@as(f32, -2), input.delta_x);
|
|
1375
|
+
try std.testing.expectEqual(@as(f32, 4), input.delta_y);
|
|
1376
|
+
try std.testing.expectEqualStrings("enter", input.key);
|
|
1377
|
+
try std.testing.expectEqualStrings("\n", input.text);
|
|
1378
|
+
try std.testing.expect(input.modifiers.primary);
|
|
1379
|
+
try std.testing.expect(input.modifiers.shift);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
test "windows gpu surface input maps pointer cancel" {
|
|
1383
|
+
var event = std.mem.zeroes(WindowsEvent);
|
|
1384
|
+
event.input_kind = 11;
|
|
1385
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.pointer_cancel, gpuSurfaceInputEventFromWindowsEvent(&event).kind);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
test "windows gpu surface input maps ime text and composition events" {
|
|
1389
|
+
// A GCS_COMPSTR preedit update: kind 8 carries the full preedit text
|
|
1390
|
+
// plus a UTF-8 byte cursor (the host converts GCS_CURSORPOS UTF-16
|
|
1391
|
+
// units into bytes before emitting).
|
|
1392
|
+
const preedit = "\xe3\x81\x8b\xe3\x82\x99"; // "か" + combining voiced mark
|
|
1393
|
+
var set_event = std.mem.zeroes(WindowsEvent);
|
|
1394
|
+
set_event.input_kind = 8;
|
|
1395
|
+
set_event.input_text = preedit.ptr;
|
|
1396
|
+
set_event.input_text_len = preedit.len;
|
|
1397
|
+
set_event.has_composition_cursor = 1;
|
|
1398
|
+
set_event.composition_cursor = 3;
|
|
1399
|
+
const set_input = gpuSurfaceInputEventFromWindowsEvent(&set_event);
|
|
1400
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.ime_set_composition, set_input.kind);
|
|
1401
|
+
try std.testing.expectEqualStrings(preedit, set_input.text);
|
|
1402
|
+
try std.testing.expectEqual(@as(?usize, 3), set_input.composition_cursor);
|
|
1403
|
+
|
|
1404
|
+
// A GCS_RESULTSTR commit that differs from the preedit arrives as a
|
|
1405
|
+
// plain text_input with no cursor (the cancel travelled separately).
|
|
1406
|
+
var text_event = std.mem.zeroes(WindowsEvent);
|
|
1407
|
+
text_event.input_kind = 7;
|
|
1408
|
+
const committed = "が";
|
|
1409
|
+
text_event.input_text = committed.ptr;
|
|
1410
|
+
text_event.input_text_len = committed.len;
|
|
1411
|
+
const text_input = gpuSurfaceInputEventFromWindowsEvent(&text_event);
|
|
1412
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.text_input, text_input.kind);
|
|
1413
|
+
try std.testing.expectEqualStrings(committed, text_input.text);
|
|
1414
|
+
try std.testing.expectEqual(@as(?usize, null), text_input.composition_cursor);
|
|
1415
|
+
|
|
1416
|
+
// Commit-of-preedit and cancel are empty-text notifications: the
|
|
1417
|
+
// runtime already buffers the composition text.
|
|
1418
|
+
var commit_event = std.mem.zeroes(WindowsEvent);
|
|
1419
|
+
commit_event.input_kind = 9;
|
|
1420
|
+
const commit_input = gpuSurfaceInputEventFromWindowsEvent(&commit_event);
|
|
1421
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.ime_commit_composition, commit_input.kind);
|
|
1422
|
+
try std.testing.expectEqual(@as(usize, 0), commit_input.text.len);
|
|
1423
|
+
try std.testing.expectEqual(@as(?usize, null), commit_input.composition_cursor);
|
|
1424
|
+
|
|
1425
|
+
var cancel_event = std.mem.zeroes(WindowsEvent);
|
|
1426
|
+
cancel_event.input_kind = 10;
|
|
1427
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.ime_cancel_composition, gpuSurfaceInputEventFromWindowsEvent(&cancel_event).kind);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
test "windows chromium reports unsupported native surfaces" {
|
|
1431
|
+
var system = testPlatformWithEngine(.system);
|
|
1432
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .main_webview));
|
|
1433
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .child_webviews));
|
|
1434
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .native_views));
|
|
1435
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .native_control_commands));
|
|
1436
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .menus));
|
|
1437
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .gpu_surfaces));
|
|
1438
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .audio_playback));
|
|
1439
|
+
try std.testing.expect(WindowsPlatform.supportsFeature(&system, .audio_streaming));
|
|
1440
|
+
|
|
1441
|
+
var chromium = testPlatformWithEngine(.chromium);
|
|
1442
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .main_webview));
|
|
1443
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .child_webviews));
|
|
1444
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .native_views));
|
|
1445
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .native_control_commands));
|
|
1446
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .menus));
|
|
1447
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .shortcuts));
|
|
1448
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .gpu_surfaces));
|
|
1449
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .audio_playback));
|
|
1450
|
+
try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .audio_streaming));
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
test "windows audio event maps kinds and payload" {
|
|
1454
|
+
var event = std.mem.zeroes(WindowsEvent);
|
|
1455
|
+
event.audio_kind = 1;
|
|
1456
|
+
event.audio_position_ms = 1_500;
|
|
1457
|
+
event.audio_duration_ms = 120_000;
|
|
1458
|
+
event.audio_playing = 1;
|
|
1459
|
+
event.audio_buffering = 1;
|
|
1460
|
+
try std.testing.expectEqual(platform_mod.AudioEventKind.position, audioEventKindFromInt(event.audio_kind));
|
|
1461
|
+
try std.testing.expectEqual(platform_mod.AudioEventKind.loaded, audioEventKindFromInt(0));
|
|
1462
|
+
try std.testing.expectEqual(platform_mod.AudioEventKind.completed, audioEventKindFromInt(2));
|
|
1463
|
+
// Unknown ordinals degrade loudly to failed, never to silence.
|
|
1464
|
+
try std.testing.expectEqual(platform_mod.AudioEventKind.failed, audioEventKindFromInt(3));
|
|
1465
|
+
try std.testing.expectEqual(platform_mod.AudioEventKind.failed, audioEventKindFromInt(99));
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
fn testPlatformWithEngine(web_engine: platform_mod.WebEngine) WindowsPlatform {
|
|
1469
|
+
return .{
|
|
1470
|
+
.host = undefined,
|
|
1471
|
+
.web_engine = web_engine,
|
|
1472
|
+
.app_info = .{},
|
|
1473
|
+
.surface_value = .{},
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
fn viewKindInt(kind: platform_mod.ViewKind) c_int {
|
|
1478
|
+
return switch (kind) {
|
|
1479
|
+
.webview => 0,
|
|
1480
|
+
.toolbar => 1,
|
|
1481
|
+
.titlebar_accessory => 2,
|
|
1482
|
+
.sidebar => 3,
|
|
1483
|
+
.statusbar => 4,
|
|
1484
|
+
.split => 5,
|
|
1485
|
+
.stack => 6,
|
|
1486
|
+
.button => 7,
|
|
1487
|
+
.icon_button => 17,
|
|
1488
|
+
.list_item => 18,
|
|
1489
|
+
.text_field => 8,
|
|
1490
|
+
.search_field => 9,
|
|
1491
|
+
.label => 10,
|
|
1492
|
+
.spacer => 11,
|
|
1493
|
+
.gpu_surface => 12,
|
|
1494
|
+
.checkbox => 13,
|
|
1495
|
+
.toggle => 14,
|
|
1496
|
+
.progress_indicator => 15,
|
|
1497
|
+
.segmented_control => 16,
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
fn flattenFilters(filters: []const platform_mod.FileFilter, buffer: []u8) []const u8 {
|
|
1502
|
+
var offset: usize = 0;
|
|
1503
|
+
for (filters) |filter| {
|
|
1504
|
+
for (filter.extensions) |ext| {
|
|
1505
|
+
if (offset > 0 and offset < buffer.len) {
|
|
1506
|
+
buffer[offset] = ';';
|
|
1507
|
+
offset += 1;
|
|
1508
|
+
}
|
|
1509
|
+
const end = @min(offset + ext.len, buffer.len);
|
|
1510
|
+
if (end > offset) {
|
|
1511
|
+
@memcpy(buffer[offset..end], ext[0..(end - offset)]);
|
|
1512
|
+
offset = end;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return buffer[0..offset];
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
test "windows platform module exports type" {
|
|
1520
|
+
_ = WindowsPlatform;
|
|
1521
|
+
}
|