apprt/gtk-ng: clean up some changed handlers

pull/8207/head
Mitchell Hashimoto 2025-08-09 14:19:42 -07:00
parent ec293c1fd0
commit aed6a3a343
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
4 changed files with 21 additions and 17 deletions

View File

@ -330,9 +330,18 @@ pub const SplitTree = extern struct {
/// Set the tree data model that we're showing in this widget. This
/// will clone the given tree.
pub fn setTree(self: *Self, tree: ?*const Surface.Tree) void {
pub fn setTree(self: *Self, tree_: ?*const Surface.Tree) void {
const priv = self.private();
// We always normalize our tree parameter so that empty trees
// become null so that we don't have to deal with callers being
// confused about that.
const tree: ?*const Surface.Tree = tree: {
const tree = tree_ orelse break :tree null;
if (tree.isEmpty()) break :tree null;
break :tree tree;
};
// Emit the signal so that handlers can witness both the before and
// after values of the tree.
signals.changed.impl.emit(
@ -349,6 +358,8 @@ pub const SplitTree = extern struct {
}
if (tree) |new_tree| {
assert(priv.tree == null);
assert(!new_tree.isEmpty());
priv.tree = ext.boxedCopy(Surface.Tree, new_tree);
self.connectSurfaceHandlers();
}

View File

@ -242,14 +242,15 @@ pub const Tab = extern struct {
//---------------------------------------------------------------
// Signal handlers
fn splitTreeChanged(
fn propSplitTree(
_: *SplitTree,
_: ?*const Surface.Tree,
new_tree: ?*const Surface.Tree,
_: *gobject.ParamSpec,
self: *Self,
) callconv(.c) void {
self.as(gobject.Object).notifyByPspec(properties.@"surface-tree".impl.param_spec);
// If our tree is empty we close the tab.
const tree: *const Surface.Tree = new_tree orelse &.empty;
const tree: *const Surface.Tree = self.getSurfaceTree() orelse &.empty;
if (tree.isEmpty()) {
signals.@"close-request".impl.emit(
self,
@ -261,14 +262,6 @@ pub const Tab = extern struct {
}
}
fn propSplitTree(
_: *SplitTree,
_: *gobject.ParamSpec,
self: *Self,
) callconv(.c) void {
self.as(gobject.Object).notifyByPspec(properties.@"surface-tree".impl.param_spec);
}
fn propActiveSurface(
_: *SplitTree,
_: *gobject.ParamSpec,
@ -318,7 +311,6 @@ pub const Tab = extern struct {
class.bindTemplateChildPrivate("split_tree", .{});
// Template Callbacks
class.bindTemplateCallback("tree_changed", &splitTreeChanged);
class.bindTemplateCallback("notify_active_surface", &propActiveSurface);
class.bindTemplateCallback("notify_tree", &propSplitTree);

View File

@ -12,6 +12,5 @@ template $GhosttyTab: Box {
$GhosttySplitTree split_tree {
notify::active-surface => $notify_active_surface();
notify::tree => $notify_tree();
changed => $tree_changed();
}
}

View File

@ -826,8 +826,10 @@ pub fn SplitTree(comptime V: type) type {
.copy = &struct {
fn copy(self: *Self) callconv(.c) *Self {
const ptr = @import("glib").ext.create(Self);
const alloc = self.arena.child_allocator;
ptr.* = self.clone(alloc) catch @panic("oom");
ptr.* = if (self.nodes.len == 0)
.empty
else
self.clone(self.arena.child_allocator) catch @panic("oom");
return ptr;
}
}.copy,