From 604eeceb0344043ad0479f050550bf380f810272 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 22 Sep 2023 18:54:58 -0700 Subject: [PATCH] apprt/glfw: support window-width, window-height configurations --- src/apprt/glfw.zig | 9 +++++++++ src/config/Config.zig | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index e4acab289..e69aa1479 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -376,6 +376,15 @@ pub const Surface = struct { self, ); errdefer self.core_surface.deinit(); + + // If we have a desired window size, we can now calculate the size + // because we have the cell size. + if (config.@"window-height" > 0 or config.@"window-width" > 0) { + self.window.setSize(.{ + .height = @max(config.@"window-height" * self.core_surface.cell_size.height, 480), + .width = @max(config.@"window-width" * self.core_surface.cell_size.width, 640), + }); + } } pub fn deinit(self: *Surface) void { diff --git a/src/config/Config.zig b/src/config/Config.zig index 1b6e8d84b..8ba3b02c1 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -300,6 +300,26 @@ keybind: Keybinds = .{}, /// This is currently only supported on macOS. @"window-theme": WindowTheme = .system, +/// The initial window size. This size is in terminal grid cells by default. +/// +/// We don't currently support specifying a size in pixels but a future +/// change can enable that. If this isn't specified, the app runtime will +/// determine some default size. +/// +/// Note that the window manager may put limits on the size or override +/// the size. For example, a tiling window manager may force the window +/// to be a certain size to fit within the grid. There is nothing Ghostty +/// will do about this, but it will make an effort. +/// +/// This will not affect new tabs, splits, or other nested terminal +/// elements. This only affects the initial window size of any new window. +/// Changing this value will not affect the size of the window after +/// it has been created. This is only used for the initial size. +/// +/// Windows smaller than 10 wide by 4 high are not allowed. +@"window-height": u32 = 0, +@"window-width": u32 = 0, + /// Whether to allow programs running in the terminal to read/write to /// the system clipboard (OSC 52, for googling). The default is to /// disallow clipboard reading but allow writing. @@ -1007,6 +1027,10 @@ pub fn finalize(self: *Config) !void { // Clamp our split opacity self.@"unfocused-split-opacity" = @min(1.0, @max(0.15, self.@"unfocused-split-opacity")); + + // Minimmum window size + if (self.@"window-width" > 0) self.@"window-width" = @max(10, self.@"window-width"); + if (self.@"window-height" > 0) self.@"window-height" = @max(4, self.@"window-height"); } /// Create a shallow copy of this config. This will share all the memory