Add a keybind to reload config; still needs more testing
This commit is contained in:
parent
365c000b6e
commit
cd32463d52
2 changed files with 33 additions and 20 deletions
|
|
@ -313,15 +313,6 @@ fn loadKeybindsChildBlock(config: *Config, parser: *kdl.Parser) !void {
|
||||||
const split_exec = try utils.tokenizeToOwnedSlices(exec_str, ' ');
|
const split_exec = try utils.tokenizeToOwnedSlices(exec_str, ' ');
|
||||||
break :sw .{ .spawn = split_exec };
|
break :sw .{ .spawn = split_exec };
|
||||||
},
|
},
|
||||||
.focus_next => {
|
|
||||||
break :sw .focus_next;
|
|
||||||
},
|
|
||||||
.focus_prev => {
|
|
||||||
break :sw .focus_prev;
|
|
||||||
},
|
|
||||||
.zoom => {
|
|
||||||
break :sw .zoom;
|
|
||||||
},
|
|
||||||
.change_ratio => {
|
.change_ratio => {
|
||||||
const diff_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
const diff_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
||||||
logWarnMissingNodeArg(name, "diff");
|
logWarnMissingNodeArg(name, "diff");
|
||||||
|
|
@ -333,11 +324,13 @@ fn loadKeybindsChildBlock(config: *Config, parser: *kdl.Parser) !void {
|
||||||
};
|
};
|
||||||
break :sw .{ .change_ratio = diff };
|
break :sw .{ .change_ratio = diff };
|
||||||
},
|
},
|
||||||
.toggle_fullscreen => {
|
inline .focus_next, .focus_prev, .zoom, .reload_config, .toggle_fullscreen, .close_window => |cmd| {
|
||||||
break :sw .toggle_fullscreen;
|
// None of these have arguments, just create the union and give it back
|
||||||
},
|
break :sw @unionInit(
|
||||||
.close_window => {
|
XkbBindings.Command,
|
||||||
break :sw .close_window;
|
@tagName(cmd),
|
||||||
|
{},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
inline .set_output_tags, .set_window_tags, .toggle_output_tags, .toggle_window_tags => |cmd| {
|
inline .set_output_tags, .set_window_tags, .toggle_output_tags, .toggle_window_tags => |cmd| {
|
||||||
const tags_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
const tags_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
||||||
|
|
@ -348,7 +341,11 @@ fn loadKeybindsChildBlock(config: *Config, parser: *kdl.Parser) !void {
|
||||||
logWarnInvalidNodeArg(name, tags_str);
|
logWarnInvalidNodeArg(name, tags_str);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
break :sw @unionInit(XkbBindings.Command, @tagName(cmd), tags);
|
break :sw @unionInit(
|
||||||
|
XkbBindings.Command,
|
||||||
|
@tagName(cmd),
|
||||||
|
tags,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,9 @@ pub const Command = union(enum) {
|
||||||
focus_prev,
|
focus_prev,
|
||||||
zoom,
|
zoom,
|
||||||
change_ratio: f32,
|
change_ratio: f32,
|
||||||
// reload_config, // TODO
|
reload_config,
|
||||||
toggle_fullscreen,
|
toggle_fullscreen,
|
||||||
close_window,
|
close_window,
|
||||||
// exit, // TODO: Delete?
|
|
||||||
// Tag management
|
// Tag management
|
||||||
set_output_tags: u32,
|
set_output_tags: u32,
|
||||||
set_window_tags: u32,
|
set_window_tags: u32,
|
||||||
|
|
@ -128,10 +127,26 @@ const XkbBinding = struct {
|
||||||
current_focus.link.swapWith(&first_window.link);
|
current_focus.link.swapWith(&first_window.link);
|
||||||
},
|
},
|
||||||
.change_ratio => |diff| {
|
.change_ratio => |diff| {
|
||||||
const new_ratio = context.wm.primary_ratio + diff;
|
context.wm.pending_manage.primary_ratio = std.math.clamp(context.wm.primary_ratio + diff, 0.10, 0.90);
|
||||||
if (new_ratio >= 0.10 and new_ratio <= 0.90) {
|
},
|
||||||
context.wm.pending_manage.primary_ratio = context.wm.primary_ratio + diff;
|
.reload_config => {
|
||||||
|
// Try create new config
|
||||||
|
const new_config = Config.create() catch {
|
||||||
|
// We do this so that, if the Config fails to reload, the
|
||||||
|
// user still has *some* config.
|
||||||
|
log.err("Failed to reload Config. Not deleting old one", .{});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
// Clean up old one
|
||||||
|
var it = context.xkb_bindings.bindings.safeIterator(.forward);
|
||||||
|
while (it.next()) |binding| {
|
||||||
|
binding.link.remove();
|
||||||
|
binding.destroy();
|
||||||
}
|
}
|
||||||
|
context.config.destroy();
|
||||||
|
// Replace the old one
|
||||||
|
context.config = new_config;
|
||||||
|
context.initialized = false;
|
||||||
},
|
},
|
||||||
.toggle_fullscreen => {
|
.toggle_fullscreen => {
|
||||||
const seat = context.wm.seats.first() orelse return;
|
const seat = context.wm.seats.first() orelse return;
|
||||||
|
|
@ -241,6 +256,7 @@ const xkbcommon = @import("xkbcommon");
|
||||||
|
|
||||||
const utils = @import("utils.zig");
|
const utils = @import("utils.zig");
|
||||||
const Context = @import("Context.zig");
|
const Context = @import("Context.zig");
|
||||||
|
const Config = @import("Config.zig");
|
||||||
const Seat = @import("Seat.zig");
|
const Seat = @import("Seat.zig");
|
||||||
const Window = @import("Window.zig");
|
const Window = @import("Window.zig");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue