@native-sdk/cli 0.11.0 → 0.11.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/build/app.zig +73 -37
- package/build.zig +239 -5
- package/native-sdk.d.ts +5 -1
- package/package.json +13 -12
- package/packages/core/compile-surface/core.ts +30 -0
- package/packages/core/package-lock.json +6 -6
- package/packages/core/package.json +3 -3
- package/packages/core/scripts/scriptc-toolchain.json +44 -44
- package/packages/core/scripts/stage_external_core.mjs +27 -16
- package/packages/core/sdk/core.d.ts +24 -1
- package/packages/core/sdk/core.ts +51 -1
- package/packages/core/sdk/events.d.ts +5 -0
- package/packages/core/sdk/events.ts +10 -0
- package/packages/core/src/bridge_descriptors.ts +3 -3
- package/packages/core/src/checker.ts +20 -0
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/portable_sources.json +24 -0
- package/packages/core/src/registered_font.ts +2 -3
- package/packages/core/src/runtime_policy.ts +24 -0
- package/packages/core/src/scalar_text.ts +1 -3
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +53 -2
- package/packages/core/src/sqlite_cli.ts +3 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +340 -218
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/skill-data/native-ui/SKILL.md +2 -2
- package/skill-data/ts-core/SKILL.md +5 -3
- package/skill-data/ts-services/references/service-surface.md +29 -5
- package/src/app_runner/root.zig +14 -0
- package/src/app_runner/ts_compiled_view.zig +88 -17
- package/src/app_runner/ts_core_main.zig +43 -5
- package/src/app_runner/ts_core_mobile.zig +1 -1
- package/src/automation/server.zig +56 -3
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +31 -9
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/null_platform.zig +104 -0
- package/src/platform/root.zig +14 -0
- package/src/platform/types.zig +102 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +15 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/reference.zig +3 -5
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +1 -1
- package/src/primitives/canvas/root.zig +7 -4
- package/src/primitives/canvas/text_metrics.zig +32 -39
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +142 -3
- package/src/primitives/canvas/text_scalar_policy.zig +80 -2
- package/src/primitives/canvas/tokens.zig +9 -0
- package/src/primitives/canvas/ui.zig +1 -0
- package/src/primitives/canvas/ui_markup.zig +69 -14
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +2817 -74
- package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
- package/src/primitives/canvas/virtual_extents.zig +47 -33
- package/src/primitives/canvas/widget_metric_policy.zig +4 -1
- package/src/primitives/canvas/widget_runtime.zig +2 -1
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +1 -0
- package/src/runtime/bridge_descriptor_policy.zig +1 -1
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/canvas_widget_context_menu.zig +179 -0
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_runtime.zig +306 -92
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +14 -0
- package/src/runtime/effects.zig +172 -4
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/flow.zig +1 -0
- package/src/runtime/flow_reference.zig +1 -0
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/root.zig +3 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_record.zig +7 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/system_services.zig +19 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +126 -0
- package/src/runtime/ts_ui_app.zig +24 -0
- package/src/runtime/ui_app.zig +274 -31
- package/src/runtime/ui_app_tests.zig +48 -179
- package/src/runtime/ui_app_window_tests.zig +133 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_scroll.zig +30 -21
- package/src/runtime/view_widget_tree.zig +43 -13
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_views.zig +19 -4
- package/src/security/root.zig +1 -0
- package/src/tooling/templates.zig +8 -0
- package/src/tooling/ts_core.zig +84 -1
- package/src/tooling/verbs.zig +79 -15
- package/tools/corewire/core.test.ts +25 -3
- package/tools/corewire/core_abi.zig +4 -0
- package/tools/corewire/core_contract.ts +1 -1
- package/tools/corewire/core_goldens.json +75 -75
- package/tools/corewire/core_projection.ts +3 -2
- package/tools/corewire/emit_mirror.ts +19 -9
- package/tools/corewire/facade_templates.ts +1 -1
- package/tools/corewire/intake.test.ts +4 -0
- package/tools/corewire/intake_goldens.json +50 -50
- package/tools/corewire/invocation.test.ts +4 -0
- package/tools/corewire/invocation_goldens.json +3 -3
- package/tools/corewire/mirror_templates.ts +4 -0
- package/tools/corewire/profile_emission.ts +2 -0
- package/tools/corewire/sidecar.zig +2 -0
|
@@ -68,6 +68,7 @@ const max_menu_key_bytes = types.max_menu_key_bytes;
|
|
|
68
68
|
const max_shortcuts = types.max_shortcuts;
|
|
69
69
|
const max_shortcut_id_bytes = types.max_shortcut_id_bytes;
|
|
70
70
|
const max_shortcut_key_bytes = types.max_shortcut_key_bytes;
|
|
71
|
+
const max_global_shortcuts = types.max_global_shortcuts;
|
|
71
72
|
const max_widget_accessibility_nodes = types.max_widget_accessibility_nodes;
|
|
72
73
|
const max_gpu_surface_packet_json_bytes = types.max_gpu_surface_packet_json_bytes;
|
|
73
74
|
const ShortcutModifiers = types.ShortcutModifiers;
|
|
@@ -297,6 +298,11 @@ pub const NullAudio = struct {
|
|
|
297
298
|
}
|
|
298
299
|
};
|
|
299
300
|
|
|
301
|
+
pub const NullGlobalShortcut = struct {
|
|
302
|
+
binding: types.OwnedShortcut,
|
|
303
|
+
pressed: bool = false,
|
|
304
|
+
};
|
|
305
|
+
|
|
300
306
|
pub const NullAudioCapture = struct {
|
|
301
307
|
active: bool = false,
|
|
302
308
|
format: types.AudioCaptureFormat = .{},
|
|
@@ -398,6 +404,10 @@ pub const NullPlatform = struct {
|
|
|
398
404
|
/// like `windows` — same seam-regression purpose as
|
|
399
405
|
/// `window_resizable` (the startup create used to hardcode it).
|
|
400
406
|
window_titlebar: [max_windows]WindowTitlebarStyle = [_]WindowTitlebarStyle{.standard} ** max_windows,
|
|
407
|
+
window_color_scheme: [max_windows]types.WindowColorScheme = @splat(.system),
|
|
408
|
+
/// Source-less test harnesses have an implicit primary window rather
|
|
409
|
+
/// than a createWindow entry, just like the main canvas surface.
|
|
410
|
+
main_window_color_scheme: types.WindowColorScheme = .system,
|
|
401
411
|
/// Captured independently from `restore_state`: persistence opt-in does
|
|
402
412
|
/// not mean a frame was actually found and restored.
|
|
403
413
|
window_placement: [max_windows]WindowInitialPlacement = [_]WindowInitialPlacement{.default} ** max_windows,
|
|
@@ -466,6 +476,13 @@ pub const NullPlatform = struct {
|
|
|
466
476
|
dock_presence_count: u32 = 0,
|
|
467
477
|
launch_at_login_status: types.LaunchAtLoginStatus = .disabled,
|
|
468
478
|
launch_at_login_set_count: u32 = 0,
|
|
479
|
+
/// Set false before `platform()` to model a host without keyboard input.
|
|
480
|
+
keyboard_input: bool = true,
|
|
481
|
+
/// `.denied` makes posts fail like a macOS app without the Accessibility grant.
|
|
482
|
+
keyboard_input_access: types.KeyboardInputAccess = .granted,
|
|
483
|
+
keyboard_input_prompt_count: u32 = 0,
|
|
484
|
+
keyboard_chords: [32]types.KeyChord = undefined,
|
|
485
|
+
keyboard_chord_count: usize = 0,
|
|
469
486
|
/// Captured `WindowOptions.min_width`/`min_height` per created
|
|
470
487
|
/// window — the content min-size floor that must survive to the
|
|
471
488
|
/// create seam (macOS applies it as `contentMinSize`); same
|
|
@@ -722,6 +739,11 @@ pub const NullPlatform = struct {
|
|
|
722
739
|
microphone_capture: bool = true,
|
|
723
740
|
system_audio_capture: bool = true,
|
|
724
741
|
audio_captures: [2]NullAudioCapture = [_]NullAudioCapture{.{}} ** 2,
|
|
742
|
+
/// Model a host with system-wide shortcuts; false models Linux.
|
|
743
|
+
global_shortcuts: bool = true,
|
|
744
|
+
global_shortcut_entries: [max_global_shortcuts]NullGlobalShortcut = undefined,
|
|
745
|
+
global_shortcut_count: usize = 0,
|
|
746
|
+
global_shortcut_sink: types.GlobalShortcutSink = .{},
|
|
725
747
|
/// Whether this modeled host has a video decoder. On by default (the
|
|
726
748
|
/// fake below stands in for AVFoundation); tests modelling a staged
|
|
727
749
|
/// host (Windows/Linux today) set it false BEFORE `platform()` so
|
|
@@ -926,6 +948,7 @@ pub const NullPlatform = struct {
|
|
|
926
948
|
.quit_app_fn = quitApp,
|
|
927
949
|
.start_window_drag_fn = startWindowDrag,
|
|
928
950
|
.window_chrome_fn = windowChrome,
|
|
951
|
+
.set_window_color_scheme_fn = setWindowColorScheme,
|
|
929
952
|
.set_window_drag_regions_fn = setWindowDragRegions,
|
|
930
953
|
.create_view_fn = createView,
|
|
931
954
|
.update_view_fn = updateView,
|
|
@@ -957,6 +980,8 @@ pub const NullPlatform = struct {
|
|
|
957
980
|
.remove_tray_fn = removeTray,
|
|
958
981
|
.open_external_url_fn = openExternalUrl,
|
|
959
982
|
.reveal_path_fn = revealPath,
|
|
983
|
+
.send_key_chord_fn = if (self.keyboard_input) sendKeyChord else null,
|
|
984
|
+
.keyboard_input_access_fn = if (self.keyboard_input) keyboardInputAccess else null,
|
|
960
985
|
.add_recent_document_fn = addRecentDocument,
|
|
961
986
|
.clear_recent_documents_fn = clearRecentDocuments,
|
|
962
987
|
.configure_security_policy_fn = configureSecurityPolicy,
|
|
@@ -972,6 +997,7 @@ pub const NullPlatform = struct {
|
|
|
972
997
|
.audio_stop_fn = if (self.audio_playback) audioStop else null,
|
|
973
998
|
.audio_seek_fn = if (self.audio_playback) audioSeek else null,
|
|
974
999
|
.audio_set_volume_fn = if (self.audio_playback) audioSetVolume else null,
|
|
1000
|
+
.configure_global_shortcuts_fn = if (self.global_shortcuts) configureGlobalShortcuts else null,
|
|
975
1001
|
.audio_capture_start_fn = if (self.microphone_capture or self.system_audio_capture) audioCaptureStart else null,
|
|
976
1002
|
.audio_capture_stop_fn = if (self.microphone_capture or self.system_audio_capture) audioCaptureStop else null,
|
|
977
1003
|
.video_load_fn = if (self.video_playback) videoLoad else null,
|
|
@@ -1041,6 +1067,8 @@ pub const NullPlatform = struct {
|
|
|
1041
1067
|
.microphone_capture => self.microphone_capture,
|
|
1042
1068
|
.system_audio_capture => self.system_audio_capture,
|
|
1043
1069
|
.video_playback => self.video_playback,
|
|
1070
|
+
.global_shortcuts => self.global_shortcuts,
|
|
1071
|
+
.keyboard_input => self.keyboard_input,
|
|
1044
1072
|
};
|
|
1045
1073
|
}
|
|
1046
1074
|
|
|
@@ -1190,6 +1218,7 @@ pub const NullPlatform = struct {
|
|
|
1190
1218
|
self.windows[self.window_count] = info;
|
|
1191
1219
|
self.window_resizable[self.window_count] = options.resizable;
|
|
1192
1220
|
self.window_titlebar[self.window_count] = options.titlebar;
|
|
1221
|
+
self.window_color_scheme[self.window_count] = .system;
|
|
1193
1222
|
self.window_placement[self.window_count] = options.initial_placement;
|
|
1194
1223
|
self.window_restore_policy[self.window_count] = options.restore_policy;
|
|
1195
1224
|
self.window_transparent[self.window_count] = options.transparent;
|
|
@@ -1901,6 +1930,24 @@ pub const NullPlatform = struct {
|
|
|
1901
1930
|
self.revealed_path_len = (try copyInto(&self.revealed_path, path)).len;
|
|
1902
1931
|
}
|
|
1903
1932
|
|
|
1933
|
+
fn sendKeyChord(context: ?*anyopaque, chord: types.KeyChord) anyerror!void {
|
|
1934
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1935
|
+
if (self.keyboard_input_access == .denied) return error.KeyboardInputAccessDenied;
|
|
1936
|
+
if (self.keyboard_chord_count == self.keyboard_chords.len) return error.KeyboardInputFailed;
|
|
1937
|
+
self.keyboard_chords[self.keyboard_chord_count] = chord;
|
|
1938
|
+
self.keyboard_chord_count += 1;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
fn keyboardInputAccess(context: ?*anyopaque, prompt: bool) anyerror!types.KeyboardInputAccess {
|
|
1942
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1943
|
+
if (prompt and self.keyboard_input_access == .denied) self.keyboard_input_prompt_count += 1;
|
|
1944
|
+
return self.keyboard_input_access;
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
pub fn keyboardChords(self: *const NullPlatform) []const types.KeyChord {
|
|
1948
|
+
return self.keyboard_chords[0..self.keyboard_chord_count];
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1904
1951
|
fn addRecentDocument(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1905
1952
|
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1906
1953
|
self.recent_document_path = undefined;
|
|
@@ -2065,6 +2112,46 @@ pub const NullPlatform = struct {
|
|
|
2065
2112
|
capture.stop_count += 1;
|
|
2066
2113
|
}
|
|
2067
2114
|
|
|
2115
|
+
fn configureGlobalShortcuts(context: ?*anyopaque, shortcuts: []const Shortcut, sink: types.GlobalShortcutSink, statuses: []types.GlobalShortcutStatus) anyerror!void {
|
|
2116
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
2117
|
+
self.global_shortcut_sink = sink;
|
|
2118
|
+
var next: [max_global_shortcuts]NullGlobalShortcut = undefined;
|
|
2119
|
+
var count: usize = 0;
|
|
2120
|
+
for (shortcuts, statuses) |shortcut, *status| {
|
|
2121
|
+
status.* = .registered;
|
|
2122
|
+
for (next[0..count]) |*entry| {
|
|
2123
|
+
if (types.sameShortcutCombination(entry.binding.shortcut(), shortcut)) status.* = .conflict;
|
|
2124
|
+
}
|
|
2125
|
+
if (status.* == .conflict) continue;
|
|
2126
|
+
next[count] = .{ .binding = .init(shortcut) };
|
|
2127
|
+
for (self.configuredGlobalShortcuts()) |*previous| next[count].pressed = next[count].pressed or (previous.pressed and previous.binding.matches(shortcut));
|
|
2128
|
+
count += 1;
|
|
2129
|
+
}
|
|
2130
|
+
for (self.configuredGlobalShortcuts()) |*previous| {
|
|
2131
|
+
if (!previous.pressed) continue;
|
|
2132
|
+
for (next[0..count]) |*entry| {
|
|
2133
|
+
if (entry.binding.matches(previous.binding.shortcut())) break;
|
|
2134
|
+
} else sink.push(.{ .shortcut = previous.binding.shortcut(), .phase = .released });
|
|
2135
|
+
}
|
|
2136
|
+
@memcpy(self.global_shortcut_entries[0..count], next[0..count]);
|
|
2137
|
+
self.global_shortcut_count = count;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
pub fn configuredGlobalShortcuts(self: *const NullPlatform) []const NullGlobalShortcut {
|
|
2141
|
+
return self.global_shortcut_entries[0..self.global_shortcut_count];
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
/// Simulate pressing or releasing a registered global shortcut.
|
|
2145
|
+
pub fn pushGlobalShortcut(self: *NullPlatform, id: []const u8, phase: types.GlobalShortcutPhase) bool {
|
|
2146
|
+
for (self.global_shortcut_entries[0..self.global_shortcut_count]) |*entry| {
|
|
2147
|
+
if (!std.mem.eql(u8, entry.binding.shortcut().id, id) or entry.pressed == (phase == .pressed)) continue;
|
|
2148
|
+
entry.pressed = phase == .pressed;
|
|
2149
|
+
self.global_shortcut_sink.push(.{ .shortcut = entry.binding.shortcut(), .phase = phase });
|
|
2150
|
+
return true;
|
|
2151
|
+
}
|
|
2152
|
+
return false;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2068
2155
|
/// Push deterministic PCM through a live fake capture.
|
|
2069
2156
|
pub fn pushAudioCapture(self: *NullPlatform, source: types.AudioCaptureSource, timestamp_ns: u64, pcm_s16le: []const u8) types.AudioCapturePushResult {
|
|
2070
2157
|
const capture = &self.audio_captures[@intFromEnum(source)];
|
|
@@ -3007,6 +3094,22 @@ pub const NullPlatform = struct {
|
|
|
3007
3094
|
return self.window_show_count[index];
|
|
3008
3095
|
}
|
|
3009
3096
|
|
|
3097
|
+
fn setWindowColorScheme(context: ?*anyopaque, window_id: WindowId, scheme: types.WindowColorScheme) anyerror!void {
|
|
3098
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
3099
|
+
const index = self.findWindowIndex(window_id) orelse {
|
|
3100
|
+
if (window_id != 1) return error.WindowNotFound;
|
|
3101
|
+
self.main_window_color_scheme = scheme;
|
|
3102
|
+
return;
|
|
3103
|
+
};
|
|
3104
|
+
if (!self.windows[index].open) return error.WindowNotFound;
|
|
3105
|
+
self.window_color_scheme[index] = scheme;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
pub fn windowColorScheme(self: *const NullPlatform, window_id: WindowId) ?types.WindowColorScheme {
|
|
3109
|
+
const index = self.findWindowIndex(window_id) orelse return if (window_id == 1) self.main_window_color_scheme else null;
|
|
3110
|
+
return self.window_color_scheme[index];
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3010
3113
|
/// Test seam: model a window leaving or returning to the glass
|
|
3011
3114
|
/// without a minimize verb (fully covered by another app, revealed
|
|
3012
3115
|
/// again) — the occlusion fact the real hosts' spectrum gating
|
|
@@ -3042,6 +3145,7 @@ pub const NullPlatform = struct {
|
|
|
3042
3145
|
self.window_sources[cursor] = self.window_sources[cursor + 1];
|
|
3043
3146
|
self.window_resizable[cursor] = self.window_resizable[cursor + 1];
|
|
3044
3147
|
self.window_titlebar[cursor] = self.window_titlebar[cursor + 1];
|
|
3148
|
+
self.window_color_scheme[cursor] = self.window_color_scheme[cursor + 1];
|
|
3045
3149
|
self.window_placement[cursor] = self.window_placement[cursor + 1];
|
|
3046
3150
|
self.window_restore_policy[cursor] = self.window_restore_policy[cursor + 1];
|
|
3047
3151
|
self.window_transparent[cursor] = self.window_transparent[cursor + 1];
|
package/src/platform/root.zig
CHANGED
|
@@ -67,6 +67,7 @@ pub const max_menu_item_label_bytes = types.max_menu_item_label_bytes;
|
|
|
67
67
|
pub const max_menu_command_bytes = types.max_menu_command_bytes;
|
|
68
68
|
pub const max_menu_key_bytes = types.max_menu_key_bytes;
|
|
69
69
|
pub const max_shortcuts = types.max_shortcuts;
|
|
70
|
+
pub const max_global_shortcuts = types.max_global_shortcuts;
|
|
70
71
|
pub const max_shortcut_id_bytes = types.max_shortcut_id_bytes;
|
|
71
72
|
pub const max_shortcut_key_bytes = types.max_shortcut_key_bytes;
|
|
72
73
|
pub const max_widget_accessibility_nodes = types.max_widget_accessibility_nodes;
|
|
@@ -80,6 +81,11 @@ pub const max_gpu_surface_font_bytes = types.max_gpu_surface_font_bytes;
|
|
|
80
81
|
pub const ShortcutModifiers = types.ShortcutModifiers;
|
|
81
82
|
pub const Shortcut = types.Shortcut;
|
|
82
83
|
pub const ShortcutEvent = types.ShortcutEvent;
|
|
84
|
+
pub const OwnedShortcut = types.OwnedShortcut;
|
|
85
|
+
pub const sameShortcutCombination = types.sameShortcutCombination;
|
|
86
|
+
pub const GlobalShortcutStatus = types.GlobalShortcutStatus;
|
|
87
|
+
pub const GlobalShortcutEvent = types.GlobalShortcutEvent;
|
|
88
|
+
pub const GlobalShortcutSink = types.GlobalShortcutSink;
|
|
83
89
|
pub const Menu = types.Menu;
|
|
84
90
|
pub const MenuItem = types.MenuItem;
|
|
85
91
|
pub const validateShortcut = types.validateShortcut;
|
|
@@ -141,6 +147,8 @@ pub const NotificationCommandEvent = types.NotificationCommandEvent;
|
|
|
141
147
|
pub const CredentialKey = types.CredentialKey;
|
|
142
148
|
pub const Credential = types.Credential;
|
|
143
149
|
pub const LocalTimeStyle = types.LocalTimeStyle;
|
|
150
|
+
pub const KeyChord = types.KeyChord;
|
|
151
|
+
pub const KeyboardInputAccess = types.KeyboardInputAccess;
|
|
144
152
|
pub const StatusItemId = types.StatusItemId;
|
|
145
153
|
pub const primary_status_item_id = types.primary_status_item_id;
|
|
146
154
|
pub const TrayItemId = types.TrayItemId;
|
|
@@ -214,6 +222,7 @@ pub const WidgetAccessibilityActionEvent = types.WidgetAccessibilityActionEvent;
|
|
|
214
222
|
pub const WidgetContextMenuActionEvent = types.WidgetContextMenuActionEvent;
|
|
215
223
|
pub const ClipboardData = types.ClipboardData;
|
|
216
224
|
pub const ColorScheme = types.ColorScheme;
|
|
225
|
+
pub const WindowColorScheme = types.WindowColorScheme;
|
|
217
226
|
pub const Appearance = types.Appearance;
|
|
218
227
|
pub const Event = types.Event;
|
|
219
228
|
pub const splitDropPaths = types.splitDropPaths;
|
|
@@ -264,4 +273,9 @@ pub fn installHeadlessImageCodec(
|
|
|
264
273
|
test {
|
|
265
274
|
std.testing.refAllDecls(@This());
|
|
266
275
|
_ = @import("null_platform_tests.zig");
|
|
276
|
+
_ = @import("macos/key_codes.zig");
|
|
277
|
+
_ = @import("windows/key_codes.zig");
|
|
278
|
+
_ = @import("keyboard_input.zig");
|
|
279
|
+
_ = @import("macos/keyboard_input.zig");
|
|
280
|
+
_ = @import("windows/keyboard_input.zig");
|
|
267
281
|
}
|
package/src/platform/types.zig
CHANGED
|
@@ -77,8 +77,15 @@ pub const Error = error{
|
|
|
77
77
|
InvalidGpuSurfacePacket,
|
|
78
78
|
InvalidGpuSurfaceImage,
|
|
79
79
|
InvalidGpuSurfaceFont,
|
|
80
|
+
KeyboardInputAccessDenied,
|
|
81
|
+
KeyboardInputBlocked,
|
|
82
|
+
KeyboardInputFailed,
|
|
80
83
|
};
|
|
81
84
|
|
|
85
|
+
pub const keyboard_input = @import("keyboard_input.zig");
|
|
86
|
+
pub const KeyChord = keyboard_input.KeyChord;
|
|
87
|
+
pub const KeyboardInputAccess = keyboard_input.Access;
|
|
88
|
+
|
|
82
89
|
pub const WebEngine = enum {
|
|
83
90
|
system,
|
|
84
91
|
chromium,
|
|
@@ -189,6 +196,10 @@ pub const PlatformFeature = enum {
|
|
|
189
196
|
/// verbs with a teaching and `error.UnsupportedService` — named
|
|
190
197
|
/// unsupported, not half-implemented — and report false here.
|
|
191
198
|
video_playback,
|
|
199
|
+
/// System-wide shortcuts with press and release.
|
|
200
|
+
global_shortcuts,
|
|
201
|
+
/// Posting key chords to whichever app has keyboard focus.
|
|
202
|
+
keyboard_input,
|
|
192
203
|
};
|
|
193
204
|
|
|
194
205
|
pub const WebViewSourceKind = enum {
|
|
@@ -292,6 +303,7 @@ pub const max_menu_key_bytes: usize = 32;
|
|
|
292
303
|
pub const max_shortcuts: usize = 64;
|
|
293
304
|
pub const max_shortcut_id_bytes: usize = 64;
|
|
294
305
|
pub const max_shortcut_key_bytes: usize = 32;
|
|
306
|
+
pub const max_global_shortcuts: usize = 16;
|
|
295
307
|
pub const max_widget_accessibility_nodes: usize = 64;
|
|
296
308
|
pub const max_gpu_surface_packet_json_bytes: usize = 128 * 1024;
|
|
297
309
|
/// Payload bound for the compact binary gpu-surface packet encoding
|
|
@@ -365,6 +377,55 @@ pub const ShortcutEvent = struct {
|
|
|
365
377
|
window_id: WindowId = 1,
|
|
366
378
|
};
|
|
367
379
|
|
|
380
|
+
pub const OwnedShortcut = struct {
|
|
381
|
+
id: [max_shortcut_id_bytes]u8 = undefined,
|
|
382
|
+
id_len: usize = 0,
|
|
383
|
+
key: [max_shortcut_key_bytes]u8 = undefined,
|
|
384
|
+
key_len: usize = 0,
|
|
385
|
+
modifiers: ShortcutModifiers = .{},
|
|
386
|
+
|
|
387
|
+
pub fn init(source: Shortcut) OwnedShortcut {
|
|
388
|
+
var owned: OwnedShortcut = .{ .id_len = source.id.len, .key_len = source.key.len, .modifiers = source.modifiers };
|
|
389
|
+
@memcpy(owned.id[0..source.id.len], source.id);
|
|
390
|
+
@memcpy(owned.key[0..source.key.len], source.key);
|
|
391
|
+
return owned;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
pub fn shortcut(self: *const OwnedShortcut) Shortcut {
|
|
395
|
+
return .{ .id = self.id[0..self.id_len], .key = self.key[0..self.key_len], .modifiers = self.modifiers };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
pub fn matches(self: *const OwnedShortcut, other: Shortcut) bool {
|
|
399
|
+
return std.mem.eql(u8, self.id[0..self.id_len], other.id) and sameShortcutCombination(self.shortcut(), other);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
pub fn sameShortcutCombination(a: Shortcut, b: Shortcut) bool {
|
|
404
|
+
return std.ascii.eqlIgnoreCase(a.key, b.key) and std.meta.eql(a.modifiers, b.modifiers);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
pub const GlobalShortcutPhase = enum(u8) { pressed, released };
|
|
408
|
+
|
|
409
|
+
/// A host's answer for one global shortcut binding.
|
|
410
|
+
pub const GlobalShortcutStatus = enum(u8) { registered, conflict, rejected };
|
|
411
|
+
|
|
412
|
+
pub const GlobalShortcutEvent = struct {
|
|
413
|
+
shortcut: Shortcut,
|
|
414
|
+
phase: GlobalShortcutPhase,
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
/// Where a host delivers presses and releases; safe to push from any thread.
|
|
418
|
+
pub const GlobalShortcutSink = struct {
|
|
419
|
+
context: ?*anyopaque = null,
|
|
420
|
+
generation: u64 = 0,
|
|
421
|
+
push_fn: ?*const fn (context: ?*anyopaque, generation: u64, event: GlobalShortcutEvent) void = null,
|
|
422
|
+
|
|
423
|
+
pub fn push(self: GlobalShortcutSink, event: GlobalShortcutEvent) void {
|
|
424
|
+
const push_fn = self.push_fn orelse return;
|
|
425
|
+
push_fn(self.context, self.generation, event);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
368
429
|
pub const Menu = struct {
|
|
369
430
|
title: []const u8,
|
|
370
431
|
items: []const MenuItem = &.{},
|
|
@@ -1292,6 +1353,9 @@ pub const AppInfo = struct {
|
|
|
1292
1353
|
/// default menus: web items like Reload only exist when a webview
|
|
1293
1354
|
/// can answer them.
|
|
1294
1355
|
has_web_content: bool = false,
|
|
1356
|
+
/// Explicit macOS system-WebView debugging capability. Direct embedding
|
|
1357
|
+
/// defaults to disabled; app runners resolve their build-time setting.
|
|
1358
|
+
webview_inspection: bool = false,
|
|
1295
1359
|
/// Whether the manifest declares the "tray" capability (a status
|
|
1296
1360
|
/// item). Close policy `.hide` leans on it where the OS has no
|
|
1297
1361
|
/// built-in re-show affordance: hiding a window on windows removes
|
|
@@ -2570,6 +2634,14 @@ pub const ColorScheme = enum {
|
|
|
2570
2634
|
dark,
|
|
2571
2635
|
};
|
|
2572
2636
|
|
|
2637
|
+
/// Requested native window appearance. `system` removes the window's
|
|
2638
|
+
/// override without changing the application's observed OS appearance.
|
|
2639
|
+
pub const WindowColorScheme = enum(u8) {
|
|
2640
|
+
system = 0,
|
|
2641
|
+
light = 1,
|
|
2642
|
+
dark = 2,
|
|
2643
|
+
};
|
|
2644
|
+
|
|
2573
2645
|
pub const Appearance = struct {
|
|
2574
2646
|
color_scheme: ColorScheme = .light,
|
|
2575
2647
|
reduce_motion: bool = false,
|
|
@@ -2755,6 +2827,9 @@ pub const PlatformServices = struct {
|
|
|
2755
2827
|
/// windows and platforms without the concept report the zero
|
|
2756
2828
|
/// `WindowChrome`; the null default is the same honest zero.
|
|
2757
2829
|
window_chrome_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) WindowChrome = null,
|
|
2830
|
+
/// Apply an app-requested scheme to native window chrome and child
|
|
2831
|
+
/// controls. Hosts without window appearance overrides leave this null.
|
|
2832
|
+
set_window_color_scheme_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, scheme: WindowColorScheme) anyerror!void = null,
|
|
2758
2833
|
/// Replace the platform's mirror of a canvas view's window-drag
|
|
2759
2834
|
/// regions (see `WindowDragRegion`). Called by the runtime after
|
|
2760
2835
|
/// every layout install whose regions changed; an empty slice
|
|
@@ -2792,6 +2867,9 @@ pub const PlatformServices = struct {
|
|
|
2792
2867
|
format_local_time_fn: ?*const fn (context: ?*anyopaque, timestamp_ms: i64, style: LocalTimeStyle, buffer: []u8) anyerror![]const u8 = null,
|
|
2793
2868
|
open_external_url_fn: ?*const fn (context: ?*anyopaque, url: []const u8) anyerror!void = null,
|
|
2794
2869
|
reveal_path_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
|
|
2870
|
+
/// Keyboard input for the focused app; `prompt` asks the OS to show its grant prompt.
|
|
2871
|
+
send_key_chord_fn: ?*const fn (context: ?*anyopaque, chord: KeyChord) anyerror!void = null,
|
|
2872
|
+
keyboard_input_access_fn: ?*const fn (context: ?*anyopaque, prompt: bool) anyerror!KeyboardInputAccess = null,
|
|
2795
2873
|
add_recent_document_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
|
|
2796
2874
|
clear_recent_documents_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
|
|
2797
2875
|
check_for_updates_fn: ?*const fn (context: ?*anyopaque, user_initiated: bool) anyerror!void = null,
|
|
@@ -2804,6 +2882,8 @@ pub const PlatformServices = struct {
|
|
|
2804
2882
|
configure_security_policy_fn: ?*const fn (context: ?*anyopaque, policy: security.Policy) anyerror!void = null,
|
|
2805
2883
|
configure_menus_fn: ?*const fn (context: ?*anyopaque, menus: []const Menu) anyerror!void = null,
|
|
2806
2884
|
configure_shortcuts_fn: ?*const fn (context: ?*anyopaque, shortcuts: []const Shortcut) anyerror!void = null,
|
|
2885
|
+
/// Replace the whole system-wide shortcut set.
|
|
2886
|
+
configure_global_shortcuts_fn: ?*const fn (context: ?*anyopaque, shortcuts: []const Shortcut, sink: GlobalShortcutSink, statuses: []GlobalShortcutStatus) anyerror!void = null,
|
|
2807
2887
|
emit_window_event_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, name: []const u8, detail_json: []const u8) anyerror!void = null,
|
|
2808
2888
|
request_gpu_surface_frame_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void = null,
|
|
2809
2889
|
/// Input was dispatched to the surface: hosts that throttle occluded
|
|
@@ -3214,6 +3294,11 @@ pub const PlatformServices = struct {
|
|
|
3214
3294
|
return error.UnsupportedViewKind;
|
|
3215
3295
|
}
|
|
3216
3296
|
|
|
3297
|
+
pub fn setWindowColorScheme(self: PlatformServices, window_id: WindowId, scheme: WindowColorScheme) anyerror!void {
|
|
3298
|
+
const set_fn = self.set_window_color_scheme_fn orelse return;
|
|
3299
|
+
return set_fn(self.context, window_id, scheme);
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3217
3302
|
pub fn updateView(self: PlatformServices, window_id: WindowId, label: []const u8, patch: ViewPatch) anyerror!void {
|
|
3218
3303
|
const update_fn = self.update_view_fn orelse return error.UnsupportedViewKind;
|
|
3219
3304
|
return update_fn(self.context, window_id, label, patch);
|
|
@@ -3356,6 +3441,16 @@ pub const PlatformServices = struct {
|
|
|
3356
3441
|
return open_fn(self.context, url);
|
|
3357
3442
|
}
|
|
3358
3443
|
|
|
3444
|
+
pub fn sendKeyChord(self: PlatformServices, chord: KeyChord) anyerror!void {
|
|
3445
|
+
const send_fn = self.send_key_chord_fn orelse return error.UnsupportedService;
|
|
3446
|
+
return send_fn(self.context, chord);
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
pub fn keyboardInputAccess(self: PlatformServices, prompt: bool) anyerror!KeyboardInputAccess {
|
|
3450
|
+
const access_fn = self.keyboard_input_access_fn orelse return error.UnsupportedService;
|
|
3451
|
+
return access_fn(self.context, prompt);
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3359
3454
|
pub fn revealPath(self: PlatformServices, path: []const u8) anyerror!void {
|
|
3360
3455
|
const reveal_fn = self.reveal_path_fn orelse return error.UnsupportedService;
|
|
3361
3456
|
return reveal_fn(self.context, path);
|
|
@@ -3456,6 +3551,11 @@ pub const PlatformServices = struct {
|
|
|
3456
3551
|
return configure_fn(self.context, shortcuts);
|
|
3457
3552
|
}
|
|
3458
3553
|
|
|
3554
|
+
pub fn configureGlobalShortcuts(self: PlatformServices, shortcuts: []const Shortcut, sink: GlobalShortcutSink, statuses: []GlobalShortcutStatus) anyerror!void {
|
|
3555
|
+
const configure_fn = self.configure_global_shortcuts_fn orelse return error.UnsupportedService;
|
|
3556
|
+
return configure_fn(self.context, shortcuts, sink, statuses);
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3459
3559
|
pub fn emitWindowEvent(self: PlatformServices, window_id: WindowId, name: []const u8, detail_json: []const u8) anyerror!void {
|
|
3460
3560
|
const emit_fn = self.emit_window_event_fn orelse return error.UnsupportedService;
|
|
3461
3561
|
return emit_fn(self.context, window_id, name, detail_json);
|
|
@@ -3806,6 +3906,8 @@ fn defaultSupportsFeature(services: PlatformServices, feature: PlatformFeature)
|
|
|
3806
3906
|
// generic floor still probes the verb for embedders that wire a
|
|
3807
3907
|
// real one.
|
|
3808
3908
|
.video_playback => services.video_load_fn != null,
|
|
3909
|
+
.global_shortcuts => services.configure_global_shortcuts_fn != null,
|
|
3910
|
+
.keyboard_input => services.send_key_chord_fn != null and services.keyboard_input_access_fn != null,
|
|
3809
3911
|
};
|
|
3810
3912
|
}
|
|
3811
3913
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
//! System-wide shortcuts through `RegisterHotKey` on a message-only window.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const builtin = @import("builtin");
|
|
4
|
+
const types = @import("../types.zig");
|
|
5
|
+
const key_codes = @import("key_codes.zig");
|
|
6
|
+
|
|
7
|
+
const HWND = ?*anyopaque;
|
|
8
|
+
const WindowProc = *const fn (HWND, c_uint, usize, isize) callconv(.winapi) isize;
|
|
9
|
+
const WindowClass = extern struct {
|
|
10
|
+
size: c_uint = @sizeOf(WindowClass),
|
|
11
|
+
style: c_uint = 0,
|
|
12
|
+
proc: WindowProc,
|
|
13
|
+
class_extra: c_int = 0,
|
|
14
|
+
window_extra: c_int = 0,
|
|
15
|
+
instance: ?*anyopaque,
|
|
16
|
+
icon: ?*anyopaque = null,
|
|
17
|
+
cursor: ?*anyopaque = null,
|
|
18
|
+
background: ?*anyopaque = null,
|
|
19
|
+
menu_name: ?[*:0]const u16 = null,
|
|
20
|
+
class_name: [*:0]const u16,
|
|
21
|
+
small_icon: ?*anyopaque = null,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const wm_hotkey: c_uint = 0x0312;
|
|
25
|
+
const wm_timer: c_uint = 0x0113;
|
|
26
|
+
const user_data: c_int = -21;
|
|
27
|
+
const poll_timer: usize = 1;
|
|
28
|
+
const class_name = std.unicode.utf8ToUtf16LeStringLiteral("NativeSdkGlobalShortcuts");
|
|
29
|
+
|
|
30
|
+
extern "user32" fn RegisterClassExW(class: *const WindowClass) callconv(.winapi) u16;
|
|
31
|
+
extern "user32" fn CreateWindowExW(ex_style: u32, class: [*:0]const u16, name: ?[*:0]const u16, style: u32, x: c_int, y: c_int, width: c_int, height: c_int, parent: HWND, menu: ?*anyopaque, instance: ?*anyopaque, param: ?*anyopaque) callconv(.winapi) HWND;
|
|
32
|
+
extern "user32" fn DestroyWindow(hwnd: HWND) callconv(.winapi) c_int;
|
|
33
|
+
extern "user32" fn DefWindowProcW(hwnd: HWND, msg: c_uint, wparam: usize, lparam: isize) callconv(.winapi) isize;
|
|
34
|
+
extern "user32" fn SetWindowLongPtrW(hwnd: HWND, index: c_int, value: isize) callconv(.winapi) isize;
|
|
35
|
+
extern "user32" fn GetWindowLongPtrW(hwnd: HWND, index: c_int) callconv(.winapi) isize;
|
|
36
|
+
extern "user32" fn RegisterHotKey(hwnd: HWND, id: c_int, modifiers: c_uint, vk: c_uint) callconv(.winapi) c_int;
|
|
37
|
+
extern "user32" fn UnregisterHotKey(hwnd: HWND, id: c_int) callconv(.winapi) c_int;
|
|
38
|
+
extern "user32" fn SetTimer(hwnd: HWND, id: usize, elapse_ms: c_uint, callback: ?*const anyopaque) callconv(.winapi) usize;
|
|
39
|
+
extern "user32" fn KillTimer(hwnd: HWND, id: usize) callconv(.winapi) c_int;
|
|
40
|
+
extern "user32" fn GetAsyncKeyState(vk: c_int) callconv(.winapi) i16;
|
|
41
|
+
extern "kernel32" fn GetModuleHandleW(name: ?[*:0]const u16) callconv(.winapi) ?*anyopaque;
|
|
42
|
+
extern "kernel32" fn GetLastError() callconv(.winapi) u32;
|
|
43
|
+
|
|
44
|
+
pub fn available() bool {
|
|
45
|
+
return builtin.os.tag == .windows and !builtin.is_test;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const Entry = struct {
|
|
49
|
+
binding: types.OwnedShortcut,
|
|
50
|
+
id: c_int = 0,
|
|
51
|
+
vk: c_uint = 0,
|
|
52
|
+
registered: bool = false,
|
|
53
|
+
pressed: bool = false,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
pub const Registry = struct {
|
|
57
|
+
entries: [types.max_global_shortcuts]Entry = undefined,
|
|
58
|
+
count: usize = 0,
|
|
59
|
+
sink: types.GlobalShortcutSink = .{},
|
|
60
|
+
hwnd: HWND = null,
|
|
61
|
+
polling: bool = false,
|
|
62
|
+
next_id: c_int = 0,
|
|
63
|
+
|
|
64
|
+
pub fn configure(self: *Registry, shortcuts: []const types.Shortcut, sink: types.GlobalShortcutSink, statuses: []types.GlobalShortcutStatus) !void {
|
|
65
|
+
if (comptime !available()) return error.UnsupportedService;
|
|
66
|
+
self.sink = sink;
|
|
67
|
+
if (self.hwnd == null) {
|
|
68
|
+
const instance = GetModuleHandleW(null);
|
|
69
|
+
_ = RegisterClassExW(&.{ .proc = windowProc, .instance = instance, .class_name = class_name });
|
|
70
|
+
self.hwnd = CreateWindowExW(0, class_name, null, 0, 0, 0, 0, 0, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))), null, instance, null) orelse return error.UnsupportedService;
|
|
71
|
+
_ = SetWindowLongPtrW(self.hwnd, user_data, @bitCast(@intFromPtr(self)));
|
|
72
|
+
}
|
|
73
|
+
for (self.entries[0..self.count]) |*entry| {
|
|
74
|
+
for (shortcuts) |shortcut| {
|
|
75
|
+
if (entry.binding.matches(shortcut)) break;
|
|
76
|
+
} else self.retire(entry);
|
|
77
|
+
}
|
|
78
|
+
var next: [types.max_global_shortcuts]Entry = undefined;
|
|
79
|
+
var count: usize = 0;
|
|
80
|
+
for (shortcuts, statuses) |shortcut, *status| {
|
|
81
|
+
status.* = .registered;
|
|
82
|
+
for (self.entries[0..self.count]) |*entry| {
|
|
83
|
+
if (entry.registered and entry.binding.matches(shortcut)) {
|
|
84
|
+
next[count] = entry.*;
|
|
85
|
+
entry.registered = false;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
self.next_id = @mod(self.next_id, 0xBFFF) + 1;
|
|
90
|
+
const vk = key_codes.virtualKey(shortcut.key) orelse {
|
|
91
|
+
status.* = .rejected;
|
|
92
|
+
continue;
|
|
93
|
+
};
|
|
94
|
+
next[count] = .{ .binding = .init(shortcut), .id = self.next_id, .vk = vk, .registered = true };
|
|
95
|
+
if (RegisterHotKey(self.hwnd, self.next_id, modifierMask(shortcut.modifiers), vk) == 0) {
|
|
96
|
+
status.* = if (GetLastError() == 1409) .conflict else .rejected;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
count += 1;
|
|
101
|
+
}
|
|
102
|
+
@memcpy(self.entries[0..count], next[0..count]);
|
|
103
|
+
self.count = count;
|
|
104
|
+
self.updatePolling();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pub fn deinit(self: *Registry) void {
|
|
108
|
+
if (comptime !available()) return;
|
|
109
|
+
for (self.entries[0..self.count]) |*entry| self.retire(entry);
|
|
110
|
+
self.count = 0;
|
|
111
|
+
self.updatePolling();
|
|
112
|
+
if (self.hwnd != null) _ = DestroyWindow(self.hwnd);
|
|
113
|
+
self.hwnd = null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fn retire(self: *Registry, entry: *Entry) void {
|
|
117
|
+
if (entry.pressed) self.sink.push(.{ .shortcut = entry.binding.shortcut(), .phase = .released });
|
|
118
|
+
entry.pressed = false;
|
|
119
|
+
if (entry.registered) _ = UnregisterHotKey(self.hwnd, entry.id);
|
|
120
|
+
entry.registered = false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fn update(self: *Registry, hot_key: ?c_int) void {
|
|
124
|
+
for (self.entries[0..self.count]) |*entry| {
|
|
125
|
+
const repeated = if (hot_key) |id| entry.id == id and entry.pressed else false;
|
|
126
|
+
if (repeated) self.sink.push(.{ .shortcut = entry.binding.shortcut(), .phase = .released });
|
|
127
|
+
const pressing = if (hot_key) |id| entry.id == id or entry.pressed else entry.pressed and GetAsyncKeyState(@intCast(entry.vk)) < 0;
|
|
128
|
+
if (pressing == entry.pressed and !repeated) continue;
|
|
129
|
+
entry.pressed = pressing;
|
|
130
|
+
self.sink.push(.{ .shortcut = entry.binding.shortcut(), .phase = if (pressing) .pressed else .released });
|
|
131
|
+
}
|
|
132
|
+
self.updatePolling();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fn updatePolling(self: *Registry) void {
|
|
136
|
+
var held = false;
|
|
137
|
+
for (self.entries[0..self.count]) |entry| held = held or entry.pressed;
|
|
138
|
+
if (held and !self.polling) self.polling = SetTimer(self.hwnd, poll_timer, 10, null) != 0;
|
|
139
|
+
if (!held and self.polling) {
|
|
140
|
+
_ = KillTimer(self.hwnd, poll_timer);
|
|
141
|
+
self.polling = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
fn windowProc(hwnd: HWND, msg: c_uint, wparam: usize, lparam: isize) callconv(.winapi) isize {
|
|
147
|
+
const raw = GetWindowLongPtrW(hwnd, user_data);
|
|
148
|
+
if (raw == 0 or (msg != wm_hotkey and !(msg == wm_timer and wparam == poll_timer))) return DefWindowProcW(hwnd, msg, wparam, lparam);
|
|
149
|
+
const registry: *Registry = @ptrFromInt(@as(usize, @bitCast(raw)));
|
|
150
|
+
registry.update(if (msg == wm_hotkey) @intCast(wparam & 0xFFFF) else null);
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fn modifierMask(modifiers: types.ShortcutModifiers) c_uint {
|
|
155
|
+
return 0x4000 | @as(c_uint, if (modifiers.option) 1 else 0) | @as(c_uint, if (modifiers.primary or modifiers.control) 2 else 0) |
|
|
156
|
+
@as(c_uint, if (modifiers.shift) 4 else 0) | @as(c_uint, if (modifiers.command) 8 else 0);
|
|
157
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//! Maps shortcut key names to Windows virtual-key codes.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const builtin = @import("builtin");
|
|
4
|
+
const types = @import("../types.zig");
|
|
5
|
+
|
|
6
|
+
const punctuation = "=-,./;'[]\\`";
|
|
7
|
+
const punctuation_codes = [_]u16{ 0xBB, 0xBD, 0xBC, 0xBE, 0xBF, 0xBA, 0xDE, 0xDB, 0xDD, 0xDC, 0xC0 };
|
|
8
|
+
|
|
9
|
+
const named = [_]struct { []const u8, u16 }{
|
|
10
|
+
.{ "escape", 0x1B }, .{ "enter", 0x0D }, .{ "tab", 0x09 }, .{ "space", 0x20 }, .{ "backspace", 0x08 },
|
|
11
|
+
.{ "arrowleft", 0x25 }, .{ "arrowup", 0x26 }, .{ "arrowright", 0x27 }, .{ "arrowdown", 0x28 }, .{ "delete", 0x2E },
|
|
12
|
+
.{ "home", 0x24 }, .{ "end", 0x23 }, .{ "pageup", 0x21 }, .{ "pagedown", 0x22 }, .{ "insert", 0x2D },
|
|
13
|
+
.{ "f1", 0x70 }, .{ "f2", 0x71 }, .{ "f3", 0x72 }, .{ "f4", 0x73 }, .{ "f5", 0x74 },
|
|
14
|
+
.{ "f6", 0x75 }, .{ "f7", 0x76 }, .{ "f8", 0x77 }, .{ "f9", 0x78 }, .{ "f10", 0x79 },
|
|
15
|
+
.{ "f11", 0x7A }, .{ "f12", 0x7B },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
extern "user32" fn VkKeyScanW(ch: u16) callconv(.winapi) i16;
|
|
19
|
+
|
|
20
|
+
/// Returns the Windows virtual-key code for a shortcut key name; punctuation resolves through the active layout on Windows.
|
|
21
|
+
pub fn virtualKey(key: []const u8) ?u16 {
|
|
22
|
+
if (comptime builtin.os.tag == .windows) {
|
|
23
|
+
if (key.len == 1 and std.mem.indexOfScalar(u8, punctuation, key[0]) != null) {
|
|
24
|
+
const scan = VkKeyScanW(key[0]);
|
|
25
|
+
if (scan != -1 and scan >> 8 == 0) return @intCast(scan & 0xFF);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return tableKey(key);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fn tableKey(key: []const u8) ?u16 {
|
|
32
|
+
if (key.len == 1) {
|
|
33
|
+
const ch = std.ascii.toUpper(key[0]);
|
|
34
|
+
if (std.ascii.isAlphanumeric(ch)) return ch;
|
|
35
|
+
return punctuation_codes[std.mem.indexOfScalar(u8, punctuation, ch) orelse return null];
|
|
36
|
+
}
|
|
37
|
+
for (named) |entry| {
|
|
38
|
+
if (std.ascii.eqlIgnoreCase(key, entry[0])) return entry[1];
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test "every valid shortcut key has a distinct virtual key" {
|
|
44
|
+
var seen = [_]bool{false} ** 256;
|
|
45
|
+
var count: usize = 0;
|
|
46
|
+
var ch: u8 = 0;
|
|
47
|
+
while (true) : (ch += 1) {
|
|
48
|
+
if (types.isValidShortcutKey(&.{ch}) and !std.ascii.isUpper(ch)) {
|
|
49
|
+
const code = tableKey(&.{ch}).?;
|
|
50
|
+
try std.testing.expect(!seen[code]);
|
|
51
|
+
seen[code] = true;
|
|
52
|
+
count += 1;
|
|
53
|
+
}
|
|
54
|
+
if (ch == 255) break;
|
|
55
|
+
}
|
|
56
|
+
for (named) |entry| {
|
|
57
|
+
try std.testing.expect(types.isValidShortcutKey(entry[0]));
|
|
58
|
+
try std.testing.expect(!seen[tableKey(entry[0]).?]);
|
|
59
|
+
seen[entry[1]] = true;
|
|
60
|
+
count += 1;
|
|
61
|
+
}
|
|
62
|
+
try std.testing.expectEqual(@as(usize, 26 + 10 + 11 + 27), count);
|
|
63
|
+
}
|