feat: avoid sigwinch handling if we detect in band resize capability

This commit is contained in:
CJ van den Berg 2024-08-07 21:45:50 +02:00
parent 3816ec2327
commit 9b00805546
2 changed files with 17 additions and 15 deletions

View file

@ -103,8 +103,11 @@ pub fn run(self: *Self) !void {
panic_cleanup = .{ .a = self.a, .tty = &self.tty, .vx = &self.vx };
if (!self.no_alternate) try self.vx.enterAltScreen(self.tty.anyWriter());
try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis
try self.query_resize();
if (builtin.os.tag == .windows) {
try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis
} else {
try self.sigwinch();
}
try self.vx.setBracketedPaste(self.tty.anyWriter(), true);
try self.vx.queryTerminalSend(self.tty.anyWriter());
@ -118,9 +121,9 @@ pub fn render(self: *Self) !void {
try bufferedWriter.flush();
}
pub fn query_resize(self: *Self) !void {
if (builtin.os.tag != .windows)
try self.resize(try vaxis.Tty.getWinsize(self.input_fd_blocking()));
pub fn sigwinch(self: *Self) !void {
if (builtin.os.tag == .windows or self.vx.state.in_band_resize) return;
try self.resize(try vaxis.Tty.getWinsize(self.input_fd_blocking()));
}
fn resize(self: *Self, ws: vaxis.Winsize) !void {
@ -244,7 +247,13 @@ pub fn process_input_event(self: *Self, input_: []const u8, text: ?[]const u8) !
},
.color_report => {},
.color_scheme => {},
.winsize => |ws| try self.resize(ws),
.winsize => |ws| {
if (!self.vx.state.in_band_resize) {
self.vx.state.in_band_resize = true;
self.logger.print("in band resize capability detected", .{});
}
try self.resize(ws);
},
.cap_unicode => {
self.logger.print("unicode capability detected", .{});
@ -463,11 +472,6 @@ const Loop = struct {
}
},
else => {
const winsize = try vaxis.Tty.getWinsize(self.tty.fd);
if (@hasField(Event, "winsize")) {
self.postEvent(.{ .winsize = winsize });
}
var parser: vaxis.Parser = .{
.grapheme_data = &self.vaxis.unicode.grapheme_data,
};
@ -497,8 +501,6 @@ const Loop = struct {
continue;
}
if (result.event) |event| {
if (event == .winsize)
self.vaxis.state.in_band_resize = true;
self.postEvent(event);
}
if (result.n < n) {

View file

@ -54,7 +54,7 @@ final_exit: []const u8 = "normal",
render_pending: bool = false,
keepalive_timer: ?tp.Cancellable = null,
const keepalive = std.time.us_per_s * 60 * 60 * 24 * 356; // one year
const keepalive = std.time.us_per_day * 365; // one year
const idle_frames = 0;
const init_delay = 1; // ms
@ -233,7 +233,7 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
if (builtin.os.tag != .windows)
if (try m.match(.{"sigwinch"})) {
try self.listen_sigwinch();
self.rdr.query_resize() catch |e| return self.logger.err("query_resize", e);
self.rdr.sigwinch() catch |e| return self.logger.err("query_resize", e);
return;
};