mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-10 05:38:16 +00:00
apprt: action to change conditional state, implement for embedded
This commit is contained in:
@@ -193,6 +193,13 @@ pub const Action = union(Key) {
|
||||
/// such as OSC 10/11.
|
||||
color_change: ColorChange,
|
||||
|
||||
/// The state of conditionals in the configuration has changed, so
|
||||
/// the configuration should be reloaded. The apprt doesn't need
|
||||
/// to do a full physical reload; it should call the
|
||||
/// `changeConditionalState` function and then `updateConfig`
|
||||
/// on the app or surface.
|
||||
config_change_conditional_state,
|
||||
|
||||
/// Sync with: ghostty_action_tag_e
|
||||
pub const Key = enum(c_int) {
|
||||
new_window,
|
||||
@@ -228,6 +235,7 @@ pub const Action = union(Key) {
|
||||
secure_input,
|
||||
key_sequence,
|
||||
color_change,
|
||||
config_change_conditional_state,
|
||||
};
|
||||
|
||||
/// Sync with: ghostty_action_u
|
||||
|
||||
@@ -430,6 +430,28 @@ pub const App = struct {
|
||||
comptime action: apprt.Action.Key,
|
||||
value: apprt.Action.Value(action),
|
||||
) !void {
|
||||
// Special case certain actions before they are sent to the
|
||||
// embedded apprt.
|
||||
self.performPreAction(target, action, value);
|
||||
|
||||
log.debug("dispatching action target={s} action={} value={}", .{
|
||||
@tagName(target),
|
||||
action,
|
||||
value,
|
||||
});
|
||||
self.opts.action(
|
||||
self,
|
||||
target.cval(),
|
||||
@unionInit(apprt.Action, @tagName(action), value).cval(),
|
||||
);
|
||||
}
|
||||
|
||||
fn performPreAction(
|
||||
self: *App,
|
||||
target: apprt.Target,
|
||||
comptime action: apprt.Action.Key,
|
||||
value: apprt.Action.Value(action),
|
||||
) void {
|
||||
// Special case certain actions before they are sent to the embedder
|
||||
switch (action) {
|
||||
.set_title => switch (target) {
|
||||
@@ -443,19 +465,32 @@ pub const App = struct {
|
||||
},
|
||||
},
|
||||
|
||||
.config_change_conditional_state => switch (target) {
|
||||
.app => {},
|
||||
.surface => |surface| action: {
|
||||
// Build our new configuration. We can free the memory
|
||||
// immediately after because the surface will derive any
|
||||
// values it needs to.
|
||||
var new_config = self.config.changeConditionalState(
|
||||
surface.config_conditional_state,
|
||||
) catch |err| {
|
||||
// Not a big deal if we error... we just don't update
|
||||
// the config. We log the error and move on.
|
||||
log.warn("error changing config conditional state err={}", .{err});
|
||||
break :action;
|
||||
};
|
||||
defer new_config.deinit();
|
||||
|
||||
// Update our surface.
|
||||
surface.updateConfig(&new_config) catch |err| {
|
||||
log.warn("error updating surface config for state change err={}", .{err});
|
||||
break :action;
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
else => {},
|
||||
}
|
||||
|
||||
log.debug("dispatching action target={s} action={} value={}", .{
|
||||
@tagName(target),
|
||||
action,
|
||||
value,
|
||||
});
|
||||
self.opts.action(
|
||||
self,
|
||||
target.cval(),
|
||||
@unionInit(apprt.Action, @tagName(action), value).cval(),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -225,6 +225,7 @@ pub const App = struct {
|
||||
.renderer_health,
|
||||
.color_change,
|
||||
.pwd,
|
||||
.config_change_conditional_state,
|
||||
=> log.info("unimplemented action={}", .{action}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,6 +487,7 @@ pub fn performAction(
|
||||
.render_inspector,
|
||||
.renderer_health,
|
||||
.color_change,
|
||||
.config_change_conditional_state,
|
||||
=> log.warn("unimplemented action={}", .{action}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user