apprt/embedded: supporting setting working directory in config

This commit is contained in:
Mitchell Hashimoto
2023-10-03 17:34:44 -07:00
parent a8d2a30dfd
commit 140afb395f
2 changed files with 9 additions and 0 deletions

View File

@ -309,6 +309,7 @@ typedef struct {
void *nsview;
double scale_factor;
uint16_t font_size;
const char *working_directory;
} ghostty_surface_config_s;
typedef void (*ghostty_runtime_wakeup_cb)(void *);

View File

@ -208,6 +208,9 @@ pub const Surface = struct {
/// The font size to inherit. If 0, default font size will be used.
font_size: u16 = 0,
/// The working directory to load into.
working_directory: [*:0]const u8 = "",
};
pub fn init(self: *Surface, app: *App, opts: Options) !void {
@ -236,6 +239,11 @@ pub const Surface = struct {
var config = try apprt.surface.newConfig(app.core_app, app.config);
defer config.deinit();
// If we have a working directory from the options then we set it.
// TODO: validate the working directory
const wd = std.mem.sliceTo(opts.working_directory, 0);
if (wd.len > 0) config.@"working-directory" = wd;
// Initialize our surface right away. We're given a view that is
// ready to use.
try self.core_surface.init(