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
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();

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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",