From 05cd77e7cf78f179b991a14b7b975d5f2b88e86e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 6 Nov 2022 16:06:34 -0800 Subject: [PATCH] DevMode only renders on first window --- src/Window.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index 2dad88b67..f9ac53d54 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -315,6 +315,11 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window { var io_thread = try termio.Thread.init(alloc, &self.io); errdefer io_thread.deinit(); + // True if this window is hosting devmode. We only host devmode on + // the first window since imgui is not threadsafe. We need to do some + // work to make DevMode work with multiple threads. + const host_devmode = DevMode.enabled and DevMode.instance.window == null; + self.* = .{ .alloc = alloc, .app = app, @@ -332,7 +337,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window { .visible = true, }, .terminal = &self.io.terminal, - .devmode = if (!DevMode.enabled) null else &DevMode.instance, + .devmode = if (!host_devmode) null else &DevMode.instance, }, .renderer_thr = undefined, .mouse = .{}, @@ -370,7 +375,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window { // Load imgui. This must be done LAST because it has to be done after // all our GLFW setup is complete. - if (DevMode.enabled) { + if (DevMode.enabled and DevMode.instance.window == null) { const dev_io = try imgui.IO.get(); dev_io.cval().IniFilename = "ghostty_dev_mode.ini"; @@ -385,7 +390,7 @@ pub fn create(alloc: Allocator, app: *App, config: *const Config) !*Window { const style = try imgui.Style.get(); style.colorsDark(); - // Add our window to the instance + // Add our window to the instance if it isn't set. DevMode.instance.window = self; } @@ -425,7 +430,7 @@ pub fn destroy(self: *Window) void { self.renderer.deinit(); } - if (DevMode.enabled) { + if (DevMode.enabled and DevMode.instance.window == self) { // Clear the window DevMode.instance.window = null;