apprt: switch to reload_config action that calls update_config API

This commit is contained in:
Mitchell Hashimoto
2024-11-22 10:43:51 -08:00
parent 6371af0d8e
commit a191f3c396
6 changed files with 132 additions and 59 deletions

View File

@@ -201,6 +201,15 @@ pub const Action = union(Key) {
/// on the app or surface.
config_change_conditional_state,
/// A request to reload the configuration. The reload request can be
/// from a user or for some internal reason. The reload request may
/// request it is a soft reload or a full reload. See the struct for
/// more documentation.
///
/// The configuration should be passed to updateConfig either at the
/// app or surface level depending on the target.
reload_config: ReloadConfig,
/// The configuration has changed. The value is a pointer to the new
/// configuration. The pointer is only valid for the duration of the
/// action and should not be stored.
@@ -251,6 +260,7 @@ pub const Action = union(Key) {
key_sequence,
color_change,
config_change_conditional_state,
reload_config,
config_change,
};
@@ -514,6 +524,13 @@ pub const ColorKind = enum(c_int) {
_,
};
pub const ReloadConfig = extern struct {
/// A soft reload means that the configuration doesn't need to be
/// read off disk, but libghostty needs the full config again so call
/// updateConfig with it.
soft: bool = false,
};
pub const ConfigChange = struct {
config: *const configpkg.Config,

View File

@@ -47,11 +47,6 @@ pub const App = struct {
/// Callback called to handle an action.
action: *const fn (*App, apprt.Target.C, apprt.Action.C) callconv(.C) void,
/// Reload the configuration and return the new configuration.
/// The old configuration can be freed immediately when this is
/// called.
reload_config: *const fn (AppUD) callconv(.C) ?*const Config,
/// Read the clipboard value. The return value must be preserved
/// by the host until the next call. If there is no valid clipboard
/// value then this should return null.
@@ -375,16 +370,6 @@ pub const App = struct {
}
}
pub fn reloadConfig(self: *App) !?*const Config {
// Reload
if (self.opts.reload_config(self.opts.userdata)) |new| {
self.config = new;
return self.config;
}
return null;
}
pub fn wakeup(self: App) void {
self.opts.wakeup(self.opts.userdata);
}
@@ -1374,10 +1359,14 @@ pub const CAPI = struct {
};
}
/// Reload the configuration.
export fn ghostty_app_reload_config(v: *App) void {
_ = v.core_app.reloadConfig(v) catch |err| {
log.err("error reloading config err={}", .{err});
/// Update the configuration to the provided config. This will propagate
/// to all surfaces as well.
export fn ghostty_app_update_config(
v: *App,
config: *const Config,
) void {
v.core_app.updateConfig(v, config) catch |err| {
log.err("error updating config err={}", .{err});
return;
};
}
@@ -1434,6 +1423,17 @@ pub const CAPI = struct {
return surface.newSurfaceOptions();
}
/// Update the configuration to the provided config for only this surface.
export fn ghostty_surface_update_config(
surface: *Surface,
config: *const Config,
) void {
surface.core_surface.updateConfig(config) catch |err| {
log.err("error updating config err={}", .{err});
return;
};
}
/// Returns true if the surface needs to confirm quitting.
export fn ghostty_surface_needs_confirm_quit(surface: *Surface) bool {
return surface.core_surface.needsConfirmQuit();