diff --git a/src/apprt/gtk-ng/class/split_tree.zig b/src/apprt/gtk-ng/class/split_tree.zig index ae945027e..b0c1a34a3 100644 --- a/src/apprt/gtk-ng/class/split_tree.zig +++ b/src/apprt/gtk-ng/class/split_tree.zig @@ -49,8 +49,6 @@ pub const SplitTree = extern struct { Self, ?*Surface, .{ - .nick = "Active Surface", - .blurb = "The currently active surface.", .accessor = gobject.ext.typedAccessor( Self, ?*Surface, @@ -481,6 +479,7 @@ pub const SplitTree = extern struct { // Remove the surface from the tree. .surface => { // TODO: close confirmation + // TODO: invalid free on final close // Find the surface in the tree. const tree = self.getTree() orelse return; @@ -517,6 +516,9 @@ pub const SplitTree = extern struct { // the surface is destroyed. if (!surface.getFocused()) return; self.private().last_focused.set(surface); + + // Our active surface probably changed + self.as(gobject.Object).notifyByPspec(properties.@"active-surface".impl.param_spec); } fn propTree( @@ -566,6 +568,9 @@ pub const SplitTree = extern struct { v.grabFocus(); } + // Our active surface may have changed + self.as(gobject.Object).notifyByPspec(properties.@"active-surface".impl.param_spec); + return 0; } @@ -616,6 +621,7 @@ pub const SplitTree = extern struct { // Properties gobject.ext.registerProperties(class, &.{ + properties.@"active-surface".impl, properties.@"has-surfaces".impl, properties.tree.impl, }); diff --git a/src/apprt/gtk-ng/class/tab.zig b/src/apprt/gtk-ng/class/tab.zig index 964f6fc3e..051807071 100644 --- a/src/apprt/gtk-ng/class/tab.zig +++ b/src/apprt/gtk-ng/class/tab.zig @@ -175,42 +175,6 @@ pub const Tab = extern struct { }; } - fn connectSurfaceHandlers( - self: *Self, - tree: *const Surface.Tree, - ) void { - var it = tree.iterator(); - while (it.next()) |entry| { - const surface = entry.view; - _ = gobject.Object.signals.notify.connect( - surface, - *Self, - propSurfaceFocused, - self, - .{ .detail = "focused" }, - ); - } - } - - fn disconnectSurfaceHandlers( - self: *Self, - tree: *const Surface.Tree, - ) void { - var it = tree.iterator(); - while (it.next()) |entry| { - const surface = entry.view; - _ = gobject.signalHandlersDisconnectMatched( - surface.as(gobject.Object), - .{ .data = true }, - 0, - 0, - null, - null, - self, - ); - } - } - //--------------------------------------------------------------- // Properties @@ -280,14 +244,10 @@ pub const Tab = extern struct { fn splitTreeChanged( _: *SplitTree, - old_tree: ?*const Surface.Tree, + _: ?*const Surface.Tree, new_tree: ?*const Surface.Tree, self: *Self, ) callconv(.c) void { - if (old_tree) |tree| { - self.disconnectSurfaceHandlers(tree); - } - // If our tree is empty we close the tab. const tree: *const Surface.Tree = new_tree orelse &.empty; if (tree.isEmpty()) { @@ -299,9 +259,6 @@ pub const Tab = extern struct { ); return; } - - // Non-empty tree, connect handlers we care about. - self.connectSurfaceHandlers(tree); } fn propSplitTree( @@ -313,7 +270,7 @@ pub const Tab = extern struct { } fn propActiveSurface( - _: *Self, + _: *SplitTree, _: *gobject.ParamSpec, self: *Self, ) callconv(.c) void { @@ -322,14 +279,7 @@ pub const Tab = extern struct { if (self.getActiveSurface()) |surface| { priv.surface_bindings.setSource(surface.as(gobject.Object)); } - } - fn propSurfaceFocused( - surface: *Surface, - _: *gobject.ParamSpec, - self: *Self, - ) callconv(.c) void { - if (!surface.getFocused()) return; self.as(gobject.Object).notifyByPspec(properties.@"active-surface".impl.param_spec); } diff --git a/src/apprt/gtk-ng/ui/1.5/tab.blp b/src/apprt/gtk-ng/ui/1.5/tab.blp index 61f106ce1..70e4f709b 100644 --- a/src/apprt/gtk-ng/ui/1.5/tab.blp +++ b/src/apprt/gtk-ng/ui/1.5/tab.blp @@ -5,12 +5,12 @@ template $GhosttyTab: Box { "tab", ] - notify::active-surface => $notify_active_surface(); orientation: vertical; hexpand: true; vexpand: true; $GhosttySplitTree split_tree { + notify::active-surface => $notify_active_surface(); notify::tree => $notify_tree(); changed => $tree_changed(); } diff --git a/src/datastruct/split_tree.zig b/src/datastruct/split_tree.zig index a1f2de035..48b887707 100644 --- a/src/datastruct/split_tree.zig +++ b/src/datastruct/split_tree.zig @@ -1151,3 +1151,21 @@ test "SplitTree: split twice, remove intermediary" { t.deinit(); } } + +test "SplitTree: clone empty tree" { + const testing = std.testing; + const alloc = testing.allocator; + var t: TestTree = .empty; + defer t.deinit(); + + var t2 = try t.clone(alloc); + defer t2.deinit(); + + { + const str = try std.fmt.allocPrint(alloc, "{}", .{t2}); + defer alloc.free(str); + try testing.expectEqualStrings(str, + \\empty + ); + } +}