Add XkbBinding.deinit()
Also fixed a crash if two non-spawn keybinds had the same keys
This commit is contained in:
parent
1b37ab7afd
commit
9fef3f70f5
3 changed files with 43 additions and 14 deletions
|
|
@ -127,13 +127,7 @@ pub fn create() !*Config {
|
||||||
|
|
||||||
pub fn destroy(config: *Config) void {
|
pub fn destroy(config: *Config) void {
|
||||||
for (config.keybinds.values()) |cmd| {
|
for (config.keybinds.values()) |cmd| {
|
||||||
switch (cmd) {
|
cmd.deinit();
|
||||||
.spawn => |argv| {
|
|
||||||
for (argv) |arg| utils.gpa.free(arg);
|
|
||||||
utils.gpa.free(argv);
|
|
||||||
},
|
|
||||||
else => {},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
config.keybinds.deinit(utils.gpa);
|
config.keybinds.deinit(utils.gpa);
|
||||||
config.tag_binds.deinit(utils.gpa);
|
config.tag_binds.deinit(utils.gpa);
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,47 @@ pub const Command = union(enum) {
|
||||||
|
|
||||||
// When passthrough is enabled, only keybinds set to toggle_passthrough are active
|
// When passthrough is enabled, only keybinds set to toggle_passthrough are active
|
||||||
toggle_passthrough,
|
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 {
|
const XkbBinding = struct {
|
||||||
|
|
|
||||||
|
|
@ -185,13 +185,7 @@ pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
.keysym = keysym,
|
.keysym = keysym,
|
||||||
});
|
});
|
||||||
if (gop.found_existing) {
|
if (gop.found_existing) {
|
||||||
switch (gop.value_ptr.*) {
|
gop.value_ptr.deinit();
|
||||||
.spawn => |argv| {
|
|
||||||
for (argv) |arg| utils.gpa.free(arg);
|
|
||||||
utils.gpa.free(argv);
|
|
||||||
},
|
|
||||||
else => unreachable,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gop.value_ptr.* = command;
|
gop.value_ptr.* = command;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue