From f5c1dfa37471e8ea2ceff494e9b09953a6b485e4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 13 Mar 2023 22:00:10 -0700 Subject: [PATCH] reload_config keybinding (defaults to ctrl+alt+super+space) --- src/App.zig | 2 ++ src/Surface.zig | 6 ++++++ src/config.zig | 6 ++++++ src/input/Binding.zig | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/src/App.zig b/src/App.zig index 7563058b2..f2d18a7fd 100644 --- a/src/App.zig +++ b/src/App.zig @@ -135,7 +135,9 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void { } fn reloadConfig(self: *App, rt_app: *apprt.App) !void { + log.debug("reloading configuration", .{}); if (try rt_app.reloadConfig()) |new| { + log.debug("new configuration received, applying", .{}); try self.updateConfig(new); } } diff --git a/src/Surface.zig b/src/Surface.zig index b34eabaa2..6e002091b 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -852,6 +852,12 @@ pub fn keyCallback( .unbind => unreachable, .ignore => {}, + .reload_config => { + _ = self.app_mailbox.push(.{ + .reload_config = {}, + }, .{ .instant = {} }); + }, + .csi => |data| { _ = self.io_thread.mailbox.push(.{ .write_stable = "\x1B[", diff --git a/src/config.zig b/src/config.zig index 3789fe1a8..c30355f55 100644 --- a/src/config.zig +++ b/src/config.zig @@ -239,6 +239,12 @@ pub const Config = struct { const alloc = result._arena.?.allocator(); // Add our default keybindings + try result.keybind.set.put( + alloc, + .{ .key = .space, .mods = .{ .super = true, .alt = true, .ctrl = true } }, + .{ .reload_config = {} }, + ); + { // On macOS we default to super but Linux ctrl+shift since // ctrl+c is to kill the process. diff --git a/src/input/Binding.zig b/src/input/Binding.zig index cac34826c..746ccbff7 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -187,6 +187,12 @@ pub const Action = union(enum) { /// Focus on a split in a given direction. goto_split: SplitFocusDirection, + /// Reload the configuration. The exact meaning depends on the app runtime + /// in use but this usually involves re-reading the configuration file + /// and applying any changes. Note that not all changes can be applied at + /// runtime. + reload_config: void, + /// Close the current "surface", whether that is a window, tab, split, /// etc. This only closes ONE surface. close_surface: void,