From f2f2b1eaf16502dc4d38aec3cb4bb45058e5cccc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 24 Aug 2023 08:45:32 -0700 Subject: [PATCH] termio/exec: initial subprocess screen size should be sub padding --- src/Surface.zig | 1 + src/terminal/kitty/graphics_exec.zig | 4 ++-- src/termio/Exec.zig | 15 ++++++++++----- src/termio/Options.zig | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index d60f4c620..004a2c987 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -401,6 +401,7 @@ pub fn init( var io = try termio.Impl.init(alloc, .{ .grid_size = grid_size, .screen_size = screen_size, + .padding = padding, .full_config = config, .config = try termio.Impl.DerivedConfig.init(alloc, config), .resources_dir = app.resources_dir, diff --git a/src/terminal/kitty/graphics_exec.zig b/src/terminal/kitty/graphics_exec.zig index 5b3454f9b..0415722b6 100644 --- a/src/terminal/kitty/graphics_exec.zig +++ b/src/terminal/kitty/graphics_exec.zig @@ -222,14 +222,14 @@ fn display( // We can do better by doing this with pure internal screen state // but this handles scroll regions. - const height = rect.bottom_right.y - rect.top_left.y + 1; + const height = rect.bottom_right.y - rect.top_left.y; for (0..height) |_| terminal.index() catch |err| { log.warn("failed to move cursor: {}", .{err}); break; }; terminal.setCursorPos( - terminal.screen.cursor.y + 1, + terminal.screen.cursor.y, rect.bottom_right.x + 1, ); }, diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 91d95062a..35a74c837 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -105,8 +105,6 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec { ); errdefer term.deinit(alloc); term.color_palette = opts.config.palette; - term.width_px = opts.screen_size.width; - term.height_px = opts.screen_size.height; // Set the image size limits try term.screen.kitty_images.setLimit(alloc, opts.config.image_storage_limit); @@ -115,6 +113,10 @@ pub fn init(alloc: Allocator, opts: termio.Options) !Exec { var subprocess = try Subprocess.init(alloc, opts); errdefer subprocess.deinit(); + // Initial width/height based on subprocess + term.width_px = subprocess.screen_size.width; + term.height_px = subprocess.screen_size.height; + return Exec{ .alloc = alloc, .terminal = term, @@ -289,8 +291,8 @@ pub fn resize( ); // Update our pixel sizes - self.terminal.width_px = screen_size.width; - self.terminal.height_px = screen_size.height; + self.terminal.width_px = padded_size.width; + self.terminal.height_px = padded_size.height; } } @@ -682,6 +684,9 @@ const Subprocess = struct { log.warn("shell could not be detected, no automatic shell integration will be injected", .{}); } + // Our screen size should be our padded size + const padded_size = opts.screen_size.subPadding(opts.padding); + return .{ .arena = arena, .env = env, @@ -689,7 +694,7 @@ const Subprocess = struct { .path = final_path, .args = args, .grid_size = opts.grid_size, - .screen_size = opts.screen_size, + .screen_size = padded_size, }; } diff --git a/src/termio/Options.zig b/src/termio/Options.zig index cad5d5665..1fd9d034a 100644 --- a/src/termio/Options.zig +++ b/src/termio/Options.zig @@ -12,6 +12,9 @@ grid_size: renderer.GridSize, /// 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 memory it points to is NOT stable after the init call so any values /// in here must be copied.