From 4d462296525a02849948711c704042c1fc9a0550 Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Sat, 1 Jul 2023 14:43:40 +0200 Subject: [PATCH] Use the precision calculation to determine when to send mouse events --- src/Surface.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index d557482f9..1943ffe58 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1337,6 +1337,7 @@ pub fn scrollCallback( self.mouse.pending_scroll_y = poff - (amount * cell_size); break :y .{ + .sign = if (yoff > 0) 1 else -1, .delta_unsigned = @intFromFloat(@fabs(amount)), .delta = @intFromFloat(amount), }; @@ -1420,13 +1421,13 @@ pub fn scrollCallback( // If we're scrolling up or down, then send a mouse event. This requires // a lock since we read terminal state. - if (yoff != 0) { + if (y.delta != 0) { const pos = try self.rt_surface.getCursorPos(); - try self.mouseReport(if (yoff < 0) .five else .four, .press, self.mouse.mods, pos); + try self.mouseReport(if (y.sign < 0) .five else .four, .press, self.mouse.mods, pos); } - if (xoff != 0) { + if (x.delta != 0) { const pos = try self.rt_surface.getCursorPos(); - try self.mouseReport(if (xoff > 0) .six else .seven, .press, self.mouse.mods, pos); + try self.mouseReport(if (x.delta > 0) .six else .seven, .press, self.mouse.mods, pos); } }