@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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
//! Owned context-menu plans. All identities/tokens remain complete integer
|
|
2
|
+
//! words. Native owns labels, widgets, callbacks, buffers and OS services.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const canvas = @import("canvas");
|
|
5
|
+
const platform = @import("../platform/root.zig");
|
|
6
|
+
const limits = @import("canvas_limits.zig");
|
|
7
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
8
|
+
pub const Kind = enum(u32) { app = 1, edit_text, terminal, static_copy };
|
|
9
|
+
pub const Action = enum(u32) { none, app, cut, copy, paste, select_all, terminal_copy, terminal_paste, static_copy };
|
|
10
|
+
fn header(comptime n: usize, mode: u8) [n]u8 {
|
|
11
|
+
var bytes: [n]u8 = @splat(0);
|
|
12
|
+
bytes[0..2].* = .{ 98, mode };
|
|
13
|
+
return bytes;
|
|
14
|
+
}
|
|
15
|
+
fn put(bytes: []u8, at: usize, value: u32) void {
|
|
16
|
+
std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
|
|
17
|
+
}
|
|
18
|
+
fn wide(bytes: []u8, at: usize, value: u64) void {
|
|
19
|
+
std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
|
|
20
|
+
}
|
|
21
|
+
fn scalar(policy: Policy, request: []const u8, maximum: u32) u32 {
|
|
22
|
+
var out: [4]u8 = undefined;
|
|
23
|
+
if (policy(request, &out) != out.len) @panic("invalid context menu scalar length");
|
|
24
|
+
const value = std.mem.readInt(u32, &out, .little);
|
|
25
|
+
if (value > maximum) @panic("invalid context menu scalar");
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
pub fn route(policy: Policy, nodes: []const canvas.WidgetLayoutNode, entries: []const canvas.WidgetEventRouteEntry) ?usize {
|
|
29
|
+
if (nodes.len > limits.max_canvas_widget_nodes_per_view or entries.len > limits.max_canvas_widget_nodes_per_view) @panic("context menu route capacity");
|
|
30
|
+
var request = header(16 + limits.max_canvas_widget_nodes_per_view * 24, 0);
|
|
31
|
+
put(&request, 4, @intCast(nodes.len));
|
|
32
|
+
put(&request, 8, @intCast(entries.len));
|
|
33
|
+
for (nodes, 0..) |node, i| {
|
|
34
|
+
const at = 16 + i * 16;
|
|
35
|
+
wide(&request, at, node.depth);
|
|
36
|
+
put(&request, at + 8, @intCast(node.widget.context_menu.len));
|
|
37
|
+
put(&request, at + 12, @intFromBool(node.widget.state.disabled));
|
|
38
|
+
}
|
|
39
|
+
for (entries, 0..) |entry, i| wide(&request, 16 + nodes.len * 16 + i * 8, entry.node_index);
|
|
40
|
+
const slot = scalar(policy, request[0 .. 16 + nodes.len * 16 + entries.len * 8], std.math.maxInt(u32));
|
|
41
|
+
if (slot == std.math.maxInt(u32)) return null;
|
|
42
|
+
if (slot >= nodes.len or nodes[slot].widget.context_menu.len == 0 or nodes[slot].widget.state.disabled) @panic("invalid context menu route capability");
|
|
43
|
+
return slot;
|
|
44
|
+
}
|
|
45
|
+
pub const Presentation = struct {
|
|
46
|
+
kind: enum(u8) { none, hold, edit_text, terminal, static_copy },
|
|
47
|
+
count: usize,
|
|
48
|
+
items: [5]platform.ContextMenuItem = undefined,
|
|
49
|
+
};
|
|
50
|
+
pub const Facts = struct {
|
|
51
|
+
flags: u32,
|
|
52
|
+
target: u64 = 0,
|
|
53
|
+
selected: u64 = 0,
|
|
54
|
+
selected_group: u64 = 0,
|
|
55
|
+
target_group: u64 = 0,
|
|
56
|
+
};
|
|
57
|
+
pub fn presentation(policy: Policy, facts: Facts) Presentation {
|
|
58
|
+
var request = header(56, 1);
|
|
59
|
+
put(&request, 4, facts.flags);
|
|
60
|
+
for ([_]u64{ facts.target, facts.selected, facts.selected_group, facts.target_group }, 0..) |v, i| wide(&request, 16 + i * 8, v);
|
|
61
|
+
var out: [28]u8 = undefined;
|
|
62
|
+
const length = policy(&request, &out);
|
|
63
|
+
if (length < 8 or length > out.len or out[0] > 4 or out[1] > 5 or length != 8 + @as(usize, out[1]) * 4 or
|
|
64
|
+
!std.mem.allEqual(u8, out[2..8], 0)) @panic("invalid context menu presentation");
|
|
65
|
+
const labels = [_][]const u8{ "", "Cut", "Copy", "Paste", "Select All" };
|
|
66
|
+
var result = Presentation{ .kind = @enumFromInt(out[0]), .count = out[1] };
|
|
67
|
+
for (0..result.count) |i| {
|
|
68
|
+
const at = 8 + i * 4;
|
|
69
|
+
if (out[at] > 4 or out[at + 1] > 4 or out[at + 2] > 1 or out[at + 3] > 1) @panic("invalid context menu item capability");
|
|
70
|
+
result.items[i] = .{ .id = out[at], .label = labels[out[at + 1]], .enabled = out[at + 2] != 0, .separator = out[at + 3] != 0 };
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
pub fn nextToken(policy: Policy, token: u64) u64 {
|
|
75
|
+
var request = header(16, 2);
|
|
76
|
+
wide(&request, 8, token);
|
|
77
|
+
var out: [8]u8 = undefined;
|
|
78
|
+
if (policy(&request, &out) != out.len) @panic("invalid context menu token length");
|
|
79
|
+
const value = std.mem.readInt(u64, &out, .little);
|
|
80
|
+
if (value == 0) @panic("invalid context menu token");
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
pub fn notice(policy: Policy, kind: ?Kind) bool {
|
|
84
|
+
var request = header(16, 3);
|
|
85
|
+
put(&request, 4, if (kind) |k| @intFromEnum(k) else 0);
|
|
86
|
+
return scalar(policy, &request, 1) != 0;
|
|
87
|
+
}
|
|
88
|
+
pub const Continuation = enum(u32) { superseded, view_closed, shown };
|
|
89
|
+
pub fn continuation(policy: Policy, token: u64, current: ?u64, view_open: bool) Continuation {
|
|
90
|
+
var request = header(32, 4);
|
|
91
|
+
put(&request, 4, @as(u32, @intFromBool(current != null)) | (@as(u32, @intFromBool(view_open)) << 1));
|
|
92
|
+
wide(&request, 8, token);
|
|
93
|
+
wide(&request, 16, current orelse 0);
|
|
94
|
+
return @enumFromInt(scalar(policy, &request, 2));
|
|
95
|
+
}
|
|
96
|
+
pub const Admission = enum(u32) { ignore, dismiss, clear, lookup };
|
|
97
|
+
pub fn admission(policy: Policy, kind: ?Kind, window: u64, token: u64, event: platform.ContextMenuActionEvent) Admission {
|
|
98
|
+
var request = header(48, 5);
|
|
99
|
+
put(&request, 4, if (kind) |k| @intFromEnum(k) else 0);
|
|
100
|
+
wide(&request, 8, window);
|
|
101
|
+
wide(&request, 16, event.window_id);
|
|
102
|
+
wide(&request, 24, token);
|
|
103
|
+
wide(&request, 32, event.token);
|
|
104
|
+
put(&request, 40, event.item_id);
|
|
105
|
+
return @enumFromInt(scalar(policy, &request, 3));
|
|
106
|
+
}
|
|
107
|
+
pub fn action(policy: Policy, kind: Kind, item: u32) Action {
|
|
108
|
+
var request = header(16, 6);
|
|
109
|
+
put(&request, 4, @intFromEnum(kind));
|
|
110
|
+
put(&request, 8, item);
|
|
111
|
+
return @enumFromInt(scalar(policy, &request, 8));
|
|
112
|
+
}
|
package/src/runtime/core.zig
CHANGED
|
@@ -283,6 +283,7 @@ pub const Runtime = struct {
|
|
|
283
283
|
snapshot_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
284
284
|
host_flow_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
285
285
|
command_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
286
|
+
context_menu_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
286
287
|
text_cache_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
287
288
|
render_cache_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
288
289
|
render_plan_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
@@ -731,6 +732,7 @@ pub const Runtime = struct {
|
|
|
731
732
|
pub const focusWindow = WindowViewMethods.focusWindow;
|
|
732
733
|
pub const closeWindow = WindowViewMethods.closeWindow;
|
|
733
734
|
pub const restoreWindowCapabilityResult = WindowViewMethods.restoreWindowCapabilityResult;
|
|
735
|
+
pub const restoreWindowShow = WindowViewMethods.restoreWindowShow;
|
|
734
736
|
pub const minimizeWindow = WindowViewMethods.minimizeWindow;
|
|
735
737
|
pub const hideWindow = WindowViewMethods.hideWindow;
|
|
736
738
|
pub const showWindow = WindowViewMethods.showWindow;
|
|
@@ -832,6 +834,8 @@ pub const Runtime = struct {
|
|
|
832
834
|
pub const getCredential = SystemServiceMethods.getCredential;
|
|
833
835
|
pub const deleteCredential = SystemServiceMethods.deleteCredential;
|
|
834
836
|
pub const formatLocalTime = SystemServiceMethods.formatLocalTime;
|
|
837
|
+
pub const sendKeyChord = SystemServiceMethods.sendKeyChord;
|
|
838
|
+
pub const keyboardInputAccess = SystemServiceMethods.keyboardInputAccess;
|
|
835
839
|
pub const createTray = SystemServiceMethods.createTray;
|
|
836
840
|
pub const createStatusItem = SystemServiceMethods.createStatusItem;
|
|
837
841
|
pub const updateStatusItemShell = SystemServiceMethods.updateStatusItemShell;
|
|
@@ -1334,6 +1338,16 @@ const testingBuiltinBridgeErrorCode = builtinBridgeErrorCode;
|
|
|
1334
1338
|
const testingBuiltinBridgeErrorMessage = builtinBridgeErrorMessage;
|
|
1335
1339
|
|
|
1336
1340
|
pub const testing = struct {
|
|
1341
|
+
pub const scroll_mutation_methods = @import("view_widget_scroll.zig");
|
|
1342
|
+
pub const scroll_mutation_policy = @import("scroll_mutation_policy.zig");
|
|
1343
|
+
pub const virtual_window_policy = @import("virtual_window_policy.zig");
|
|
1344
|
+
pub const context_menu_policy = @import("context_menu_policy.zig");
|
|
1345
|
+
pub const web_pane_test_cases = @import("web_pane_test_cases.zig");
|
|
1346
|
+
pub const web_pane_policy = @import("web_pane_policy.zig");
|
|
1347
|
+
pub const context_menu_test_cases = @import("canvas_widget_context_menu_test_cases.zig");
|
|
1348
|
+
pub const widget_retention_policy = @import("widget_retention_policy.zig");
|
|
1349
|
+
pub const widget_retention_runtime = runtime_canvas_widget_runtime;
|
|
1350
|
+
pub const widget_retention_view = runtime_view.RuntimeView;
|
|
1337
1351
|
pub const markup_development_policy = @import("markup_development_policy.zig");
|
|
1338
1352
|
pub const markup_provenance = @import("ui_app_provenance.zig");
|
|
1339
1353
|
pub const markup_provenance_reference = @import("ui_app_provenance_reference.zig");
|
package/src/runtime/effects.zig
CHANGED
|
@@ -77,8 +77,10 @@ const persist_store = @import("persist_store.zig");
|
|
|
77
77
|
const record_store = @import("record_store.zig");
|
|
78
78
|
const relational_store = @import("relational_store.zig");
|
|
79
79
|
const credentials_store = @import("credentials_store.zig");
|
|
80
|
+
const keyboard_input = @import("keyboard_input.zig");
|
|
80
81
|
const file_access = @import("file_access.zig");
|
|
81
82
|
const pty_transport = @import("pty.zig");
|
|
83
|
+
const global_shortcuts_mod = @import("global_shortcuts.zig");
|
|
82
84
|
|
|
83
85
|
/// Maximum in-flight effects (spawn slots / worker threads).
|
|
84
86
|
pub const max_effects: usize = 16;
|
|
@@ -373,6 +375,9 @@ pub const WindowActionBinding = struct {
|
|
|
373
375
|
minimize_fn: *const fn (context: *anyopaque, window_label: []const u8) bool,
|
|
374
376
|
hide_fn: *const fn (context: *anyopaque, window_label: []const u8) bool,
|
|
375
377
|
show_fn: *const fn (context: *anyopaque, window_label: []const u8) bool,
|
|
378
|
+
/// Replay the synchronous show bookkeeping without an OS call. The
|
|
379
|
+
/// later native frame event must not delay keyboard-focus loss.
|
|
380
|
+
replay_show_fn: ?*const fn (context: *anyopaque, window_label: []const u8) void = null,
|
|
376
381
|
dock_presence_fn: *const fn (context: *anyopaque, visible: bool) bool,
|
|
377
382
|
quit_fn: *const fn (context: *anyopaque) bool,
|
|
378
383
|
};
|
|
@@ -390,6 +395,7 @@ pub const SystemServiceBinding = struct {
|
|
|
390
395
|
/// Restore only runtime window bookkeeping from a journaled successful
|
|
391
396
|
/// capability, without invoking native window focus or close services.
|
|
392
397
|
replay_window_result_fn: ?*const fn (context: *anyopaque, label: []const u8, closed: bool) void = null,
|
|
398
|
+
keyboard_input: ?keyboard_input.Binding = null,
|
|
393
399
|
};
|
|
394
400
|
|
|
395
401
|
/// Type-erased handle to the embedding host's named-command services,
|
|
@@ -1284,6 +1290,9 @@ pub const EffectAudioCaptureEvent = struct {
|
|
|
1284
1290
|
const audio_capture_packet_header_bytes: usize = 24;
|
|
1285
1291
|
const audio_capture_packet_magic = "AC01";
|
|
1286
1292
|
|
|
1293
|
+
pub const EffectGlobalShortcutEventKind = global_shortcuts_mod.EffectGlobalShortcutEventKind;
|
|
1294
|
+
pub const EffectGlobalShortcutEvent = global_shortcuts_mod.EffectGlobalShortcutEvent;
|
|
1295
|
+
|
|
1287
1296
|
/// Convert the channel envelope used internally by capture into its public
|
|
1288
1297
|
/// typed event. Also useful to native integrations that intentionally route
|
|
1289
1298
|
/// capture through a generic `channelMsg` handler.
|
|
@@ -2976,6 +2985,15 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
2976
2985
|
}.make;
|
|
2977
2986
|
}
|
|
2978
2987
|
|
|
2988
|
+
/// Msg constructor for `setGlobalShortcuts` reports.
|
|
2989
|
+
pub fn globalShortcutMsg(comptime tag: std.meta.Tag(Msg)) ChannelMsgFn {
|
|
2990
|
+
return struct {
|
|
2991
|
+
fn make(event: EffectChannelEvent) Msg {
|
|
2992
|
+
return @unionInit(Msg, @tagName(tag), global_shortcuts_mod.decodeChannelEvent(event));
|
|
2993
|
+
}
|
|
2994
|
+
}.make;
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2979
2997
|
/// Comptime Msg constructor for `on_event` of pty effects:
|
|
2980
2998
|
/// `ptyMsg(.shell)` builds `Msg{ .shell = event }` — the
|
|
2981
2999
|
/// variant's payload type must be `native_sdk.EffectPtyEvent`.
|
|
@@ -3464,6 +3482,12 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
3464
3482
|
max_pending: u32 = max_effect_channel_pending,
|
|
3465
3483
|
};
|
|
3466
3484
|
|
|
3485
|
+
pub const SetGlobalShortcutsOptions = struct {
|
|
3486
|
+
key: u64,
|
|
3487
|
+
shortcuts: []const platform.Shortcut,
|
|
3488
|
+
on_event: ChannelMsgFn,
|
|
3489
|
+
};
|
|
3490
|
+
|
|
3467
3491
|
pub const PtySpawnOptions = struct {
|
|
3468
3492
|
/// Caller-chosen identity, stored in the model. Shares the
|
|
3469
3493
|
/// keyed families' one key space, occupied from spawn until
|
|
@@ -5067,6 +5091,7 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
5067
5091
|
/// channel table; this tiny loop-side mirror exists to quiesce native
|
|
5068
5092
|
/// audio callbacks before closing/reusing their channel occupancy.
|
|
5069
5093
|
audio_capture_slots: [2]AudioCaptureSlot = [_]AudioCaptureSlot{.{}} ** 2,
|
|
5094
|
+
global_shortcuts: global_shortcuts_mod.Session = .{},
|
|
5070
5095
|
/// Monotonic post-order stamp shared by every channel's staging
|
|
5071
5096
|
/// FIFO and the close markers: the cross-channel delivery order
|
|
5072
5097
|
/// and the drain boundary's causality cut (posts stamped at or
|
|
@@ -5314,6 +5339,10 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
5314
5339
|
}
|
|
5315
5340
|
capture.* = .{};
|
|
5316
5341
|
}
|
|
5342
|
+
if (self.global_shortcuts.platform_configured) {
|
|
5343
|
+
if (self.services) |services| services.configureGlobalShortcuts(&.{}, .{}, &.{}) catch {};
|
|
5344
|
+
}
|
|
5345
|
+
self.global_shortcuts = .{};
|
|
5317
5346
|
// Silence the platform audio player (best effort) and clear
|
|
5318
5347
|
// the channel.
|
|
5319
5348
|
if (self.audio.active and !self.audio.fake) {
|
|
@@ -7943,6 +7972,80 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
7943
7972
|
if (result != .accepted) return error.EffectQueueFull;
|
|
7944
7973
|
}
|
|
7945
7974
|
|
|
7975
|
+
/// Register or replace the app's global shortcut set.
|
|
7976
|
+
pub fn setGlobalShortcuts(self: *Self, options: SetGlobalShortcutsOptions) void {
|
|
7977
|
+
const session = &self.global_shortcuts;
|
|
7978
|
+
if (session.active and session.key != options.key) {
|
|
7979
|
+
self.rejectChannel(options.key, options.on_event, true);
|
|
7980
|
+
return;
|
|
7981
|
+
}
|
|
7982
|
+
if (!session.active) {
|
|
7983
|
+
if (self.keyOccupiedUntilDelivery(options.key)) {
|
|
7984
|
+
self.rejectChannel(options.key, options.on_event, true);
|
|
7985
|
+
return;
|
|
7986
|
+
}
|
|
7987
|
+
_ = self.openChannel(.{ .key = options.key, .on_event = options.on_event });
|
|
7988
|
+
if (self.findChannelSlot(options.key) == null) return;
|
|
7989
|
+
session.* = .{ .active = true, .key = options.key };
|
|
7990
|
+
}
|
|
7991
|
+
const handle = self.channelHandle(options.key) orelse return;
|
|
7992
|
+
if (!handle.live()) return;
|
|
7993
|
+
|
|
7994
|
+
var accepted: [platform.max_global_shortcuts]platform.Shortcut = undefined;
|
|
7995
|
+
var accepted_count: usize = 0;
|
|
7996
|
+
for (options.shortcuts) |shortcut| {
|
|
7997
|
+
if (global_shortcuts_mod.admissible(shortcut, accepted[0..accepted_count])) {
|
|
7998
|
+
accepted[accepted_count] = shortcut;
|
|
7999
|
+
accepted_count += 1;
|
|
8000
|
+
} else {
|
|
8001
|
+
postGlobalShortcutReport(handle, .rejected, shortcut);
|
|
8002
|
+
}
|
|
8003
|
+
}
|
|
8004
|
+
|
|
8005
|
+
var statuses: [platform.max_global_shortcuts]platform.GlobalShortcutStatus = undefined;
|
|
8006
|
+
var unsupported = false;
|
|
8007
|
+
if (self.executor == .fake) {
|
|
8008
|
+
for (accepted[0..accepted_count], 0..) |shortcut, index| {
|
|
8009
|
+
statuses[index] = .registered;
|
|
8010
|
+
for (accepted[0..index]) |earlier| {
|
|
8011
|
+
if (platform.sameShortcutCombination(earlier, shortcut)) statuses[index] = .conflict;
|
|
8012
|
+
}
|
|
8013
|
+
}
|
|
8014
|
+
} else if (self.services) |services| {
|
|
8015
|
+
services.configureGlobalShortcuts(accepted[0..accepted_count], globalShortcutSink(handle), statuses[0..accepted_count]) catch {
|
|
8016
|
+
unsupported = true;
|
|
8017
|
+
};
|
|
8018
|
+
session.platform_configured = session.platform_configured or !unsupported;
|
|
8019
|
+
} else {
|
|
8020
|
+
unsupported = true;
|
|
8021
|
+
}
|
|
8022
|
+
|
|
8023
|
+
var next: [platform.max_global_shortcuts]global_shortcuts_mod.Binding = undefined;
|
|
8024
|
+
for (accepted[0..accepted_count], 0..) |shortcut, index| {
|
|
8025
|
+
const kind: EffectGlobalShortcutEventKind = if (unsupported) .unsupported else switch (statuses[index]) {
|
|
8026
|
+
inline else => |status| @field(EffectGlobalShortcutEventKind, @tagName(status)),
|
|
8027
|
+
};
|
|
8028
|
+
const unchanged = if (session.find(shortcut.id)) |previous| previous.shortcut.matches(shortcut) and previous.kind == .registered else false;
|
|
8029
|
+
if (!unchanged or kind != .registered) postGlobalShortcutReport(handle, kind, shortcut);
|
|
8030
|
+
next[index] = .{ .shortcut = .init(shortcut), .kind = kind };
|
|
8031
|
+
}
|
|
8032
|
+
@memcpy(session.bindings[0..accepted_count], next[0..accepted_count]);
|
|
8033
|
+
session.count = accepted_count;
|
|
8034
|
+
}
|
|
8035
|
+
|
|
8036
|
+
/// Unregister the set; reports end with `stopped`.
|
|
8037
|
+
pub fn clearGlobalShortcuts(self: *Self, key: u64) void {
|
|
8038
|
+
if (!self.global_shortcuts.active or self.global_shortcuts.key != key) return;
|
|
8039
|
+
self.closeChannel(key);
|
|
8040
|
+
}
|
|
8041
|
+
|
|
8042
|
+
fn releaseGlobalShortcuts(self: *Self) void {
|
|
8043
|
+
if (self.global_shortcuts.platform_configured) {
|
|
8044
|
+
if (self.services) |services| services.configureGlobalShortcuts(&.{}, globalShortcutSink(self.channelHandle(self.global_shortcuts.key) orelse .{}), &.{}) catch {};
|
|
8045
|
+
}
|
|
8046
|
+
self.global_shortcuts = .{};
|
|
8047
|
+
}
|
|
8048
|
+
|
|
7946
8049
|
/// Close the open channel with `key`: posts stop landing
|
|
7947
8050
|
/// immediately (the handle answers `.closed`), the staged
|
|
7948
8051
|
/// backlog flushes in post order, and exactly one terminal
|
|
@@ -7952,6 +8055,7 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
7952
8055
|
/// is NOT a channel's close (channels end the way audio does:
|
|
7953
8056
|
/// through their own verb).
|
|
7954
8057
|
pub fn closeChannel(self: *Self, key: u64) void {
|
|
8058
|
+
if (self.global_shortcuts.active and self.global_shortcuts.key == key) self.releaseGlobalShortcuts();
|
|
7955
8059
|
if (self.findAudioCaptureByKey(key)) |capture| {
|
|
7956
8060
|
if (capture.platform_started) {
|
|
7957
8061
|
if (self.services) |services| services.audioCaptureStop(capture.source) catch {};
|
|
@@ -9483,6 +9587,40 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
9483
9587
|
self.startHostRequest(options, max_effect_host_payload_bytes, max_effect_host_result_bytes, null, null, null);
|
|
9484
9588
|
}
|
|
9485
9589
|
|
|
9590
|
+
pub const KeyChordOptions = struct {
|
|
9591
|
+
key: u64,
|
|
9592
|
+
chord: platform.KeyChord,
|
|
9593
|
+
on_result: ?HostMsgFn = null,
|
|
9594
|
+
};
|
|
9595
|
+
|
|
9596
|
+
pub const KeyboardAccessOptions = struct {
|
|
9597
|
+
key: u64,
|
|
9598
|
+
prompt: bool = false,
|
|
9599
|
+
on_result: ?HostMsgFn = null,
|
|
9600
|
+
};
|
|
9601
|
+
|
|
9602
|
+
/// Post a key chord to the focused app; requires the `keyboard_input` permission.
|
|
9603
|
+
pub fn sendKeyChord(self: *Self, options: KeyChordOptions) void {
|
|
9604
|
+
var payload: [keyboard_input.max_chord_payload_bytes]u8 = undefined;
|
|
9605
|
+
self.hostRequest(.{
|
|
9606
|
+
.key = options.key,
|
|
9607
|
+
.name = keyboard_input.send_chord_name,
|
|
9608
|
+
.payload = keyboard_input.encodeChord(&payload, options.chord),
|
|
9609
|
+
.on_result = options.on_result,
|
|
9610
|
+
});
|
|
9611
|
+
}
|
|
9612
|
+
|
|
9613
|
+
/// Ask for the OS grant; the ok bytes are `granted`, `denied`, or `not_required`.
|
|
9614
|
+
pub fn keyboardAccessStatus(self: *Self, options: KeyboardAccessOptions) void {
|
|
9615
|
+
const payload = [_]u8{@intFromBool(options.prompt)};
|
|
9616
|
+
self.hostRequest(.{
|
|
9617
|
+
.key = options.key,
|
|
9618
|
+
.name = keyboard_input.access_status_name,
|
|
9619
|
+
.payload = &payload,
|
|
9620
|
+
.on_result = options.on_result,
|
|
9621
|
+
});
|
|
9622
|
+
}
|
|
9623
|
+
|
|
9486
9624
|
fn startHostRequest(
|
|
9487
9625
|
self: *Self,
|
|
9488
9626
|
options: HostRequestOptions,
|
|
@@ -9665,7 +9803,8 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
9665
9803
|
return @import("desktop_files.zig").isName(name) or std.mem.startsWith(u8, name, "core.store.") or
|
|
9666
9804
|
std.mem.eql(u8, name, "native-sdk.launch-at-login.status") or
|
|
9667
9805
|
std.mem.eql(u8, name, "native-sdk.launch-at-login.set") or
|
|
9668
|
-
std.mem.eql(u8, name, "native-sdk.time.formatLocal")
|
|
9806
|
+
std.mem.eql(u8, name, "native-sdk.time.formatLocal") or
|
|
9807
|
+
keyboard_input.isRequestName(name);
|
|
9669
9808
|
}
|
|
9670
9809
|
|
|
9671
9810
|
fn isNativeHostSendName(name: []const u8) bool {
|
|
@@ -9826,6 +9965,13 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
9826
9965
|
self.performBoundSystemRequest(name, key, payload);
|
|
9827
9966
|
return;
|
|
9828
9967
|
}
|
|
9968
|
+
if (keyboard_input.isRequestName(name)) {
|
|
9969
|
+
const binding = (self.system_services orelse return self.feedUnsupportedNativeRequest(key)).keyboard_input orelse
|
|
9970
|
+
return self.feedUnsupportedNativeRequest(key);
|
|
9971
|
+
const result = keyboard_input.execute(binding, name, payload);
|
|
9972
|
+
self.feedHostResult(key, result.ok, result.bytes) catch {};
|
|
9973
|
+
return;
|
|
9974
|
+
}
|
|
9829
9975
|
const services = self.services orelse {
|
|
9830
9976
|
self.feedHostResult(key, false, "unsupported") catch {};
|
|
9831
9977
|
return;
|
|
@@ -10673,12 +10819,19 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
10673
10819
|
/// a `close_policy = .hide` hide and also brings back a minimized
|
|
10674
10820
|
/// or merely backgrounded window. Fire-and-forget, same contract
|
|
10675
10821
|
/// as `closeWindow`: no event echoes beyond the window's own
|
|
10676
|
-
/// frame event, an unknown label is a no-op, and
|
|
10677
|
-
///
|
|
10822
|
+
/// frame event, an unknown label is a no-op, and ordinary fake
|
|
10823
|
+
/// execution only records the request in the mirror. Replay also
|
|
10824
|
+
/// restores the synchronous visibility/focus transition before
|
|
10825
|
+
/// any checkpoint, without entering the native show service.
|
|
10678
10826
|
pub fn showWindow(self: *Self, window_label: []const u8) void {
|
|
10679
10827
|
self.window_action_state.show_count += 1;
|
|
10680
10828
|
self.window_action_state.record(window_label);
|
|
10681
|
-
if (self.executor == .fake)
|
|
10829
|
+
if (self.executor == .fake) {
|
|
10830
|
+
if (self.replay) if (self.window_actions) |binding| {
|
|
10831
|
+
if (binding.replay_show_fn) |restore| restore(binding.context, window_label);
|
|
10832
|
+
};
|
|
10833
|
+
return;
|
|
10834
|
+
}
|
|
10682
10835
|
const binding = self.window_actions orelse return;
|
|
10683
10836
|
_ = binding.show_fn(binding.context, window_label);
|
|
10684
10837
|
}
|
|
@@ -12098,6 +12251,7 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
12098
12251
|
if (entry.retire_slot) |slot_index| {
|
|
12099
12252
|
const parked = &self.channel_slots[slot_index];
|
|
12100
12253
|
if (parked.state != .idle and parked.generation == entry.retire_generation) {
|
|
12254
|
+
if (self.global_shortcuts.active and self.global_shortcuts.key == parked.key) self.global_shortcuts = .{};
|
|
12101
12255
|
retireChannelSlot(parked);
|
|
12102
12256
|
}
|
|
12103
12257
|
}
|
|
@@ -14127,6 +14281,20 @@ pub fn Effects(comptime Msg: type) type {
|
|
|
14127
14281
|
return null;
|
|
14128
14282
|
}
|
|
14129
14283
|
|
|
14284
|
+
fn postGlobalShortcutReport(handle: ChannelHandle, kind: EffectGlobalShortcutEventKind, shortcut: platform.Shortcut) void {
|
|
14285
|
+
var packet: [global_shortcuts_mod.max_packet_bytes]u8 = undefined;
|
|
14286
|
+
_ = handle.post(global_shortcuts_mod.encodePacket(&packet, kind, shortcut));
|
|
14287
|
+
}
|
|
14288
|
+
|
|
14289
|
+
fn globalShortcutSink(handle: ChannelHandle) platform.GlobalShortcutSink {
|
|
14290
|
+
return .{ .context = handle.shared, .generation = handle.generation, .push_fn = pushGlobalShortcutEvent };
|
|
14291
|
+
}
|
|
14292
|
+
|
|
14293
|
+
fn pushGlobalShortcutEvent(context: ?*anyopaque, generation: u64, event: platform.GlobalShortcutEvent) void {
|
|
14294
|
+
const handle: ChannelHandle = .{ .shared = @ptrCast(@alignCast(context orelse return)), .generation = generation };
|
|
14295
|
+
postGlobalShortcutReport(handle, if (event.phase == .pressed) .pressed else .released, event.shortcut);
|
|
14296
|
+
}
|
|
14297
|
+
|
|
14130
14298
|
fn pushAudioCaptureEvent(context: ?*anyopaque, generation: u64, event: platform.AudioCaptureEvent) platform.AudioCapturePushResult {
|
|
14131
14299
|
const shared: *ChannelShared = @ptrCast(@alignCast(context orelse return .closed));
|
|
14132
14300
|
var packet: [max_effect_channel_bytes]u8 = undefined;
|
|
@@ -11,6 +11,7 @@ const std = @import("std");
|
|
|
11
11
|
const geometry = @import("geometry");
|
|
12
12
|
const app_manifest = @import("app_manifest");
|
|
13
13
|
const platform = @import("../platform/root.zig");
|
|
14
|
+
const security = @import("../security/root.zig");
|
|
14
15
|
const core = @import("core.zig");
|
|
15
16
|
const ui_app_mod = @import("ui_app.zig");
|
|
16
17
|
const effects_mod = @import("effects.zig");
|
|
@@ -70,6 +71,8 @@ const HostMsg = union(enum) {
|
|
|
70
71
|
credential_prefixed_request,
|
|
71
72
|
open_external_url,
|
|
72
73
|
reveal_path,
|
|
74
|
+
send_chord,
|
|
75
|
+
keyboard_access,
|
|
73
76
|
replace,
|
|
74
77
|
drop,
|
|
75
78
|
send,
|
|
@@ -143,6 +146,12 @@ fn hostUpdate(model: *HostModel, msg: HostMsg, fx: *HostEffects) void {
|
|
|
143
146
|
}),
|
|
144
147
|
.open_external_url => fx.hostSend("native-sdk.os.openUrl", "https://example.com/docs"),
|
|
145
148
|
.reveal_path => fx.hostSend("native-sdk.os.revealPath", "/tmp/native-sdk.log"),
|
|
149
|
+
.send_chord => fx.sendKeyChord(.{
|
|
150
|
+
.key = ask_key,
|
|
151
|
+
.chord = platform.KeyChord.init("enter", .{ .command = true, .control = true, .option = true, .shift = true }).?,
|
|
152
|
+
.on_result = HostEffects.hostMsg(.host_result),
|
|
153
|
+
}),
|
|
154
|
+
.keyboard_access => fx.keyboardAccessStatus(.{ .key = ask_key, .prompt = true, .on_result = HostEffects.hostMsg(.host_result) }),
|
|
146
155
|
.replace => fx.hostRequest(.{
|
|
147
156
|
.key = ask_key,
|
|
148
157
|
.name = "svc.echo",
|
|
@@ -285,6 +294,22 @@ test "native launch-at-login requests use the platform service without a generic
|
|
|
285
294
|
try std.testing.expectEqual(@as(u32, 1), h.harness.null_platform.launch_at_login_set_count);
|
|
286
295
|
}
|
|
287
296
|
|
|
297
|
+
test "Zig keyboard effects reach the platform once keyboard_input is declared" {
|
|
298
|
+
var h = try Harness.create();
|
|
299
|
+
defer h.destroy();
|
|
300
|
+
|
|
301
|
+
h.harness.runtime.options.security.permissions = &.{security.permission_keyboard_input};
|
|
302
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .send_chord);
|
|
303
|
+
try h.wake();
|
|
304
|
+
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.ok_count);
|
|
305
|
+
try std.testing.expectEqual(platform.KeyChord.init("enter", .{ .command = true, .control = true, .option = true, .shift = true }).?, h.harness.null_platform.keyboardChords()[0]);
|
|
306
|
+
|
|
307
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .keyboard_access);
|
|
308
|
+
try h.wake();
|
|
309
|
+
try std.testing.expectEqual(@as(u32, 2), h.app_state.model.ok_count);
|
|
310
|
+
try std.testing.expectEqualStrings("granted", h.app_state.model.bytesPrefix());
|
|
311
|
+
}
|
|
312
|
+
|
|
288
313
|
test "native launch-at-login set preserves an unsupported platform result" {
|
|
289
314
|
var h = try Harness.create();
|
|
290
315
|
defer h.destroy();
|
package/src/runtime/flow.zig
CHANGED
|
@@ -233,6 +233,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
233
233
|
self.snapshot_policy = app.snapshot_policy;
|
|
234
234
|
self.frame_profile.policy = app.snapshot_policy;
|
|
235
235
|
self.command_policy = app.command_policy;
|
|
236
|
+
self.context_menu_policy = app.context_menu_policy;
|
|
236
237
|
self.text_cache_policy = app.text_cache_policy;
|
|
237
238
|
self.render_cache_policy = app.render_cache_policy;
|
|
238
239
|
self.render_plan_policy = app.render_plan_policy;
|
|
@@ -251,6 +251,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
251
251
|
self.snapshot_policy = app.snapshot_policy;
|
|
252
252
|
self.frame_profile.policy = app.snapshot_policy;
|
|
253
253
|
self.command_policy = app.command_policy;
|
|
254
|
+
self.context_menu_policy = app.context_menu_policy;
|
|
254
255
|
self.text_cache_policy = app.text_cache_policy;
|
|
255
256
|
self.render_cache_policy = app.render_cache_policy;
|
|
256
257
|
self.render_plan_policy = app.render_plan_policy;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//! Global shortcut report event, packet codec, and set mirror.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const platform = @import("../platform/root.zig");
|
|
4
|
+
|
|
5
|
+
/// What a global shortcut report says.
|
|
6
|
+
pub const EffectGlobalShortcutEventKind = enum(u8) { registered, pressed, released, conflict, unsupported, rejected, stopped };
|
|
7
|
+
|
|
8
|
+
/// A global shortcut report; `shortcut` slices are drain scratch.
|
|
9
|
+
pub const EffectGlobalShortcutEvent = struct {
|
|
10
|
+
key: u64,
|
|
11
|
+
kind: EffectGlobalShortcutEventKind,
|
|
12
|
+
shortcut: platform.Shortcut = .{ .id = "", .key = "" },
|
|
13
|
+
dropped_pending: u32 = 0,
|
|
14
|
+
dropped_total: u32 = 0,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const magic = "GS01";
|
|
18
|
+
const header_bytes: usize = 8;
|
|
19
|
+
pub const max_packet_bytes: usize = header_bytes + platform.max_shortcut_id_bytes + platform.max_shortcut_key_bytes;
|
|
20
|
+
|
|
21
|
+
pub fn modifierMask(modifiers: platform.ShortcutModifiers) u8 {
|
|
22
|
+
return @as(u8, @intFromBool(modifiers.primary)) | @as(u8, @intFromBool(modifiers.command)) << 1 | @as(u8, @intFromBool(modifiers.control)) << 2 |
|
|
23
|
+
@as(u8, @intFromBool(modifiers.option)) << 3 | @as(u8, @intFromBool(modifiers.shift)) << 4;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
pub fn modifiersFromMask(mask: u8) platform.ShortcutModifiers {
|
|
27
|
+
return .{ .primary = mask & 1 != 0, .command = mask & 2 != 0, .control = mask & 4 != 0, .option = mask & 8 != 0, .shift = mask & 16 != 0 };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub fn encodePacket(buffer: *[max_packet_bytes]u8, kind: EffectGlobalShortcutEventKind, shortcut: platform.Shortcut) []const u8 {
|
|
31
|
+
const id = shortcut.id[0..@min(shortcut.id.len, platform.max_shortcut_id_bytes)];
|
|
32
|
+
const key = shortcut.key[0..@min(shortcut.key.len, platform.max_shortcut_key_bytes)];
|
|
33
|
+
buffer[0..header_bytes].* = (magic ++ .{ @intFromEnum(kind), modifierMask(shortcut.modifiers), @as(u8, @intCast(id.len)), @as(u8, @intCast(key.len)) }).*;
|
|
34
|
+
@memcpy(buffer[header_bytes..][0..id.len], id);
|
|
35
|
+
@memcpy(buffer[header_bytes + id.len ..][0..key.len], key);
|
|
36
|
+
return buffer[0 .. header_bytes + id.len + key.len];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub fn decodeChannelEvent(channel: anytype) EffectGlobalShortcutEvent {
|
|
40
|
+
var event: EffectGlobalShortcutEvent = .{ .key = channel.key, .kind = .rejected, .dropped_pending = channel.dropped_pending, .dropped_total = channel.dropped_total };
|
|
41
|
+
const bytes = channel.bytes;
|
|
42
|
+
if (channel.kind == .closed) event.kind = .stopped;
|
|
43
|
+
if (channel.kind != .data or bytes.len < header_bytes or !std.mem.eql(u8, bytes[0..4], magic) or bytes.len != header_bytes + bytes[6] + bytes[7]) return event;
|
|
44
|
+
event.kind = std.enums.fromInt(EffectGlobalShortcutEventKind, bytes[4]) orelse .rejected;
|
|
45
|
+
event.shortcut = .{ .id = bytes[header_bytes..][0..bytes[6]], .key = bytes[header_bytes + bytes[6] ..][0..bytes[7]], .modifiers = modifiersFromMask(bytes[5]) };
|
|
46
|
+
return event;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub const Binding = struct { shortcut: platform.OwnedShortcut, kind: EffectGlobalShortcutEventKind };
|
|
50
|
+
|
|
51
|
+
pub const Session = struct {
|
|
52
|
+
active: bool = false,
|
|
53
|
+
key: u64 = 0,
|
|
54
|
+
platform_configured: bool = false,
|
|
55
|
+
bindings: [platform.max_global_shortcuts]Binding = undefined,
|
|
56
|
+
count: usize = 0,
|
|
57
|
+
|
|
58
|
+
pub fn find(self: *const Session, id: []const u8) ?*const Binding {
|
|
59
|
+
for (self.bindings[0..self.count]) |*binding| {
|
|
60
|
+
if (std.mem.eql(u8, binding.shortcut.shortcut().id, id)) return binding;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
pub fn admissible(shortcut: platform.Shortcut, earlier: []const platform.Shortcut) bool {
|
|
67
|
+
platform.validateShortcut(shortcut) catch return false;
|
|
68
|
+
const modifiers = shortcut.modifiers;
|
|
69
|
+
const function_key = shortcut.key.len > 1 and std.ascii.toLower(shortcut.key[0]) == 'f' and std.ascii.isDigit(shortcut.key[1]);
|
|
70
|
+
if (!function_key and !(modifiers.primary or modifiers.command or modifiers.control or modifiers.option)) return false;
|
|
71
|
+
for (earlier) |previous| {
|
|
72
|
+
if (std.mem.eql(u8, previous.id, shortcut.id)) return false;
|
|
73
|
+
}
|
|
74
|
+
return earlier.len < platform.max_global_shortcuts;
|
|
75
|
+
}
|