From dcb1ce83770df11b77fc7615ac3d9b9534043808 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 14 Nov 2024 13:23:11 -0800 Subject: [PATCH] termio: change resize message to use new size struct --- src/Surface.zig | 18 ++---------------- src/renderer/size.zig | 6 ++++++ src/termio/Termio.zig | 22 ++++++++++------------ src/termio/Thread.zig | 13 ++++--------- src/termio/message.zig | 18 +----------------- 5 files changed, 23 insertions(+), 54 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index a9017c0c0..1a1cc4801 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1365,14 +1365,7 @@ fn setCellSize(self: *Surface, size: renderer.CellSize) !void { if (self.config.window_padding_balance) self.size.balancePadding(); // Notify the terminal - self.io.queueMessage(.{ - .resize = .{ - .grid_size = self.size.grid(), - .cell_size = self.size.cell, - .screen_size = self.size.screen, - .padding = self.size.padding, - }, - }, .unlocked); + self.io.queueMessage(.{ .resize = self.size }, .unlocked); // Notify the window try self.rt_app.performAction( @@ -1468,14 +1461,7 @@ fn resize(self: *Surface, size: renderer.ScreenSize) !void { } // Mail the IO thread - self.io.queueMessage(.{ - .resize = .{ - .grid_size = grid_size, - .cell_size = self.size.cell, - .screen_size = self.size.screen, - .padding = self.size.padding, - }, - }, .unlocked); + self.io.queueMessage(.{ .resize = self.size }, .unlocked); } /// Called to set the preedit state for character input. Preedit is used diff --git a/src/renderer/size.zig b/src/renderer/size.zig index 2e65c8623..9d7a13b54 100644 --- a/src/renderer/size.zig +++ b/src/renderer/size.zig @@ -25,6 +25,12 @@ pub const Size = struct { return GridSize.init(self.screen.subPadding(self.padding), self.cell); } + /// The size of the terminal. This is the same as the screen without + /// padding. + pub fn terminal(self: Size) ScreenSize { + return self.screen.subPadding(self.padding); + } + /// Set the padding to be balanced around the grid. Overwrites the current /// padding. pub fn balancePadding(self: *Size) void { diff --git a/src/termio/Termio.zig b/src/termio/Termio.zig index fc1bfc32d..13ef4a73c 100644 --- a/src/termio/Termio.zig +++ b/src/termio/Termio.zig @@ -349,18 +349,16 @@ pub fn changeConfig(self: *Termio, td: *ThreadData, config: *DerivedConfig) !voi pub fn resize( self: *Termio, td: *ThreadData, - grid_size: renderer.GridSize, - cell_size: renderer.CellSize, - screen_size: renderer.ScreenSize, - padding: renderer.Padding, + size: renderer.Size, ) !void { + const grid_size = size.grid(); + // Update the size of our pty. - const padded_size = screen_size.subPadding(padding); - try self.backend.resize(grid_size, padded_size); + try self.backend.resize(grid_size, size.terminal()); // Update our cached grid size - self.grid_size = grid_size; - self.cell_size = cell_size; + self.grid_size = size.grid(); + self.cell_size = size.cell; // Enter the critical area that we want to keep small { @@ -375,8 +373,8 @@ pub fn resize( ); // Update our pixel sizes - self.terminal.width_px = self.grid_size.columns * self.cell_size.width; - self.terminal.height_px = self.grid_size.rows * self.cell_size.height; + self.terminal.width_px = grid_size.columns * self.cell_size.width; + self.terminal.height_px = grid_size.rows * self.cell_size.height; // Disable synchronized output mode so that we show changes // immediately for a resize. This is allowed by the spec. @@ -391,8 +389,8 @@ pub fn resize( // Mail the renderer so that it can update the GPU and re-render _ = self.renderer_mailbox.push(.{ .resize = .{ - .screen_size = screen_size, - .padding = padding, + .screen_size = size.screen, + .padding = size.padding, }, }, .{ .forever = {} }); self.renderer_wakeup.notify() catch {}; diff --git a/src/termio/Thread.zig b/src/termio/Thread.zig index 3d316e399..d80046737 100644 --- a/src/termio/Thread.zig +++ b/src/termio/Thread.zig @@ -17,6 +17,7 @@ const builtin = @import("builtin"); const xev = @import("xev"); const crash = @import("../crash/main.zig"); const termio = @import("../termio.zig"); +const renderer = @import("../renderer.zig"); const BlockingQueue = @import("../datastruct/main.zig").BlockingQueue; const Allocator = std.mem.Allocator; @@ -28,7 +29,7 @@ const Coalesce = struct { /// Not all message types are coalesced. const min_ms = 25; - resize: ?termio.Message.Resize = null, + resize: ?renderer.Size = null, }; /// The number of milliseconds before we reset the synchronized output flag @@ -324,7 +325,7 @@ fn startSynchronizedOutput(self: *Thread, cb: *CallbackData) void { ); } -fn handleResize(self: *Thread, cb: *CallbackData, resize: termio.Message.Resize) void { +fn handleResize(self: *Thread, cb: *CallbackData, resize: renderer.Size) void { self.coalesce_data.resize = resize; // If the timer is already active we just return. In the future we want @@ -380,13 +381,7 @@ fn coalesceCallback( if (cb.self.coalesce_data.resize) |v| { cb.self.coalesce_data.resize = null; - cb.io.resize( - &cb.data, - v.grid_size, - v.cell_size, - v.screen_size, - v.padding, - ) catch |err| { + cb.io.resize(&cb.data, v) catch |err| { log.warn("error during resize err={}", .{err}); }; } diff --git a/src/termio/message.zig b/src/termio/message.zig index c88a12f14..44381b228 100644 --- a/src/termio/message.zig +++ b/src/termio/message.zig @@ -16,22 +16,6 @@ pub const Message = union(enum) { /// in the future. pub const WriteReq = MessageData(u8, 38); - pub const Resize = struct { - /// The grid size for the given screen size with padding applied. - grid_size: renderer.GridSize, - - /// The updated cell size. - cell_size: renderer.CellSize, - - /// The full screen (drawable) size. This does NOT include padding. - /// This should be sent on to the renderer. - screen_size: renderer.ScreenSize, - - /// The padding, so that the terminal implementation can subtract - /// this to send to the pty. - padding: renderer.Padding, - }; - /// Purposely crash the renderer. This is used for testing and debugging. /// See the "crash" binding action. crash: void, @@ -47,7 +31,7 @@ pub const Message = union(enum) { inspector: bool, /// Resize the window. - resize: Resize, + resize: renderer.Size, /// Request a size report is sent to the pty ([in-band /// size report, mode 2048](https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83) and