From 0fca74c0897ccd58db369cb030222631c81c8324 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 May 2023 19:18:55 -0700 Subject: [PATCH] apprt/glfw: inherit working dir --- src/apprt/glfw.zig | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index d8da82640..b65573a03 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -346,10 +346,25 @@ pub const Surface = struct { try app.app.addSurface(self); errdefer app.app.deleteSurface(self); + // Our parent pwd will be tracked here + const alloc = app.app.alloc; + var parent_pwd: ?[]const u8 = null; + defer if (parent_pwd) |v| alloc.free(v); + + // Shallow copy the config so that we can modify it. + var config = app.config; + + // Get our previously focused surface + const parent = app.app.focusedSurface(); + if (parent) |p| { + parent_pwd = try p.pwd(alloc); + if (parent_pwd) |v| config.@"working-directory" = v; + } + // Initialize our surface now that we have the stable pointer. try self.core_surface.init( - app.app.alloc, - &app.config, + alloc, + &config, .{ .rt_app = app, .mailbox = &app.app.mailbox }, self, );