From dbd8add23ec1c7f7e2bdfaf258de0e5a7a6ef628 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 17 Sep 2023 14:31:15 -0700 Subject: [PATCH] core: don't send release events for key bindings Fixes #482 --- src/Surface.zig | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 3bfe6c991..6ff8c11b9 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -963,9 +963,9 @@ pub fn keyCallback( // Before encoding, we see if we have any keybindings for this // key. Those always intercept before any encoding tasks. - if (event.action == .press or event.action == .repeat) { - const binding_mods = event.mods.binding(); - const binding_action_: ?input.Binding.Action = action: { + binding: { + const binding_action: input.Binding.Action = action: { + const binding_mods = event.mods.binding(); var trigger: input.Binding.Trigger = .{ .mods = binding_mods, .key = event.key, @@ -978,14 +978,17 @@ pub fn keyCallback( trigger.physical = true; if (set.get(trigger)) |v| break :action v; - break :action null; + break :binding; }; - if (binding_action_) |binding_action| { - //log.warn("BINDING ACTION={}", .{binding_action}); + // We only execute the binding on press/repeat but we still consume + // the key on release so that we don't send any release events. + log.debug("key event consumed by binding action={}", .{binding_action}); + if (event.action == .press or event.action == .repeat) { try self.performBindingAction(binding_action); - return true; } + + return true; } // If this input event has text, then we hide the mouse if configured.