termio: change all sizes to the new size type

This commit is contained in:
Mitchell Hashimoto
2024-11-14 13:31:01 -08:00
parent dcb1ce8377
commit 90c59f2462
4 changed files with 40 additions and 52 deletions

View File

@ -513,10 +513,7 @@ pub fn init(
errdefer io_mailbox.deinit(alloc); errdefer io_mailbox.deinit(alloc);
try termio.Termio.init(&self.io, alloc, .{ try termio.Termio.init(&self.io, alloc, .{
.grid_size = size.grid(), .size = size,
.cell_size = size.cell,
.screen_size = size.screen,
.padding = padding,
.full_config = config, .full_config = config,
.config = try termio.Termio.DerivedConfig.init(alloc, config), .config = try termio.Termio.DerivedConfig.init(alloc, config),
.backend = .{ .exec = io_exec }, .backend = .{ .exec = io_exec },

View File

@ -8,17 +8,8 @@ const Command = @import("../Command.zig");
const Config = @import("../config.zig").Config; const Config = @import("../config.zig").Config;
const termio = @import("../termio.zig"); const termio = @import("../termio.zig");
/// The size of the terminal grid. /// All size metrics for the terminal.
grid_size: renderer.GridSize, size: renderer.Size,
/// The size of a single cell, in pixels.
cell_size: renderer.CellSize,
/// The size of the viewport in pixels.
screen_size: renderer.ScreenSize,
/// The padding of the viewport.
padding: renderer.Padding,
/// The full app configuration. This is only available during initialization. /// The full app configuration. This is only available during initialization.
/// The memory it points to is NOT stable after the init call so any values /// The memory it points to is NOT stable after the init call so any values

View File

@ -56,11 +56,8 @@ renderer_mailbox: *renderer.Thread.Mailbox,
/// The mailbox for communicating with the surface. /// The mailbox for communicating with the surface.
surface_mailbox: apprt.surface.Mailbox, surface_mailbox: apprt.surface.Mailbox,
/// The cached grid size whenever a resize is called. /// The cached size info
grid_size: renderer.GridSize, size: renderer.Size,
/// The size of a single cell. Used for size reports.
cell_size: renderer.CellSize,
/// The mailbox implementation to use. /// The mailbox implementation to use.
mailbox: termio.Mailbox, mailbox: termio.Mailbox,
@ -131,10 +128,13 @@ pub const DerivedConfig = struct {
/// to run a child process. /// to run a child process.
pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void { pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
// Create our terminal // Create our terminal
var term = try terminal.Terminal.init(alloc, .{ var term = try terminal.Terminal.init(alloc, opts: {
.cols = opts.grid_size.columns, const grid_size = opts.size.grid();
.rows = opts.grid_size.rows, break :opts .{
.max_scrollback = opts.full_config.@"scrollback-limit", .cols = grid_size.columns,
.rows = grid_size.rows,
.max_scrollback = opts.full_config.@"scrollback-limit",
};
}); });
errdefer term.deinit(alloc); errdefer term.deinit(alloc);
term.default_palette = opts.config.palette; term.default_palette = opts.config.palette;
@ -169,8 +169,8 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
term.screen.cursor.cursor_style = opts.config.cursor_style; term.screen.cursor.cursor_style = opts.config.cursor_style;
// Setup our terminal size in pixels for certain requests. // Setup our terminal size in pixels for certain requests.
term.width_px = opts.grid_size.columns * opts.cell_size.width; term.width_px = term.cols * opts.size.cell.width;
term.height_px = opts.grid_size.rows * opts.cell_size.height; term.height_px = term.rows * opts.size.cell.height;
// Setup our backend. // Setup our backend.
var backend = opts.backend; var backend = opts.backend;
@ -191,7 +191,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
.renderer_state = opts.renderer_state, .renderer_state = opts.renderer_state,
.renderer_wakeup = opts.renderer_wakeup, .renderer_wakeup = opts.renderer_wakeup,
.renderer_mailbox = opts.renderer_mailbox, .renderer_mailbox = opts.renderer_mailbox,
.grid_size = &self.grid_size, .size = &self.size,
.terminal = &self.terminal, .terminal = &self.terminal,
.osc_color_report_format = opts.config.osc_color_report_format, .osc_color_report_format = opts.config.osc_color_report_format,
.enquiry_response = opts.config.enquiry_response, .enquiry_response = opts.config.enquiry_response,
@ -214,8 +214,7 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
.renderer_wakeup = opts.renderer_wakeup, .renderer_wakeup = opts.renderer_wakeup,
.renderer_mailbox = opts.renderer_mailbox, .renderer_mailbox = opts.renderer_mailbox,
.surface_mailbox = opts.surface_mailbox, .surface_mailbox = opts.surface_mailbox,
.grid_size = opts.grid_size, .size = opts.size,
.cell_size = opts.cell_size,
.backend = opts.backend, .backend = opts.backend,
.mailbox = opts.mailbox, .mailbox = opts.mailbox,
.terminal_stream = .{ .terminal_stream = .{
@ -356,10 +355,6 @@ pub fn resize(
// Update the size of our pty. // Update the size of our pty.
try self.backend.resize(grid_size, size.terminal()); try self.backend.resize(grid_size, size.terminal());
// Update our cached grid size
self.grid_size = size.grid();
self.cell_size = size.cell;
// Enter the critical area that we want to keep small // Enter the critical area that we want to keep small
{ {
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
@ -373,8 +368,8 @@ pub fn resize(
); );
// Update our pixel sizes // Update our pixel sizes
self.terminal.width_px = grid_size.columns * self.cell_size.width; self.terminal.width_px = grid_size.columns * self.size.cell.width;
self.terminal.height_px = grid_size.rows * self.cell_size.height; self.terminal.height_px = grid_size.rows * self.size.cell.height;
// Disable synchronized output mode so that we show changes // Disable synchronized output mode so that we show changes
// immediately for a resize. This is allowed by the spec. // immediately for a resize. This is allowed by the spec.
@ -404,6 +399,8 @@ pub fn sizeReport(self: *Termio, td: *ThreadData, style: termio.Message.SizeRepo
} }
fn sizeReportLocked(self: *Termio, td: *ThreadData, style: termio.Message.SizeReport) !void { fn sizeReportLocked(self: *Termio, td: *ThreadData, style: termio.Message.SizeReport) !void {
const grid_size = self.size.grid();
// 1024 bytes should be enough for size report since report // 1024 bytes should be enough for size report since report
// in columns and pixels. // in columns and pixels.
var buf: [1024]u8 = undefined; var buf: [1024]u8 = undefined;
@ -412,34 +409,34 @@ fn sizeReportLocked(self: *Termio, td: *ThreadData, style: termio.Message.SizeRe
&buf, &buf,
"\x1B[48;{};{};{};{}t", "\x1B[48;{};{};{};{}t",
.{ .{
self.grid_size.rows, grid_size.rows,
self.grid_size.columns, grid_size.columns,
self.grid_size.rows * self.cell_size.height, grid_size.rows * self.size.cell.height,
self.grid_size.columns * self.cell_size.width, grid_size.columns * self.size.cell.width,
}, },
), ),
.csi_14_t => try std.fmt.bufPrint( .csi_14_t => try std.fmt.bufPrint(
&buf, &buf,
"\x1b[4;{};{}t", "\x1b[4;{};{}t",
.{ .{
self.grid_size.rows * self.cell_size.height, grid_size.rows * self.size.cell.height,
self.grid_size.columns * self.cell_size.width, grid_size.columns * self.size.cell.width,
}, },
), ),
.csi_16_t => try std.fmt.bufPrint( .csi_16_t => try std.fmt.bufPrint(
&buf, &buf,
"\x1b[6;{};{}t", "\x1b[6;{};{}t",
.{ .{
self.cell_size.height, self.size.cell.height,
self.cell_size.width, self.size.cell.width,
}, },
), ),
.csi_18_t => try std.fmt.bufPrint( .csi_18_t => try std.fmt.bufPrint(
&buf, &buf,
"\x1b[8;{};{}t", "\x1b[8;{};{}t",
.{ .{
self.grid_size.rows, grid_size.rows,
self.grid_size.columns, grid_size.columns,
}, },
), ),
}; };

View File

@ -26,7 +26,7 @@ const disable_kitty_keyboard_protocol = apprt.runtime == apprt.glfw;
/// unless all of the member fields are copied. /// unless all of the member fields are copied.
pub const StreamHandler = struct { pub const StreamHandler = struct {
alloc: Allocator, alloc: Allocator,
grid_size: *renderer.GridSize, size: *renderer.Size,
terminal: *terminal.Terminal, terminal: *terminal.Terminal,
/// Mailbox for data to the termio thread. /// Mailbox for data to the termio thread.
@ -611,12 +611,15 @@ pub const StreamHandler = struct {
}, },
// Force resize back to the window size // Force resize back to the window size
.enable_mode_3 => self.terminal.resize( .enable_mode_3 => {
self.alloc, const grid_size = self.size.grid();
self.grid_size.columns, self.terminal.resize(
self.grid_size.rows, self.alloc,
) catch |err| { grid_size.columns,
log.err("error updating terminal size: {}", .{err}); grid_size.rows,
) catch |err| {
log.err("error updating terminal size: {}", .{err});
};
}, },
.@"132_column" => try self.terminal.deccolm( .@"132_column" => try self.terminal.deccolm(