mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt: add config_change
action
This commit is contained in:
@ -532,6 +532,11 @@ typedef struct {
|
|||||||
uint8_t b;
|
uint8_t b;
|
||||||
} ghostty_action_color_change_s;
|
} ghostty_action_color_change_s;
|
||||||
|
|
||||||
|
// apprt.action.ConfigChange
|
||||||
|
typedef struct {
|
||||||
|
ghostty_config_t config;
|
||||||
|
} ghostty_action_config_change_s;
|
||||||
|
|
||||||
// apprt.Action.Key
|
// apprt.Action.Key
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GHOSTTY_ACTION_NEW_WINDOW,
|
GHOSTTY_ACTION_NEW_WINDOW,
|
||||||
@ -568,6 +573,7 @@ typedef enum {
|
|||||||
GHOSTTY_ACTION_KEY_SEQUENCE,
|
GHOSTTY_ACTION_KEY_SEQUENCE,
|
||||||
GHOSTTY_ACTION_COLOR_CHANGE,
|
GHOSTTY_ACTION_COLOR_CHANGE,
|
||||||
GHOSTTY_ACTION_CONFIG_CHANGE_CONDITIONAL_STATE,
|
GHOSTTY_ACTION_CONFIG_CHANGE_CONDITIONAL_STATE,
|
||||||
|
GHOSTTY_ACTION_CONFIG_CHANGE,
|
||||||
} ghostty_action_tag_e;
|
} ghostty_action_tag_e;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@ -592,6 +598,7 @@ typedef union {
|
|||||||
ghostty_action_secure_input_e secure_input;
|
ghostty_action_secure_input_e secure_input;
|
||||||
ghostty_action_key_sequence_s key_sequence;
|
ghostty_action_key_sequence_s key_sequence;
|
||||||
ghostty_action_color_change_s color_change;
|
ghostty_action_color_change_s color_change;
|
||||||
|
ghostty_action_config_change_s config_change;
|
||||||
} ghostty_action_u;
|
} ghostty_action_u;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
11
src/App.zig
11
src/App.zig
@ -147,11 +147,18 @@ pub fn tick(self: *App, rt_app: *apprt.App) !bool {
|
|||||||
/// Update the configuration associated with the app. This can only be
|
/// Update the configuration associated with the app. This can only be
|
||||||
/// called from the main thread. The caller owns the config memory. The
|
/// called from the main thread. The caller owns the config memory. The
|
||||||
/// memory can be freed immediately when this returns.
|
/// memory can be freed immediately when this returns.
|
||||||
pub fn updateConfig(self: *App, config: *const Config) !void {
|
pub fn updateConfig(self: *App, rt_app: *apprt.App, config: *const Config) !void {
|
||||||
// Go through and update all of the surface configurations.
|
// Go through and update all of the surface configurations.
|
||||||
for (self.surfaces.items) |surface| {
|
for (self.surfaces.items) |surface| {
|
||||||
try surface.core_surface.handleMessage(.{ .change_config = config });
|
try surface.core_surface.handleMessage(.{ .change_config = config });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify the apprt that the app has changed configuration.
|
||||||
|
try rt_app.performAction(
|
||||||
|
.app,
|
||||||
|
.config_change,
|
||||||
|
.{ .config = config },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an initialized surface. This is really only for the runtime
|
/// Add an initialized surface. This is really only for the runtime
|
||||||
@ -257,7 +264,7 @@ pub fn reloadConfig(self: *App, rt_app: *apprt.App) !void {
|
|||||||
log.debug("reloading configuration", .{});
|
log.debug("reloading configuration", .{});
|
||||||
if (try rt_app.reloadConfig()) |new| {
|
if (try rt_app.reloadConfig()) |new| {
|
||||||
log.debug("new configuration received, applying", .{});
|
log.debug("new configuration received, applying", .{});
|
||||||
try self.updateConfig(new);
|
try self.updateConfig(rt_app, new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,6 +1127,13 @@ pub fn updateConfig(
|
|||||||
self.queueRender() catch |err| {
|
self.queueRender() catch |err| {
|
||||||
log.warn("failed to notify renderer of config change err={}", .{err});
|
log.warn("failed to notify renderer of config change err={}", .{err});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Notify the window
|
||||||
|
try self.rt_app.performAction(
|
||||||
|
.{ .surface = self },
|
||||||
|
.config_change,
|
||||||
|
.{ .config = config },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the terminal has a selection.
|
/// Returns true if the terminal has a selection.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const apprt = @import("../apprt.zig");
|
const apprt = @import("../apprt.zig");
|
||||||
|
const configpkg = @import("../config.zig");
|
||||||
const input = @import("../input.zig");
|
const input = @import("../input.zig");
|
||||||
const renderer = @import("../renderer.zig");
|
const renderer = @import("../renderer.zig");
|
||||||
const terminal = @import("../terminal/main.zig");
|
const terminal = @import("../terminal/main.zig");
|
||||||
@ -200,6 +201,20 @@ pub const Action = union(Key) {
|
|||||||
/// on the app or surface.
|
/// on the app or surface.
|
||||||
config_change_conditional_state,
|
config_change_conditional_state,
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
///
|
||||||
|
/// This should be used by apprts to update any internal state that
|
||||||
|
/// depends on configuration for the given target (i.e. headerbar colors).
|
||||||
|
/// The apprt should copy any data it needs since the memory lifetime
|
||||||
|
/// is only valid for the duration of the action.
|
||||||
|
///
|
||||||
|
/// This allows an apprt to have config-dependent state reactively
|
||||||
|
/// change without having to store the entire configuration or poll
|
||||||
|
/// for changes.
|
||||||
|
config_change: ConfigChange,
|
||||||
|
|
||||||
/// Sync with: ghostty_action_tag_e
|
/// Sync with: ghostty_action_tag_e
|
||||||
pub const Key = enum(c_int) {
|
pub const Key = enum(c_int) {
|
||||||
new_window,
|
new_window,
|
||||||
@ -236,6 +251,7 @@ pub const Action = union(Key) {
|
|||||||
key_sequence,
|
key_sequence,
|
||||||
color_change,
|
color_change,
|
||||||
config_change_conditional_state,
|
config_change_conditional_state,
|
||||||
|
config_change,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Sync with: ghostty_action_u
|
/// Sync with: ghostty_action_u
|
||||||
@ -497,3 +513,18 @@ pub const ColorKind = enum(c_int) {
|
|||||||
// 0+ values indicate a palette index
|
// 0+ values indicate a palette index
|
||||||
_,
|
_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const ConfigChange = struct {
|
||||||
|
config: *const configpkg.Config,
|
||||||
|
|
||||||
|
// Sync with: ghostty_action_config_change_s
|
||||||
|
pub const C = extern struct {
|
||||||
|
config: *const configpkg.Config,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn cval(self: ConfigChange) C {
|
||||||
|
return .{
|
||||||
|
.config = self.config,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -226,6 +226,7 @@ pub const App = struct {
|
|||||||
.color_change,
|
.color_change,
|
||||||
.pwd,
|
.pwd,
|
||||||
.config_change_conditional_state,
|
.config_change_conditional_state,
|
||||||
|
.config_change,
|
||||||
=> log.info("unimplemented action={}", .{action}),
|
=> log.info("unimplemented action={}", .{action}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,6 +488,7 @@ pub fn performAction(
|
|||||||
.render_inspector,
|
.render_inspector,
|
||||||
.renderer_health,
|
.renderer_health,
|
||||||
.color_change,
|
.color_change,
|
||||||
|
.config_change,
|
||||||
=> log.warn("unimplemented action={}", .{action}),
|
=> log.warn("unimplemented action={}", .{action}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user