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

@@ -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();