diff --git a/src/keybind/dynamic/KeyEvent.zig b/src/keybind/dynamic/KeyEvent.zig index 8f1eea8..25debaf 100644 --- a/src/keybind/dynamic/KeyEvent.zig +++ b/src/keybind/dynamic/KeyEvent.zig @@ -8,3 +8,21 @@ modifiers: input.Mods = 0, pub fn eql(self: @This(), other: @This()) bool { return std.meta.eql(self, other); } + +pub fn format(self: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + if (self.event == input.event.press) try writer.writeAll("press "); + if (self.event == input.event.repeat) try writer.writeAll("repeat "); + if (self.event == input.event.release) try writer.writeAll("release "); + const mods: input.ModSet = @bitCast(self.modifiers); + if (mods.super) try writer.writeAll("super+"); + if (mods.ctrl) try writer.writeAll("ctrl+"); + if (mods.alt) try writer.writeAll("alt+"); + if (mods.shift) try writer.writeAll("shift+"); + var key_string = input.utils.key_id_string(self.key); + var buf: [6]u8 = undefined; + if (key_string.len == 0) { + const bytes = try input.ucs32_to_utf8(&[_]u32{self.key}, &buf); + key_string = buf[0..bytes]; + } + try writer.writeAll(key_string); +} diff --git a/src/keybind/dynamic/keybind.zig b/src/keybind/dynamic/keybind.zig index e945ade..f224470 100644 --- a/src/keybind/dynamic/keybind.zig +++ b/src/keybind/dynamic/keybind.zig @@ -587,17 +587,26 @@ const BindingSet = struct { try self.current_sequence_egc.appendSlice(buf[0..bytes]); var all_matches_impossible = true; - defer if (!builtin.is_test) self.logger.print("process_key_event all_matches_impossible:{any} event:{any} egc:{d} text:'{s}' sequence:'{s}' bindings:{d}", .{ - all_matches_impossible, + var matched_count: usize = 0; + var match_possible_count: usize = 0; + var match_impossible_count: usize = 0; + if (!builtin.is_test) self.logger.print("process_key_event begin event:{} egc:{d} text:'{s}' sequence:'{s}' bindings:{d}", .{ event, egc, buf[0..bytes], self.current_sequence_egc.items, self.bindings.items.len, }); + defer if (!builtin.is_test) self.logger.print("process_key_event end all_matches_impossible:{any} bindings matched:{d} possible:{d} impossible:{d}", .{ + all_matches_impossible, + matched_count, + match_possible_count, + match_impossible_count, + }); for (self.bindings.items) |binding| blk: { switch (binding.match(self.current_sequence.items)) { .matched => { + matched_count += 1; errdefer { //clear current sequence if command execution fails self.current_sequence.clearRetainingCapacity(); @@ -614,10 +623,12 @@ const BindingSet = struct { break :blk; }, .match_possible => { + match_possible_count += 1; if (!builtin.is_test) self.logger.print("match possible for binding -> {s}", .{binding.command}); all_matches_impossible = false; }, .match_impossible => { + match_impossible_count += 1; if (!builtin.is_test) self.logger.print("match impossible for binding -> {s}", .{binding.command}); }, }