From 3fc33089f30714b51eb717ae38b75d93a2c42f61 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 14 Aug 2025 08:35:57 -0700 Subject: [PATCH] apprt/gtk-ng: clean up a bunch of unused window stuff --- src/apprt/gtk-ng/class/inspector_widget.zig | 16 ++---- src/apprt/gtk-ng/class/inspector_window.zig | 60 ++++++-------------- src/apprt/gtk-ng/class/surface.zig | 8 ++- src/apprt/gtk-ng/ui/1.5/inspector-window.blp | 1 - 4 files changed, 25 insertions(+), 60 deletions(-) diff --git a/src/apprt/gtk-ng/class/inspector_widget.zig b/src/apprt/gtk-ng/class/inspector_widget.zig index 5032dd168..aae8fd4ac 100644 --- a/src/apprt/gtk-ng/class/inspector_widget.zig +++ b/src/apprt/gtk-ng/class/inspector_widget.zig @@ -82,21 +82,12 @@ pub const InspectorWidget = extern struct { //--------------------------------------------------------------- // Public methods - pub fn new(surface: *Surface) *Self { - return gobject.ext.newInstance(Self, .{ - .surface = surface, - }); - } - /// Queue a render of the Dear ImGui widget. pub fn queueRender(self: *Self) void { const priv = self.private(); priv.imgui_widget.queueRender(); } - //--------------------------------------------------------------- - // Private Methods - //--------------------------------------------------------------- // Properties @@ -178,9 +169,10 @@ pub const InspectorWidget = extern struct { // pointer values for comparison, but the objects themselves are unsafe. if (@intFromPtr(priv.surface) != @intFromPtr(surface)) return; - // Note: we very explicitly DO NOT want to call setSurface here - // because we can't safely use `surface` so we want to ensure we - // manually clear our ref and notify. + // According to weak notify docs, "surface" is in the "dispose" state. + // Our surface doesn't clear the core surface until the "finalize" + // state so we should be able to safely access it here. We need to + // be really careful though. const old = priv.surface orelse return; const core_surface = old.core() orelse return; core_surface.deactivateInspector(); diff --git a/src/apprt/gtk-ng/class/inspector_window.zig b/src/apprt/gtk-ng/class/inspector_window.zig index 7f5c8fe10..c75c6fecb 100644 --- a/src/apprt/gtk-ng/class/inspector_window.zig +++ b/src/apprt/gtk-ng/class/inspector_window.zig @@ -39,12 +39,10 @@ pub const InspectorWindow = extern struct { Self, ?*Surface, .{ - .accessor = gobject.ext.typedAccessor(Self, ?*Surface, .{ - .getter = getSurface, - .getter_transfer = .full, - .setter = setSurface, - .setter_transfer = .none, - }), + .accessor = .{ + .getter = getSurfaceValue, + .setter = setSurfaceValue, + }, }, ); }; @@ -132,48 +130,27 @@ pub const InspectorWindow = extern struct { priv.inspector_widget.queueRender(); } - /// The surface we are connected to is going away, shut ourselves down. - pub fn shutdown(self: *Self) void { - const priv = self.private(); - priv.surface.set(null); - self.as(gobject.Object).notifyByPspec(properties.surface.impl.param_spec); - self.as(gtk.Window).close(); - } - - //--------------------------------------------------------------- - // Private Methods - - fn isFullscreen(self: *Self) bool { - return self.as(gtk.Window).isFullscreen() != 0; - } - - fn isMaximized(self: *Self) bool { - return self.as(gtk.Window).isMaximized() != 0; - } - //--------------------------------------------------------------- // Properties - fn getSurface(self: *Self) ?*Surface { - const priv = self.private(); - return priv.surface.get(); - } - fn setSurface(self: *Self, newvalue: ?*Surface) void { const priv = self.private(); priv.surface.set(newvalue); } - //--------------------------------------------------------------- - // Signal Handlers + fn getSurfaceValue(self: *Self, value: *gobject.Value) void { + // Important: get() refs, so we take to not increase ref twice + gobject.ext.Value.take( + value, + self.private().surface.get(), + ); + } - /// The user has clicked on the close button. - fn closeRequest(_: *gtk.Window, self: *Self) callconv(.c) c_int { - const priv = self.private(); - priv.surface.set(null); - self.as(gobject.Object).notifyByPspec(properties.surface.impl.param_spec); - self.as(gtk.Window).destroy(); - return @intFromBool(false); + fn setSurfaceValue(self: *Self, value: *const gobject.Value) void { + self.setSurface(gobject.ext.Value.get( + value, + ?*Surface, + )); } const C = Common(Self, Private); @@ -203,17 +180,12 @@ pub const InspectorWindow = extern struct { // Template Bindings class.bindTemplateChildPrivate("inspector_widget", .{}); - // Template Callbacks - class.bindTemplateCallback("close_request", &closeRequest); - // Properties gobject.ext.registerProperties(class, &.{ properties.surface.impl, properties.debug.impl, }); - // Signals - // Virtual methods gobject.Object.virtual_methods.dispose.implement(class, &dispose); } diff --git a/src/apprt/gtk-ng/class/surface.zig b/src/apprt/gtk-ng/class/surface.zig index 65b128bdf..5a3107000 100644 --- a/src/apprt/gtk-ng/class/surface.zig +++ b/src/apprt/gtk-ng/class/surface.zig @@ -582,7 +582,6 @@ pub const Surface = extern struct { const priv = self.private(); if (priv.inspector.get()) |inspector| { defer inspector.unref(); - inspector.shutdown(); priv.inspector.set(null); return true; } @@ -609,7 +608,6 @@ pub const Surface = extern struct { const priv = self.private(); if (priv.inspector.get()) |inspector| { defer inspector.unref(); - inspector.shutdown(); priv.inspector.set(null); } return true; @@ -622,6 +620,7 @@ pub const Surface = extern struct { .hide => return self.hideInspector(), } } + /// Redraw our inspector, if there is one associated with this surface. pub fn redrawInspector(self: *Self) void { const priv = self.private(); @@ -1359,7 +1358,6 @@ pub const Surface = extern struct { if (priv.inspector.get()) |inspector| { defer inspector.unref(); - inspector.shutdown(); } gtk.Widget.disposeTemplate( @@ -1381,6 +1379,10 @@ pub const Surface = extern struct { // searching for this surface. Application.default().core().deleteSurface(self.rt()); + // NOTE: We must deinit the surface in the finalize call and NOT + // the dispose call because the inspector widget relies on this + // behavior with a weakRef to properly deactivate. + // Deinit the surface v.deinit(); const alloc = Application.default().allocator(); diff --git a/src/apprt/gtk-ng/ui/1.5/inspector-window.blp b/src/apprt/gtk-ng/ui/1.5/inspector-window.blp index a67e26622..2457450ee 100644 --- a/src/apprt/gtk-ng/ui/1.5/inspector-window.blp +++ b/src/apprt/gtk-ng/ui/1.5/inspector-window.blp @@ -6,7 +6,6 @@ template $GhosttyInspectorWindow: Adw.ApplicationWindow { icon-name: "com.mitchellh.ghostty"; default-width: 1000; default-height: 600; - close-request => $close_request(); styles [ "inspector",