diff --git a/src/App.zig b/src/App.zig index e9358b3a1..7563058b2 100644 --- a/src/App.zig +++ b/src/App.zig @@ -18,7 +18,6 @@ const renderer = @import("renderer.zig"); const font = @import("font/main.zig"); const macos = @import("macos"); const objc = @import("objc"); -const DevMode = @import("DevMode.zig"); const log = std.log.scoped(.app); @@ -43,9 +42,6 @@ quit: bool, pub fn create( alloc: Allocator, ) !*App { - // If we have DevMode on, store the config so we can show it - //if (DevMode.enabled) DevMode.instance.config = config; - var app = try alloc.create(App); errdefer alloc.destroy(app); app.* = .{ @@ -93,17 +89,12 @@ pub fn tick(self: *App, rt_app: *apprt.App) !bool { } /// Update the configuration associated with the app. This can only be -/// called from the main thread. -/// -/// The caller owns the config memory. The prior config must not be freed -/// until this function returns successfully. +/// called from the main thread. The caller owns the config memory. The +/// memory can be freed immediately when this returns. pub fn updateConfig(self: *App, config: *const Config) !void { - // Update our config - self.config = config; - // Go through and update all of the surface configurations. for (self.surfaces.items) |surface| { - try surface.handleMessage(.{ .change_config = config }); + try surface.core_surface.handleMessage(.{ .change_config = config }); } } @@ -144,9 +135,9 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void { } fn reloadConfig(self: *App, rt_app: *apprt.App) !void { - _ = rt_app; - _ = self; - //try rt_app.reloadConfig(); + if (try rt_app.reloadConfig()) |new| { + try self.updateConfig(new); + } } fn closeSurface(self: *App, rt_app: *apprt.App, surface: *Surface) !void { diff --git a/src/DevMode.zig b/src/DevMode.zig index bd28366ca..29288046a 100644 --- a/src/DevMode.zig +++ b/src/DevMode.zig @@ -27,7 +27,7 @@ pub var instance: DevMode = .{}; visible: bool = false, /// Our app config -config: ?*const Config = null, +config: ?Config = null, /// The surface we're tracking. surface: ?*Surface = null, diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index c86031602..dfe758bf9 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -20,6 +20,7 @@ const apprt = @import("../apprt.zig"); const CoreApp = @import("../App.zig"); const CoreSurface = @import("../Surface.zig"); const Config = @import("../config.zig").Config; +const DevMode = @import("../DevMode.zig"); // Get native API access on certain platforms so we can do more customization. const glfwNative = glfw.Native(.{ @@ -59,6 +60,11 @@ pub const App = struct { var config = try Config.load(core_app.alloc); errdefer config.deinit(); + // If we have DevMode on, store the config so we can show it. This + // is messy because we're copying a thing here. We should clean this + // up when we take a pass at cleaning up the dev mode. + if (DevMode.enabled) DevMode.instance.config = config; + return .{ .app = core_app, .config = config, @@ -97,6 +103,23 @@ pub const App = struct { glfw.postEmptyEvent(); } + /// Reload the configuration. This should return the new configuration. + /// The old value can be freed immediately at this point assuming a + /// successful return. + /// + /// The returned pointer value is only valid for a stable self pointer. + pub fn reloadConfig(self: *App) !?*const Config { + // Load our configuration + var config = try Config.load(self.app.alloc); + errdefer config.deinit(); + + // Update the existing config, be sure to clean up the old one. + self.config.deinit(); + self.config = config; + + return &self.config; + } + /// Create a new window for the app. pub fn newWindow(self: *App, parent_: ?*CoreSurface) !void { _ = try self.newSurface(parent_); diff --git a/src/apprt/gtk.zig b/src/apprt/gtk.zig index c6556e49d..5d6937aa7 100644 --- a/src/apprt/gtk.zig +++ b/src/apprt/gtk.zig @@ -137,6 +137,23 @@ pub const App = struct { glfw.terminate(); } + /// Reload the configuration. This should return the new configuration. + /// The old value can be freed immediately at this point assuming a + /// successful return. + /// + /// The returned pointer value is only valid for a stable self pointer. + pub fn reloadConfig(self: *App) !?*const Config { + // Load our configuration + var config = try Config.load(self.core_app.alloc); + errdefer config.deinit(); + + // Update the existing config, be sure to clean up the old one. + self.config.deinit(); + self.config = config; + + return &self.config; + } + pub fn wakeup(self: App) void { _ = self; c.g_main_context_wakeup(null);