From fdf9d2942817a675e20f7d2efc68ed21862a5fb5 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Tue, 7 Jan 2025 06:25:46 +0400 Subject: [PATCH] feat: add new noop action for key bindings (#4680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces a “noop” action for key bindings, allowing shortcuts to be defined without triggering any action, while still passing the key event to the pseudoterminal (pty). - Unlike “ignore,” it does not block the key event from reaching the pty. - Unlike “unbind,” it overrides OS-level shortcuts, effectively disabling the default OS-level action. --- src/App.zig | 2 ++ src/Surface.zig | 6 +++++- src/input/Binding.zig | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/App.zig b/src/App.zig index a6b54db23..15f55a4b8 100644 --- a/src/App.zig +++ b/src/App.zig @@ -437,6 +437,7 @@ pub fn performAction( switch (action) { .unbind => unreachable, .ignore => {}, + .noop => {}, .quit => try rt_app.performAction(.app, .quit, {}), .new_window => try self.newWindow(rt_app, .{ .parent = null }), .open_config => try rt_app.performAction(.app, .open_config, {}), @@ -581,3 +582,4 @@ pub const Wasm = if (!builtin.target.isWasm()) struct {} else struct { // } // } }; + diff --git a/src/Surface.zig b/src/Surface.zig index 70c32098f..511b05be4 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1968,7 +1968,10 @@ fn maybeHandleBinding( // If we have the performable flag and the action was not performed, // then we act as though a binding didn't exist. - if (leaf.flags.performable and !performed) { + if (leaf.flags.performable and !performed or switch (action) { + .noop => true, + else => false, + }) { // If we're in a sequence, we treat this as if we pressed a key // that doesn't exist in the sequence. Reset our sequence and flush // any queued events. @@ -4643,3 +4646,4 @@ fn presentSurface(self: *Surface) !void { {}, ); } + diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 64e07e85e..9289e28e0 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -229,6 +229,11 @@ pub const Action = union(enum) { /// assertion to verify this. unbind: void, + /// This action is similar to `unbind` but it is used to flag that the + /// binding should be removed from the set and the key should be unbound + /// from the system. + noop: void, + /// Send a CSI sequence. The value should be the CSI sequence without the /// CSI header (`ESC [` or `\x1b[`). csi: []const u8, @@ -685,6 +690,7 @@ pub const Action = union(enum) { // Doesn't really matter, so we'll see app. .ignore, .unbind, + .noop, => .app, // Obviously app actions.