mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
apprt/gtk: prevent a new split from being smaller than 2x2
Fixes #2092 This isn't perfect because it only prevents _new_ splits from being too small. You can still resize the window to make them smaller. This just helps prevent the very-easy-to-trigger crash of #2092. We don't need to do this to macOS because it doesn't crash in the same way with zero-sized splits. Long term we should really chase down what breaks in GTK at a root level when we have zero-sized splits. But this is a quick fix for now to prevent the easy crash I feel like people might stress test and run into with the 1.0 release.
This commit is contained in:
@ -70,6 +70,27 @@ pub fn init(
|
||||
sibling: *Surface,
|
||||
direction: apprt.action.SplitDirection,
|
||||
) !void {
|
||||
// If our sibling is too small to be split in half then we don't
|
||||
// allow the split to happen. This avoids a situation where the
|
||||
// split becomes too small.
|
||||
//
|
||||
// This is kind of a hack. Ideally we'd use gtk_widget_set_size_request
|
||||
// properly along the path to ensure minimum sizes. I don't know if
|
||||
// GTK even respects that all but any way GTK does this for us seems
|
||||
// better than this.
|
||||
{
|
||||
// This is the min size of the sibling split. This means the
|
||||
// smallest split is half of this.
|
||||
const multiplier = 4;
|
||||
|
||||
const size = &sibling.core_surface.size;
|
||||
const small = switch (direction) {
|
||||
.right, .left => size.screen.width < size.cell.width * multiplier,
|
||||
.down, .up => size.screen.height < size.cell.height * multiplier,
|
||||
};
|
||||
if (small) return error.SplitTooSmall;
|
||||
}
|
||||
|
||||
// Create the new child surface for the other direction.
|
||||
const alloc = sibling.app.core_app.alloc;
|
||||
var surface = try Surface.create(alloc, sibling.app, .{
|
||||
|
Reference in New Issue
Block a user