From 14884deba7ff61495a87cd3be91dc620a1eba5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=BCrr?= Date: Mon, 18 Dec 2017 17:49:57 +0100 Subject: [PATCH] Fix faux scrolling for line-based touchpads Touchpads which use line-based instead of pixel-based updates send partial scroll requests, so decimal numbers are important. The current implementation only really used scroll amounts that are either 1 or -1. This has been fixed and now the line-based touchpads should have very smooth scrolling, but the pixel-based approach is still WIP and completely untested. --- src/input.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/input.rs b/src/input.rs index 8f6048f0..c653d486 100644 --- a/src/input.rs +++ b/src/input.rs @@ -373,19 +373,6 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { match delta { MouseScrollDelta::LineDelta(_columns, lines) => { let to_scroll = self.ctx.mouse_mut().lines_scrolled + lines; - - // Faux scrolling - if self.ctx.terminal_mode().intersects(mode::ALT_SCREEN_BUF) { - if to_scroll > 0. { - // Scroll up three lines - self.ctx.write_to_pty("\x1bOA\x1bOA\x1bOA".as_bytes()); - } else { - // Scroll down three lines - self.ctx.write_to_pty("\x1bOB\x1bOB\x1bOB".as_bytes()); - } - return; - } - let code = if to_scroll > 0.0 { 64 } else { @@ -393,8 +380,20 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { }; for _ in 0..(to_scroll.abs() as usize) { - self.normal_mouse_report(code); + if self.ctx.terminal_mode().intersects(mode::ALT_SCREEN_BUF) { + // Faux scrolling + if code == 64 { + // Scroll up one line + self.ctx.write_to_pty("\x1bOA".as_bytes()); + } else { + // Scroll down one line + self.ctx.write_to_pty("\x1bOB".as_bytes()); + } + } else { + self.normal_mouse_report(code); + } } + self.ctx.mouse_mut().lines_scrolled = to_scroll % 1.0; }, MouseScrollDelta::PixelDelta(_x, y) => {