From 8694d29bd09517205ed849977399ba87da2b6e13 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 17 Sep 2023 09:39:03 -0700 Subject: [PATCH 1/2] terminal: ignore CSI S with intermediates --- src/terminal/stream.zig | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 824d08ffa..3789d5611 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -300,16 +300,24 @@ pub fn Stream(comptime Handler: type) type { ) else log.warn("unimplemented CSI callback: {}", .{action}), // Scroll Up (SD) - 'S' => if (@hasDecl(T, "scrollUp")) try self.handler.scrollUp( - switch (action.params.len) { - 0 => 1, - 1 => action.params[0], - else => { - log.warn("invalid scroll up command: {}", .{action}); - return; + + 'S' => switch (action.intermediates.len) { + 0 => if (@hasDecl(T, "scrollUp")) try self.handler.scrollUp( + switch (action.params.len) { + 0 => 1, + 1 => action.params[0], + else => { + log.warn("invalid scroll up command: {}", .{action}); + return; + }, }, - }, - ) else log.warn("unimplemented CSI callback: {}", .{action}), + ) else log.warn("unimplemented CSI callback: {}", .{action}), + + else => log.warn( + "ignoring unimplemented CSI S with intermediates: {s}", + .{action.intermediates}, + ), + }, // Scroll Down (SD) 'T' => if (@hasDecl(T, "scrollDown")) try self.handler.scrollDown( From dd85f6c41d3b9d7f62876ce41755bf756e45154c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 17 Sep 2023 09:56:26 -0700 Subject: [PATCH 2/2] core: do not emit mouse report events if position is outside surface --- src/Surface.zig | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 465d12122..707e69104 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1283,8 +1283,11 @@ fn mouseReport( mods: input.Mods, pos: apprt.CursorPos, ) !void { - // TODO: posToViewport currently clamps to the surface boundary, - // do we want to not report mouse events at all outside the surface? + // The maximum pos values so we can determine if we're outside the window. + // If we're outside the window, we do not report mouse events. + const max_x: f32 = @floatFromInt(self.screen_size.width); + const max_y: f32 = @floatFromInt(self.screen_size.height); + if (pos.x < 0 or pos.y < 0 or pos.x > max_x or pos.y > max_y) return; // Depending on the event, we may do nothing at all. switch (self.io.terminal.flags.mouse_event) { @@ -1444,6 +1447,9 @@ fn mouseReport( }, .sgr_pixels => { + assert(pos.x >= 0); + assert(pos.y >= 0); + // Final character to send in the CSI const final: u8 = if (action == .release) 'm' else 'M'; @@ -1452,8 +1458,8 @@ fn mouseReport( var data: termio.Message.WriteReq.Small.Array = undefined; const resp = try std.fmt.bufPrint(&data, "\x1B[<{d};{d};{d}{c}", .{ button_code, - pos.x, - pos.y, + @as(u32, @intFromFloat(@round(pos.x))), + @as(u32, @intFromFloat(@round(pos.y))), final, });