Add XkbBinding.deinit()

Also fixed a crash if two non-spawn keybinds had the same keys
This commit is contained in:
Ben Buhse 2026-02-22 14:57:41 -06:00
commit 9fef3f70f5
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
3 changed files with 43 additions and 14 deletions

View file

@ -127,13 +127,7 @@ pub fn create() !*Config {
pub fn destroy(config: *Config) void {
for (config.keybinds.values()) |cmd| {
switch (cmd) {
.spawn => |argv| {
for (argv) |arg| utils.gpa.free(arg);
utils.gpa.free(argv);
},
else => {},
}
cmd.deinit();
}
config.keybinds.deinit(utils.gpa);
config.tag_binds.deinit(utils.gpa);

View file

@ -50,6 +50,47 @@ pub const Command = union(enum) {
// When passthrough is enabled, only keybinds set to toggle_passthrough are active
toggle_passthrough,
/// Explicitly list each variant so that, if we add a new one,
/// we'll get a reminder to free it here (instead of it being
/// swallowed by an `else =>`)
pub fn deinit(self: Command) void {
switch (self) {
.spawn => |argv| {
for (argv) |arg| utils.gpa.free(arg);
utils.gpa.free(argv);
},
.focus_next_window,
.focus_prev_window,
.focus_next_output,
.focus_prev_output,
.send_to_next_output,
.send_to_prev_output,
.zoom,
.toggle_float,
.change_ratio,
.increment_primary_count,
.decrement_primary_count,
.reload_config,
.toggle_fullscreen,
.close_window,
.set_output_tags,
.set_window_tags,
.toggle_output_tags,
.toggle_window_tags,
.move_up,
.move_down,
.move_left,
.move_right,
.resize_width,
.resize_height,
.center_float,
.swap_next,
.swap_prev,
.toggle_passthrough,
=> {},
}
}
};
const XkbBinding = struct {

View file

@ -185,13 +185,7 @@ pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
.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.deinit();
}
gop.value_ptr.* = command;
} else {