apprt/gtk-ng: clean up a bunch of unused window stuff

This commit is contained in:
Mitchell Hashimoto
2025-08-14 08:35:57 -07:00
parent 48a65b05d0
commit 3fc33089f3
4 changed files with 25 additions and 60 deletions

View File

@@ -82,21 +82,12 @@ pub const InspectorWidget = extern struct {
//--------------------------------------------------------------- //---------------------------------------------------------------
// Public methods // Public methods
pub fn new(surface: *Surface) *Self {
return gobject.ext.newInstance(Self, .{
.surface = surface,
});
}
/// Queue a render of the Dear ImGui widget. /// Queue a render of the Dear ImGui widget.
pub fn queueRender(self: *Self) void { pub fn queueRender(self: *Self) void {
const priv = self.private(); const priv = self.private();
priv.imgui_widget.queueRender(); priv.imgui_widget.queueRender();
} }
//---------------------------------------------------------------
// Private Methods
//--------------------------------------------------------------- //---------------------------------------------------------------
// Properties // Properties
@@ -178,9 +169,10 @@ pub const InspectorWidget = extern struct {
// pointer values for comparison, but the objects themselves are unsafe. // pointer values for comparison, but the objects themselves are unsafe.
if (@intFromPtr(priv.surface) != @intFromPtr(surface)) return; if (@intFromPtr(priv.surface) != @intFromPtr(surface)) return;
// Note: we very explicitly DO NOT want to call setSurface here // According to weak notify docs, "surface" is in the "dispose" state.
// because we can't safely use `surface` so we want to ensure we // Our surface doesn't clear the core surface until the "finalize"
// manually clear our ref and notify. // 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 old = priv.surface orelse return;
const core_surface = old.core() orelse return; const core_surface = old.core() orelse return;
core_surface.deactivateInspector(); core_surface.deactivateInspector();

View File

@@ -39,12 +39,10 @@ pub const InspectorWindow = extern struct {
Self, Self,
?*Surface, ?*Surface,
.{ .{
.accessor = gobject.ext.typedAccessor(Self, ?*Surface, .{ .accessor = .{
.getter = getSurface, .getter = getSurfaceValue,
.getter_transfer = .full, .setter = setSurfaceValue,
.setter = setSurface, },
.setter_transfer = .none,
}),
}, },
); );
}; };
@@ -132,48 +130,27 @@ pub const InspectorWindow = extern struct {
priv.inspector_widget.queueRender(); 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 // Properties
fn getSurface(self: *Self) ?*Surface {
const priv = self.private();
return priv.surface.get();
}
fn setSurface(self: *Self, newvalue: ?*Surface) void { fn setSurface(self: *Self, newvalue: ?*Surface) void {
const priv = self.private(); const priv = self.private();
priv.surface.set(newvalue); priv.surface.set(newvalue);
} }
//--------------------------------------------------------------- fn getSurfaceValue(self: *Self, value: *gobject.Value) void {
// Signal Handlers // 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 setSurfaceValue(self: *Self, value: *const gobject.Value) void {
fn closeRequest(_: *gtk.Window, self: *Self) callconv(.c) c_int { self.setSurface(gobject.ext.Value.get(
const priv = self.private(); value,
priv.surface.set(null); ?*Surface,
self.as(gobject.Object).notifyByPspec(properties.surface.impl.param_spec); ));
self.as(gtk.Window).destroy();
return @intFromBool(false);
} }
const C = Common(Self, Private); const C = Common(Self, Private);
@@ -203,17 +180,12 @@ pub const InspectorWindow = extern struct {
// Template Bindings // Template Bindings
class.bindTemplateChildPrivate("inspector_widget", .{}); class.bindTemplateChildPrivate("inspector_widget", .{});
// Template Callbacks
class.bindTemplateCallback("close_request", &closeRequest);
// Properties // Properties
gobject.ext.registerProperties(class, &.{ gobject.ext.registerProperties(class, &.{
properties.surface.impl, properties.surface.impl,
properties.debug.impl, properties.debug.impl,
}); });
// Signals
// Virtual methods // Virtual methods
gobject.Object.virtual_methods.dispose.implement(class, &dispose); gobject.Object.virtual_methods.dispose.implement(class, &dispose);
} }

View File

@@ -582,7 +582,6 @@ pub const Surface = extern struct {
const priv = self.private(); const priv = self.private();
if (priv.inspector.get()) |inspector| { if (priv.inspector.get()) |inspector| {
defer inspector.unref(); defer inspector.unref();
inspector.shutdown();
priv.inspector.set(null); priv.inspector.set(null);
return true; return true;
} }
@@ -609,7 +608,6 @@ pub const Surface = extern struct {
const priv = self.private(); const priv = self.private();
if (priv.inspector.get()) |inspector| { if (priv.inspector.get()) |inspector| {
defer inspector.unref(); defer inspector.unref();
inspector.shutdown();
priv.inspector.set(null); priv.inspector.set(null);
} }
return true; return true;
@@ -622,6 +620,7 @@ pub const Surface = extern struct {
.hide => return self.hideInspector(), .hide => return self.hideInspector(),
} }
} }
/// Redraw our inspector, if there is one associated with this surface. /// Redraw our inspector, if there is one associated with this surface.
pub fn redrawInspector(self: *Self) void { pub fn redrawInspector(self: *Self) void {
const priv = self.private(); const priv = self.private();
@@ -1359,7 +1358,6 @@ pub const Surface = extern struct {
if (priv.inspector.get()) |inspector| { if (priv.inspector.get()) |inspector| {
defer inspector.unref(); defer inspector.unref();
inspector.shutdown();
} }
gtk.Widget.disposeTemplate( gtk.Widget.disposeTemplate(
@@ -1381,6 +1379,10 @@ pub const Surface = extern struct {
// searching for this surface. // searching for this surface.
Application.default().core().deleteSurface(self.rt()); 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 // Deinit the surface
v.deinit(); v.deinit();
const alloc = Application.default().allocator(); const alloc = Application.default().allocator();

View File

@@ -6,7 +6,6 @@ template $GhosttyInspectorWindow: Adw.ApplicationWindow {
icon-name: "com.mitchellh.ghostty"; icon-name: "com.mitchellh.ghostty";
default-width: 1000; default-width: 1000;
default-height: 600; default-height: 600;
close-request => $close_request();
styles [ styles [
"inspector", "inspector",