mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +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);
|
const new_surface = try self.newSurface(sibling.tab, &sibling.core_surface);
|
||||||
// This sets .parent on each surface
|
// This sets .parent on each surface
|
||||||
self.addChild1Surface(sibling);
|
self.addChild1(.{ .surface = sibling });
|
||||||
self.addChild2Surface(new_surface);
|
self.addChild2(.{ .surface = new_surface });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*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);
|
assert(self.child1 == .none);
|
||||||
self.child1 = Child{ .surface = surface };
|
|
||||||
surface.setParent(Parent{ .paned = .{ self, .start } });
|
const parent = Parent{ .paned = .{ self, .start } };
|
||||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
self.child1 = child;
|
||||||
|
|
||||||
|
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 addChild2Surface(self: *Paned, surface: *Surface) void {
|
pub fn addChild2(self: *Paned, child: Child) void {
|
||||||
assert(self.child2 == .none);
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn addChild1Paned(self: *Paned, paned: *Paned) void {
|
const parent = Parent{ .paned = .{ self, .end } };
|
||||||
assert(self.child1 == .none);
|
self.child2 = child;
|
||||||
self.child1 = Child{ .paned = paned };
|
|
||||||
paned.setParent(Parent{ .paned = .{ self, .start } });
|
|
||||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(@alignCast(paned.paned)));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn addChild2Paned(self: *Paned, paned: *Paned) void {
|
switch (child) {
|
||||||
assert(self.child2 == .none);
|
.none => return,
|
||||||
self.child2 = Child{ .paned = paned };
|
.paned => |paned| {
|
||||||
paned.setParent(Parent{ .paned = .{ self, .end } });
|
paned.setParent(parent);
|
||||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(@alignCast(paned.paned)));
|
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
|
// Add new split-paned
|
||||||
switch (parent_position) {
|
switch (parent_position) {
|
||||||
.start => parent_paned.addChild1Paned(paned),
|
.start => parent_paned.addChild1(.{ .paned = paned }),
|
||||||
.end => parent_paned.addChild2Paned(paned),
|
.end => parent_paned.addChild2(.{ .paned = paned }),
|
||||||
}
|
}
|
||||||
// Restore position
|
// Restore position
|
||||||
c.gtk_paned_set_position(parent_paned.paned, parent_paned_position_before);
|
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) {
|
const sibling = switch (position) {
|
||||||
.start => .{
|
.start => .{
|
||||||
switch (paned.child2) {
|
paned.child2,
|
||||||
.surface => |s| s,
|
|
||||||
else => return,
|
|
||||||
},
|
|
||||||
c.gtk_paned_get_end_child(paned.paned),
|
c.gtk_paned_get_end_child(paned.paned),
|
||||||
},
|
},
|
||||||
.end => .{
|
.end => .{
|
||||||
switch (paned.child1) {
|
paned.child1,
|
||||||
.surface => |s| s,
|
|
||||||
else => return,
|
|
||||||
},
|
|
||||||
c.gtk_paned_get_start_child(paned.paned),
|
c.gtk_paned_get_start_child(paned.paned),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// TODO: Use destructuring syntax once it doesn't break ZLS
|
// 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];
|
const sibling_widget = sibling[1];
|
||||||
|
|
||||||
// Keep explicit reference to sibling's gl_area, so it's not
|
// 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
|
// If parent of Paned we belong to is a tab, we can
|
||||||
// replace the child with the other surface
|
// replace the child with the other surface
|
||||||
tab.removeChild();
|
tab.removeChild();
|
||||||
tab.setChild(.{ .surface = sibling_surface });
|
tab.setChild(sibling_child);
|
||||||
},
|
},
|
||||||
.paned => |parent_paned_tuple| {
|
.paned => |parent_paned_tuple| {
|
||||||
const parent_paned = parent_paned_tuple[0];
|
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);
|
parent_paned.removeChildInPosition(parent_paned_position);
|
||||||
|
|
||||||
switch (parent_paned_position) {
|
switch (parent_paned_position) {
|
||||||
.start => parent_paned.addChild1Surface(sibling_surface),
|
.start => parent_paned.addChild1(sibling_child),
|
||||||
.end => parent_paned.addChild2Surface(sibling_surface),
|
.end => parent_paned.addChild2(sibling_child),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore position
|
// Restore position
|
||||||
|
Reference in New Issue
Block a user