inspector: no longer holds surface pointer

This commit is contained in:
Mitchell Hashimoto
2026-01-29 20:43:58 -08:00
parent 3e825dd608
commit 32ac82c66f
4 changed files with 26 additions and 24 deletions

View File

@@ -803,7 +803,7 @@ pub fn deinit(self: *Surface) void {
self.io.deinit();
if (self.inspector) |v| {
v.deinit();
v.deinit(self.alloc);
self.alloc.destroy(v);
}
@@ -879,8 +879,10 @@ pub fn activateInspector(self: *Surface) !void {
// Setup the inspector
const ptr = try self.alloc.create(inspectorpkg.Inspector);
errdefer self.alloc.destroy(ptr);
ptr.* = try inspectorpkg.Inspector.init(self);
ptr.* = try inspectorpkg.Inspector.init(self.alloc);
errdefer ptr.deinit(self.alloc);
self.inspector = ptr;
errdefer self.inspector = null;
// Put the inspector onto the render state
{
@@ -912,7 +914,7 @@ pub fn deactivateInspector(self: *Surface) void {
self.queueIo(.{ .inspector = false }, .unlocked);
// Deinit the inspector
insp.deinit();
insp.deinit(self.alloc);
self.alloc.destroy(insp);
self.inspector = null;
}
@@ -2635,7 +2637,7 @@ pub fn keyCallback(
break :ev;
};
if (insp.recordKeyEvent(ev)) {
if (insp.recordKeyEvent(self.alloc, ev)) {
self.queueRender() catch {};
} else |err| {
log.warn("error adding key event to inspector err={}", .{err});

View File

@@ -1061,7 +1061,7 @@ pub const Inspector = struct {
render: {
const surface = &self.surface.core_surface;
const inspector = surface.inspector orelse break :render;
inspector.render();
inspector.render(surface);
}
// Render

View File

@@ -89,7 +89,7 @@ pub const InspectorWidget = extern struct {
const surface = priv.surface orelse return;
const core_surface = surface.core() orelse return;
const inspector = core_surface.inspector orelse return;
inspector.render();
inspector.render(core_surface);
}
//---------------------------------------------------------------

View File

@@ -19,9 +19,6 @@ const window_cell = "Cell";
const window_termio = "Terminal IO";
const window_imgui_demo = "Dear ImGui Demo";
/// The surface that we're inspecting.
surface: *Surface,
/// Mouse state that we track in addition to normal mouse states that
/// Ghostty always knows about.
mouse: widgets.surface.Mouse = .{},
@@ -121,23 +118,23 @@ pub fn setup() void {
}
}
pub fn init(surface: *Surface) !Inspector {
var gui: widgets.surface.Inspector = try .init(surface.alloc);
errdefer gui.deinit(surface.alloc);
return .{
.surface = surface,
.gui = gui,
};
pub fn init(alloc: Allocator) !Inspector {
var gui: widgets.surface.Inspector = try .init(alloc);
errdefer gui.deinit(alloc);
return .{ .gui = gui };
}
pub fn deinit(self: *Inspector) void {
self.gui.deinit(self.surface.alloc);
pub fn deinit(self: *Inspector, alloc: Allocator) void {
self.gui.deinit(alloc);
self.cell.deinit();
}
/// Record a keyboard event.
pub fn recordKeyEvent(self: *Inspector, ev: inspector.KeyEvent) !void {
pub fn recordKeyEvent(
self: *Inspector,
alloc: Allocator,
ev: inspector.KeyEvent,
) Allocator.Error!void {
const max_capacity = 50;
const events: *widgets.key.EventRing = &self.gui.key_stream.events;
@@ -145,11 +142,11 @@ pub fn recordKeyEvent(self: *Inspector, ev: inspector.KeyEvent) !void {
error.OutOfMemory => if (events.capacity() < max_capacity) {
// We're out of memory, but we can allocate to our capacity.
const new_capacity = @min(events.capacity() * 2, max_capacity);
try events.resize(self.surface.alloc, new_capacity);
try events.resize(alloc, new_capacity);
try events.append(ev);
} else {
var it = events.iterator(.forward);
if (it.next()) |old_ev| old_ev.deinit(self.surface.alloc);
if (it.next()) |old_ev| old_ev.deinit(alloc);
events.deleteOldest(1);
try events.append(ev);
},
@@ -177,9 +174,12 @@ pub fn recordPtyRead(
}
/// Render the frame.
pub fn render(self: *Inspector) void {
pub fn render(
self: *Inspector,
surface: *Surface,
) void {
self.gui.draw(
self.surface,
surface,
self.mouse,
);
}