summaryrefslogtreecommitdiff
path: root/src/host/script.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 07:57:28 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit1533644884c5cd2b072f78e3a42d5c4fa52f793a (patch)
treeba1a5a92af567fb82b7d667a4152c0b3b71dd973 /src/host/script.zig
parentf37732448a2a374281c9610d05a10315e97dcbbf (diff)
downloadsketchbook-1533644884c5cd2b072f78e3a42d5c4fa52f793a.tar.gz
sketchbook-1533644884c5cd2b072f78e3a42d5c4fa52f793a.zip
script: a key carries the modifiers `hold` has down, as a window's does
A window's key event carries the modifiers held as it happened in its `value` (Host.zig, `modifiers(event.key.mod)`), and a sketch reads chords from there (examples/live: Alt-o, helix's node walk). A script's `key` (and a 9P ctl's `input key`) left `value` 0, so `hold left_alt` then `key o` was a plain o to the sketch: the chord could not be scripted. `key` now carries what `hold` has down, as `click` and the other pointer verbs already did in their `flags`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/host/script.zig')
-rw-r--r--src/host/script.zig24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/host/script.zig b/src/host/script.zig
index e3976e0..817462b 100644
--- a/src/host/script.zig
+++ b/src/host/script.zig
@@ -107,8 +107,9 @@ pub fn input(host: *Host, verb: Verb, words: *std.mem.TokenIterator(u8, .any), n
.cancel => try host.route(.{ .kind = .cancel, .time = now }),
.key => {
const key = std.meta.stringToEnum(abi.Key, rest) orelse return error.UnknownKey;
- try host.route(.{ .kind = .key_down, .time = now, .code = @backingInt(key) });
- try host.route(.{ .kind = .key_up, .time = now, .code = @backingInt(key) });
+ // with the modifiers `hold` has down, as a window's key carries them
+ try host.route(.{ .kind = .key_down, .time = now, .code = @backingInt(key), .value = mods(host) });
+ try host.route(.{ .kind = .key_up, .time = now, .code = @backingInt(key), .value = mods(host) });
},
.hold, .release => {
const key = std.meta.stringToEnum(abi.Key, rest) orelse return error.UnknownKey;
@@ -285,14 +286,19 @@ fn step(host: *Host, arena: std.mem.Allocator, verb: Verb, rest: []const u8, wor
if (verbs.get(verb).frame) try advance(host, now);
}
-/// The modifiers `hold` has down, for a pointer event's `flags`.
+/// The modifiers `hold` has down, as `Key.Mod` bits: a key event's `value`.
+fn mods(host: *const Host) u32 {
+ var m: u32 = 0;
+ if (host.input.held(abi.Key.left_shift) or host.input.held(abi.Key.right_shift)) m |= abi.Key.Mod.shift;
+ if (host.input.held(abi.Key.left_ctrl) or host.input.held(abi.Key.right_ctrl)) m |= abi.Key.Mod.ctrl;
+ if (host.input.held(abi.Key.left_alt) or host.input.held(abi.Key.right_alt)) m |= abi.Key.Mod.alt;
+ if (host.input.held(abi.Key.left_gui) or host.input.held(abi.Key.right_gui)) m |= abi.Key.Mod.gui;
+ return m;
+}
+
+/// The same, for a pointer event's `flags`.
fn held(host: *const Host) u8 {
- var mods: u32 = 0;
- if (host.input.held(abi.Key.left_shift) or host.input.held(abi.Key.right_shift)) mods |= abi.Key.Mod.shift;
- if (host.input.held(abi.Key.left_ctrl) or host.input.held(abi.Key.right_ctrl)) mods |= abi.Key.Mod.ctrl;
- if (host.input.held(abi.Key.left_alt) or host.input.held(abi.Key.right_alt)) mods |= abi.Key.Mod.alt;
- if (host.input.held(abi.Key.left_gui) or host.input.held(abi.Key.right_gui)) mods |= abi.Key.Mod.gui;
- return abi.Event.withModifiers(mods);
+ return abi.Event.withModifiers(mods(host));
}
/// "VALUE" or "VALUE ~TOLERANCE".