apprt/gtk-ng: far less control inspector complexity

pull/8212/head
Mitchell Hashimoto 2025-08-14 08:57:06 -07:00
parent 3fc33089f3
commit 6280bd7a42
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
4 changed files with 31 additions and 51 deletions

View File

@ -8,7 +8,6 @@ const gresource = @import("../build/gresource.zig");
const Inspector = @import("../../../inspector/Inspector.zig");
const Common = @import("../class.zig").Common;
const WeakRef = @import("../weak_ref.zig").WeakRef;
const Surface = @import("surface.zig").Surface;
const ImguiWidget = @import("imgui_widget.zig").ImguiWidget;

View File

@ -111,12 +111,9 @@ pub const InspectorWindow = extern struct {
// Public methods
pub fn new(surface: *Surface) *Self {
const self = gobject.ext.newInstance(Self, .{
return gobject.ext.newInstance(Self, .{
.surface = surface,
});
// Bump the ref so that we aren't immediately closed.
return self.ref();
}
/// Present the window.

View File

@ -473,7 +473,7 @@ pub const Surface = extern struct {
bell_ringing: bool = false,
/// A weak reference to an inspector window.
inspector: WeakRef(InspectorWindow) = .empty,
inspector: ?*InspectorWindow = null,
// Template binds
child_exited_overlay: *ChildExited,
@ -578,55 +578,34 @@ pub const Surface = extern struct {
return self.as(gtk.Widget).activateAction("win.toggle-command-palette", null) != 0;
}
pub fn toggleInspector(self: *Self) bool {
pub fn controlInspector(
self: *Self,
value: apprt.Action.Value(.inspector),
) bool {
// Let's see if we have an inspector already.
const priv = self.private();
if (priv.inspector.get()) |inspector| {
defer inspector.unref();
priv.inspector.set(null);
return true;
}
const inspector = InspectorWindow.new(self);
defer inspector.unref();
priv.inspector.set(inspector);
inspector.present();
return true;
}
if (priv.inspector) |inspector| switch (value) {
.show => {},
// Our weak ref will set our private value to null
.toggle, .hide => inspector.as(gtk.Window).destroy(),
} else switch (value) {
.toggle, .show => {
const inspector = InspectorWindow.new(self);
inspector.present();
inspector.as(gobject.Object).weakRef(inspectorWeakNotify, self);
priv.inspector = inspector;
},
pub fn showInspector(self: *Self) bool {
const priv = self.private();
const inspector = priv.inspector.get() orelse inspector: {
const inspector = InspectorWindow.new(self);
priv.inspector.set(inspector);
break :inspector inspector;
};
defer inspector.unref();
inspector.present();
return true;
}
pub fn hideInspector(self: *Self) bool {
const priv = self.private();
if (priv.inspector.get()) |inspector| {
defer inspector.unref();
priv.inspector.set(null);
.hide => {},
}
return true;
}
pub fn controlInspector(self: *Self, value: apprt.Action.Value(.inspector)) bool {
switch (value) {
.toggle => return self.toggleInspector(),
.show => return self.showInspector(),
.hide => return self.hideInspector(),
}
return true;
}
/// Redraw our inspector, if there is one associated with this surface.
pub fn redrawInspector(self: *Self) void {
const priv = self.private();
const inspector = priv.inspector.get() orelse return;
defer inspector.unref();
inspector.queueRender();
if (priv.inspector) |v| v.queueRender();
}
pub fn showOnScreenKeyboard(self: *Self, event: ?*gdk.Event) bool {
@ -1356,10 +1335,6 @@ pub const Surface = extern struct {
priv.progress_bar_timer = null;
}
if (priv.inspector.get()) |inspector| {
defer inspector.unref();
}
gtk.Widget.disposeTemplate(
self.as(gtk.Widget),
getGObjectType(),
@ -1787,6 +1762,15 @@ pub const Surface = extern struct {
self.grabFocus();
}
fn inspectorWeakNotify(
ud: ?*anyopaque,
_: *gobject.Object,
) callconv(.c) void {
const self: *Self = @ptrCast(@alignCast(ud orelse return));
const priv = self.private();
priv.inspector = null;
}
fn dtDrop(
_: *gtk.DropTarget,
value: *gobject.Value,

View File

@ -1825,7 +1825,7 @@ pub const Window = extern struct {
/// Toggle the Ghostty inspector for the active surface.
fn toggleInspector(self: *Self) void {
const surface = self.getActiveSurface() orelse return;
_ = surface.toggleInspector();
_ = surface.controlInspector(.toggle);
}
/// React to a GTK action requesting that the Ghostty inspector be toggled.