From 306acc7a2e366d169a504eeff83e5fbc5e359b66 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 11 Oct 2024 12:07:17 -0500 Subject: [PATCH] tty(posix): remove signal handler when we have in-band-resize --- src/Loop.zig | 6 ++++++ src/posix/Tty.zig | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Loop.zig b/src/Loop.zig index 3a09cf7..a3d24bf 100644 --- a/src/Loop.zig +++ b/src/Loop.zig @@ -301,6 +301,12 @@ pub fn handleEventGeneric(self: anytype, vx: *Vaxis, cache: *GraphemeCache, Even if (@hasField(Event, "winsize")) { return self.postEvent(.{ .winsize = winsize }); } + + switch (builtin.os.tag) { + .windows => {}, + // Reset the signal handler if we are receiving in_band_resize + else => self.tty.resetSignalHandler(), + } }, } }, diff --git a/src/posix/Tty.zig b/src/posix/Tty.zig index aa03b78..7c9eed9 100644 --- a/src/posix/Tty.zig +++ b/src/posix/Tty.zig @@ -23,6 +23,8 @@ var handlers: [8]SignalHandler = undefined; var handler_mutex: std.Thread.Mutex = .{}; var handler_idx: usize = 0; +var handler_installed: bool = false; + /// global tty instance, used in case of a panic. Not guaranteed to work if /// for some reason there are multiple TTYs open under a single vaxis /// compilation unit - but this is better than nothing @@ -49,6 +51,7 @@ pub fn init() !Posix { .flags = 0, }; try posix.sigaction(posix.SIG.WINCH, &act, null); + handler_installed = true; const self: Posix = .{ .fd = fd, @@ -69,6 +72,23 @@ pub fn deinit(self: Posix) void { posix.close(self.fd); } +/// Resets the signal handler to it's default +pub fn resetSignalHandler() void { + if (!handler_installed) return; + handler_installed = false; + var act = posix.Sigaction{ + .handler = posix.SIG.DFL, + .mask = switch (builtin.os.tag) { + .macos => 0, + .linux => posix.empty_sigset, + .freebsd => posix.empty_sigset, + else => @compileError("os not supported"), + }, + .flags = 0, + }; + posix.sigaction(posix.SIG.WINCH, &act, null) catch {}; +} + /// Write bytes to the tty pub fn write(self: *const Posix, bytes: []const u8) !usize { return posix.write(self.fd, bytes); -- knotmirror 0.0.1