Make Config.keybinds into a hash map

This helps us with de-duplication. Previously, if you had host-specific
keybinds on the same key combination, the compositor would choose the
first... which is the opposite of how everything else in our config
handling works.
This commit is contained in:
Ben Buhse 2026-02-16 19:44:05 -06:00
commit 4c0117724e
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
3 changed files with 26 additions and 11 deletions

View file

@ -11,6 +11,13 @@ pub const Keybind = struct {
keysym: ?xkbcommon.Keysym,
};
pub const Key = struct {
modifiers: river.SeatV1.Modifiers,
keysym: xkbcommon.Keysym,
};
pub const Map = std.AutoArrayHashMapUnmanaged(Key, XkbBindings.Command);
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
while (try parser.next()) |event| {
switch (event) {
@ -172,11 +179,20 @@ pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
},
};
try config.keybinds.append(utils.gpa, .{
const gop = try config.keybinds.getOrPut(utils.gpa, .{
.modifiers = modifiers,
.command = command,
.keysym = keysym,
});
if (gop.found_existing) {
switch (gop.value_ptr.*) {
.spawn => |argv| {
for (argv) |arg| utils.gpa.free(arg);
utils.gpa.free(argv);
},
else => unreachable,
}
}
gop.value_ptr.* = command;
} else {
helpers.logWarnInvalidNode(node.name);
}