From 1533644884c5cd2b072f78e3a42d5c4fa52f793a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 07:57:28 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/host/script.zig | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') 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". -- cgit v1.3