mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
gtk: handle closing of surfaces with sibling being a Paned
This commit is contained in:

committed by
Mitchell Hashimoto

parent
142a2f4cb0
commit
0add9de0eb
@ -72,8 +72,8 @@ pub fn init(self: *Paned, window: *Window, sibling: *Surface, direction: input.S
|
||||
|
||||
const new_surface = try self.newSurface(sibling.tab, &sibling.core_surface);
|
||||
// This sets .parent on each surface
|
||||
self.addChild1Surface(sibling);
|
||||
self.addChild2Surface(new_surface);
|
||||
self.addChild1(.{ .surface = sibling });
|
||||
self.addChild2(.{ .surface = new_surface });
|
||||
}
|
||||
|
||||
pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*Surface {
|
||||
@ -150,30 +150,40 @@ pub fn removeChildInPosition(self: *Paned, position: Position) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addChild1Surface(self: *Paned, surface: *Surface) void {
|
||||
pub fn addChild1(self: *Paned, child: Child) void {
|
||||
assert(self.child1 == .none);
|
||||
self.child1 = Child{ .surface = surface };
|
||||
surface.setParent(Parent{ .paned = .{ self, .start } });
|
||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
||||
}
|
||||
|
||||
pub fn addChild2Surface(self: *Paned, surface: *Surface) void {
|
||||
assert(self.child2 == .none);
|
||||
self.child2 = Child{ .surface = surface };
|
||||
surface.setParent(Parent{ .paned = .{ self, .end } });
|
||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
||||
}
|
||||
const parent = Parent{ .paned = .{ self, .start } };
|
||||
self.child1 = child;
|
||||
|
||||
pub fn addChild1Paned(self: *Paned, paned: *Paned) void {
|
||||
assert(self.child1 == .none);
|
||||
self.child1 = Child{ .paned = paned };
|
||||
paned.setParent(Parent{ .paned = .{ self, .start } });
|
||||
switch (child) {
|
||||
.none => return,
|
||||
.paned => |paned| {
|
||||
paned.setParent(parent);
|
||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(@alignCast(paned.paned)));
|
||||
},
|
||||
.surface => |surface| {
|
||||
surface.setParent(parent);
|
||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addChild2Paned(self: *Paned, paned: *Paned) void {
|
||||
pub fn addChild2(self: *Paned, child: Child) void {
|
||||
assert(self.child2 == .none);
|
||||
self.child2 = Child{ .paned = paned };
|
||||
paned.setParent(Parent{ .paned = .{ self, .end } });
|
||||
|
||||
const parent = Parent{ .paned = .{ self, .end } };
|
||||
self.child2 = child;
|
||||
|
||||
switch (child) {
|
||||
.none => return,
|
||||
.paned => |paned| {
|
||||
paned.setParent(parent);
|
||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(@alignCast(paned.paned)));
|
||||
},
|
||||
.surface => |surface| {
|
||||
surface.setParent(parent);
|
||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -378,8 +378,8 @@ pub fn newSplit(self: *Surface, direction: input.SplitDirection) !void {
|
||||
|
||||
// Add new split-paned
|
||||
switch (parent_position) {
|
||||
.start => parent_paned.addChild1Paned(paned),
|
||||
.end => parent_paned.addChild2Paned(paned),
|
||||
.start => parent_paned.addChild1(.{ .paned = paned }),
|
||||
.end => parent_paned.addChild2(.{ .paned = paned }),
|
||||
}
|
||||
// Restore position
|
||||
c.gtk_paned_set_position(parent_paned.paned, parent_paned_position_before);
|
||||
|
@ -263,22 +263,16 @@ pub fn closeSurface(self: *Window, surface: *Surface) void {
|
||||
|
||||
const sibling = switch (position) {
|
||||
.start => .{
|
||||
switch (paned.child2) {
|
||||
.surface => |s| s,
|
||||
else => return,
|
||||
},
|
||||
paned.child2,
|
||||
c.gtk_paned_get_end_child(paned.paned),
|
||||
},
|
||||
.end => .{
|
||||
switch (paned.child1) {
|
||||
.surface => |s| s,
|
||||
else => return,
|
||||
},
|
||||
paned.child1,
|
||||
c.gtk_paned_get_start_child(paned.paned),
|
||||
},
|
||||
};
|
||||
// TODO: Use destructuring syntax once it doesn't break ZLS
|
||||
const sibling_surface = sibling[0];
|
||||
const sibling_child = sibling[0];
|
||||
const sibling_widget = sibling[1];
|
||||
|
||||
// Keep explicit reference to sibling's gl_area, so it's not
|
||||
@ -300,7 +294,7 @@ pub fn closeSurface(self: *Window, surface: *Surface) void {
|
||||
// If parent of Paned we belong to is a tab, we can
|
||||
// replace the child with the other surface
|
||||
tab.removeChild();
|
||||
tab.setChild(.{ .surface = sibling_surface });
|
||||
tab.setChild(sibling_child);
|
||||
},
|
||||
.paned => |parent_paned_tuple| {
|
||||
const parent_paned = parent_paned_tuple[0];
|
||||
@ -312,8 +306,8 @@ pub fn closeSurface(self: *Window, surface: *Surface) void {
|
||||
parent_paned.removeChildInPosition(parent_paned_position);
|
||||
|
||||
switch (parent_paned_position) {
|
||||
.start => parent_paned.addChild1Surface(sibling_surface),
|
||||
.end => parent_paned.addChild2Surface(sibling_surface),
|
||||
.start => parent_paned.addChild1(sibling_child),
|
||||
.end => parent_paned.addChild2(sibling_child),
|
||||
}
|
||||
|
||||
// Restore position
|
||||
|
Reference in New Issue
Block a user