mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #2151 from ghostty-org/clamp-win
Clamp initial window size configurations to screen size
This commit is contained in:
@ -281,14 +281,15 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
|||||||
// If we have only a single surface (no splits) and that surface requested
|
// If we have only a single surface (no splits) and that surface requested
|
||||||
// an initial size then we set it here now.
|
// an initial size then we set it here now.
|
||||||
if case let .leaf(leaf) = surfaceTree {
|
if case let .leaf(leaf) = surfaceTree {
|
||||||
if let initialSize = leaf.surface.initialSize {
|
if let initialSize = leaf.surface.initialSize,
|
||||||
|
let screen = window.screen ?? NSScreen.main {
|
||||||
// Setup our frame. We need to first subtract the views frame so that we can
|
// Setup our frame. We need to first subtract the views frame so that we can
|
||||||
// just get the chrome frame so that we only affect the surface view size.
|
// just get the chrome frame so that we only affect the surface view size.
|
||||||
var frame = window.frame
|
var frame = window.frame
|
||||||
frame.size.width -= leaf.surface.frame.size.width
|
frame.size.width -= leaf.surface.frame.size.width
|
||||||
frame.size.height -= leaf.surface.frame.size.height
|
frame.size.height -= leaf.surface.frame.size.height
|
||||||
frame.size.width += initialSize.width
|
frame.size.width += min(initialSize.width, screen.frame.width)
|
||||||
frame.size.height += initialSize.height
|
frame.size.height += min(initialSize.height, screen.frame.height)
|
||||||
|
|
||||||
// We have no tabs and we are not a split, so set the initial size of the window.
|
// We have no tabs and we are not a split, so set the initial size of the window.
|
||||||
window.setFrame(frame, display: true)
|
window.setFrame(frame, display: true)
|
||||||
|
@ -551,7 +551,16 @@ pub const Surface = struct {
|
|||||||
/// surface initialization time. This may be called before "self"
|
/// surface initialization time. This may be called before "self"
|
||||||
/// is fully initialized.
|
/// is fully initialized.
|
||||||
pub fn setInitialWindowSize(self: *const Surface, width: u32, height: u32) !void {
|
pub fn setInitialWindowSize(self: *const Surface, width: u32, height: u32) !void {
|
||||||
self.window.setSize(.{ .width = width, .height = height });
|
const monitor = self.window.getMonitor() orelse glfw.Monitor.getPrimary() orelse {
|
||||||
|
log.warn("window is not on a monitor, not setting initial size", .{});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
const workarea = monitor.getWorkarea();
|
||||||
|
self.window.setSize(.{
|
||||||
|
.width = @min(width, workarea.width),
|
||||||
|
.height = @min(height, workarea.height),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the cell size. Unused by GLFW.
|
/// Set the cell size. Unused by GLFW.
|
||||||
|
@ -1066,11 +1066,15 @@ const Subprocess = struct {
|
|||||||
self.screen_size = screen_size;
|
self.screen_size = screen_size;
|
||||||
|
|
||||||
if (self.pty) |*pty| {
|
if (self.pty) |*pty| {
|
||||||
|
// It is theoretically possible for the grid or screen size to
|
||||||
|
// exceed u16, although the terminal in that case isn't very
|
||||||
|
// usable. This should be protected upstream but we still clamp
|
||||||
|
// in case there is a bad caller which has happened before.
|
||||||
try pty.setSize(.{
|
try pty.setSize(.{
|
||||||
.ws_row = @intCast(grid_size.rows),
|
.ws_row = std.math.cast(u16, grid_size.rows) orelse std.math.maxInt(u16),
|
||||||
.ws_col = @intCast(grid_size.columns),
|
.ws_col = std.math.cast(u16, grid_size.columns) orelse std.math.maxInt(u16),
|
||||||
.ws_xpixel = @intCast(screen_size.width),
|
.ws_xpixel = std.math.cast(u16, screen_size.width) orelse std.math.maxInt(u16),
|
||||||
.ws_ypixel = @intCast(screen_size.height),
|
.ws_ypixel = std.math.cast(u16, screen_size.height) orelse std.math.maxInt(u16),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user