mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-23 04:06:13 +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.
|
/// Remove both children, setting *c.GtkSplit start/end children to null.
|
||||||
pub fn removeChildren(self: *Split) void {
|
// pub fn removeChildren(self: *Split) void {
|
||||||
self.removeChildInPosition(.start);
|
// self.removeChildInPosition(.start);
|
||||||
self.removeChildInPosition(.end);
|
// self.removeChildInPosition(.end);
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// Deinit the Split by deiniting its child Split, if they exist.
|
/// Deinit the Split by deiniting its child Split, if they exist.
|
||||||
pub fn deinit(self: *Split, alloc: Allocator) void {
|
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
|
// TODO: ehhhhhh
|
||||||
pub fn replace(
|
pub fn replace(
|
||||||
self: *Split,
|
self: *Split,
|
||||||
@ -203,12 +215,6 @@ pub fn replace(
|
|||||||
// position but we want to keep it in place so save and restore it.
|
// position but we want to keep it in place so save and restore it.
|
||||||
const pos = c.gtk_paned_get_position(self.paned);
|
const pos = c.gtk_paned_get_position(self.paned);
|
||||||
defer c.gtk_paned_set_position(self.paned, pos);
|
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();
|
self.updateChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +222,12 @@ pub fn replace(
|
|||||||
/// This should be called anytime the top/left or bottom/right
|
/// This should be called anytime the top/left or bottom/right
|
||||||
/// element is changed.
|
/// element is changed.
|
||||||
fn updateChildren(self: *const Split) void {
|
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(
|
c.gtk_paned_set_start_child(
|
||||||
@ptrCast(self.paned),
|
@ptrCast(self.paned),
|
||||||
self.top_left.widget(),
|
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 {
|
fn addChild1(self: *Split, child: Child) void {
|
||||||
assert(self.child1 == .none);
|
assert(self.child1 == .none);
|
||||||
|
|
||||||
|
@ -72,6 +72,13 @@ pub const Container = union(enum) {
|
|||||||
.split => |s| @ptrCast(@alignCast(s.paned)),
|
.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.
|
/// 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
|
/// from a surface to a split or a split back to a surface or
|
||||||
/// a split to a nested split and so on.
|
/// a split to a nested split and so on.
|
||||||
pub fn replace(self: Container, elem: Elem) void {
|
pub fn replace(self: Container, elem: Elem) void {
|
||||||
|
// Move the element into the container
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.none => {},
|
.none => {},
|
||||||
.tab_ => |t| t.replaceElem(elem),
|
.tab_ => |t| t.replaceElem(elem),
|
||||||
@ -120,6 +128,9 @@ pub const Container = union(enum) {
|
|||||||
s.replace(ptr, elem);
|
s.replace(ptr, elem);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the reverse reference to the container
|
||||||
|
elem.containerPtr().* = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove ourselves from the container. This is used by
|
/// Remove ourselves from the container. This is used by
|
||||||
@ -129,6 +140,7 @@ pub const Container = union(enum) {
|
|||||||
switch (self) {
|
switch (self) {
|
||||||
.none => {},
|
.none => {},
|
||||||
.tab_ => |t| t.closeElem(),
|
.tab_ => |t| t.closeElem(),
|
||||||
|
.split_tl => self.split().?.removeTopLeft(),
|
||||||
else => @panic("TOOD"),
|
else => @panic("TOOD"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user