config: copy key table name into arena

This commit is contained in:
Mitchell Hashimoto
2025-12-20 15:11:08 -08:00
parent daa613482e
commit 845bcdb498
2 changed files with 14 additions and 3 deletions

View File

@@ -5609,15 +5609,20 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.activate_key_table_once,
=> |name, tag| {
// Look up the table in our config
const set = self.config.keybind.tables.getPtr(name) orelse
const set = self.config.keybind.tables.getPtr(name) orelse {
log.debug("key table not found: {s}", .{name});
return false;
};
// If this is the same table as is currently active, then
// do nothing.
if (self.keyboard.table_stack.items.len > 0) {
const items = self.keyboard.table_stack.items;
const active = items[items.len - 1].set;
if (active == set) return false;
if (active == set) {
log.debug("ignoring duplicate activate table: {s}", .{name});
return false;
}
}
// Add the table to the stack.
@@ -5625,6 +5630,8 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.set = set,
.once = tag == .activate_key_table_once,
});
log.debug("key table activated: {s}", .{name});
},
.deactivate_key_table => switch (self.keyboard.table_stack.items.len) {

View File

@@ -6610,6 +6610,9 @@ pub const Keybinds = struct {
// Get or create the table
const gop = try self.tables.getOrPut(alloc, table_name);
if (!gop.found_existing) {
// We need to copy our table name into the arena
// for valid lookups later.
gop.key_ptr.* = try alloc.dupe(u8, table_name);
gop.value_ptr.* = .{};
}
@@ -6636,7 +6639,8 @@ pub const Keybinds = struct {
try tables.ensureTotalCapacity(alloc, @intCast(self.tables.count()));
var it = self.tables.iterator();
while (it.next()) |entry| {
tables.putAssumeCapacity(entry.key_ptr.*, try entry.value_ptr.clone(alloc));
const key = try alloc.dupe(u8, entry.key_ptr.*);
tables.putAssumeCapacity(key, try entry.value_ptr.clone(alloc));
}
return .{