apprt/gtk-ng: close inspector window when widget loses surface

pull/8212/head
Mitchell Hashimoto 2025-08-14 09:42:21 -07:00
parent 7548dcfe63
commit 68f337e398
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 24 additions and 0 deletions

View File

@ -104,6 +104,10 @@ pub const InspectorWidget = extern struct {
));
}
pub fn getSurface(self: *Self) ?*Surface {
return self.private().surface;
}
pub fn setSurface(self: *Self, surface_: ?*Surface) void {
const priv = self.private();

View File

@ -157,6 +157,22 @@ pub const InspectorWindow = extern struct {
));
}
//---------------------------------------------------------------
// Signal Handlers
fn propInspectorSurface(
inspector: *InspectorWidget,
_: *gobject.ParamSpec,
self: *Self,
) callconv(.c) void {
// If the inspector's surface went away, we destroy the window.
// The inspector has a weak notify on the surface so it knows
// if it goes nil.
if (inspector.getSurface() == null) {
self.as(gtk.Window).destroy();
}
}
const C = Common(Self, Private);
pub const as = C.as;
pub const ref = C.ref;
@ -184,6 +200,9 @@ pub const InspectorWindow = extern struct {
// Template Bindings
class.bindTemplateChildPrivate("inspector_widget", .{});
// Template callbacks
class.bindTemplateCallback("notify_inspector_surface", &propInspectorSurface);
// Properties
gobject.ext.registerProperties(class, &.{
properties.surface.impl,

View File

@ -30,6 +30,7 @@ template $GhosttyInspectorWindow: Adw.ApplicationWindow {
}
$GhosttyInspectorWidget inspector_widget {
notify::surface => $notify_inspector_surface();
surface: bind template.surface;
}
}