mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-22 19:56:08 +03:00
apprt/gtk: maintain container pointers
This commit is contained in:
@ -156,10 +156,10 @@ pub fn replaceChildInPosition(self: *Split, child: Child, position: Position) vo
|
||||
}
|
||||
|
||||
/// Remove both children, setting *c.GtkSplit start/end children to null.
|
||||
pub fn removeChildren(self: *Split) void {
|
||||
self.removeChildInPosition(.start);
|
||||
self.removeChildInPosition(.end);
|
||||
}
|
||||
// pub fn removeChildren(self: *Split) void {
|
||||
// self.removeChildInPosition(.start);
|
||||
// self.removeChildInPosition(.end);
|
||||
//}
|
||||
|
||||
/// Deinit the Split by deiniting its child Split, if they exist.
|
||||
pub fn deinit(self: *Split, alloc: Allocator) void {
|
||||
@ -189,6 +189,18 @@ fn removeChildInPosition(self: *Split, position: Position) void {
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the top left child.
|
||||
pub fn removeTopLeft(self: *Split) void {
|
||||
// Remove our children since we are going to no longer be
|
||||
// a split anyways. This prevents widgets with multiple parents.
|
||||
self.removeChildren();
|
||||
|
||||
// Our container must become whatever our bottom right is
|
||||
self.container.replace(self.bottom_right);
|
||||
|
||||
// TODO: memory management of top left
|
||||
}
|
||||
|
||||
// TODO: ehhhhhh
|
||||
pub fn replace(
|
||||
self: *Split,
|
||||
@ -203,12 +215,6 @@ pub fn replace(
|
||||
// position but we want to keep it in place so save and restore it.
|
||||
const pos = c.gtk_paned_get_position(self.paned);
|
||||
defer c.gtk_paned_set_position(self.paned, pos);
|
||||
|
||||
// We have to set both to null. If we overwrite the pane with
|
||||
// the same value, then GTK bugs out (the GL area unrealizes
|
||||
// and never rerealizes).
|
||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), null);
|
||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), null);
|
||||
self.updateChildren();
|
||||
}
|
||||
|
||||
@ -216,6 +222,12 @@ pub fn replace(
|
||||
/// This should be called anytime the top/left or bottom/right
|
||||
/// element is changed.
|
||||
fn updateChildren(self: *const Split) void {
|
||||
// We have to set both to null. If we overwrite the pane with
|
||||
// the same value, then GTK bugs out (the GL area unrealizes
|
||||
// and never rerealizes).
|
||||
self.removeChildren();
|
||||
|
||||
// Set our current children
|
||||
c.gtk_paned_set_start_child(
|
||||
@ptrCast(self.paned),
|
||||
self.top_left.widget(),
|
||||
@ -226,6 +238,11 @@ fn updateChildren(self: *const Split) void {
|
||||
);
|
||||
}
|
||||
|
||||
fn removeChildren(self: *const Split) void {
|
||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), null);
|
||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), null);
|
||||
}
|
||||
|
||||
fn addChild1(self: *Split, child: Child) void {
|
||||
assert(self.child1 == .none);
|
||||
|
||||
|
@ -72,6 +72,13 @@ pub const Container = union(enum) {
|
||||
.split => |s| @ptrCast(@alignCast(s.paned)),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn containerPtr(self: Elem) *Container {
|
||||
return switch (self) {
|
||||
.surface => |s| &s.container,
|
||||
.split => |s| &s.container,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns the window that this surface is attached to.
|
||||
@ -112,6 +119,7 @@ pub const Container = union(enum) {
|
||||
/// from a surface to a split or a split back to a surface or
|
||||
/// a split to a nested split and so on.
|
||||
pub fn replace(self: Container, elem: Elem) void {
|
||||
// Move the element into the container
|
||||
switch (self) {
|
||||
.none => {},
|
||||
.tab_ => |t| t.replaceElem(elem),
|
||||
@ -120,6 +128,9 @@ pub const Container = union(enum) {
|
||||
s.replace(ptr, elem);
|
||||
},
|
||||
}
|
||||
|
||||
// Update the reverse reference to the container
|
||||
elem.containerPtr().* = self;
|
||||
}
|
||||
|
||||
/// Remove ourselves from the container. This is used by
|
||||
@ -129,6 +140,7 @@ pub const Container = union(enum) {
|
||||
switch (self) {
|
||||
.none => {},
|
||||
.tab_ => |t| t.closeElem(),
|
||||
.split_tl => self.split().?.removeTopLeft(),
|
||||
else => @panic("TOOD"),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user