Fix ignoring of slow touchpad scrolling

Fixes #3377.
This commit is contained in:
Timo 2020-03-02 06:32:18 +01:00 committed by GitHub
parent 1972cce8a4
commit f83d55f0f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 16 deletions

View File

@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Tabstops cleared on resize - Tabstops cleared on resize
- Tabstops not breaking across lines - Tabstops not breaking across lines
- Crash when parsing DCS escape with more than 16 parameters - Crash when parsing DCS escape with more than 16 parameters
- Ignoring of slow touchpad scrolling
### Removed ### Removed

View File

@ -272,7 +272,7 @@ pub struct Mouse {
pub right_button_state: ElementState, pub right_button_state: ElementState,
pub last_click_timestamp: Instant, pub last_click_timestamp: Instant,
pub click_state: ClickState, pub click_state: ClickState,
pub scroll_px: i32, pub scroll_px: f64,
pub line: Line, pub line: Line,
pub column: Column, pub column: Column,
pub cell_side: Side, pub cell_side: Side,
@ -292,11 +292,11 @@ impl Default for Mouse {
middle_button_state: ElementState::Released, middle_button_state: ElementState::Released,
right_button_state: ElementState::Released, right_button_state: ElementState::Released,
click_state: ClickState::None, click_state: ClickState::None,
scroll_px: 0, scroll_px: 0.,
line: Line(0), line: Line(0),
column: Column(0), column: Column(0),
cell_side: Side::Left, cell_side: Side::Left,
lines_scrolled: 0.0, lines_scrolled: 0.,
block_url_launcher: false, block_url_launcher: false,
last_button: MouseButton::Other(0), last_button: MouseButton::Other(0),
inside_grid: false, inside_grid: false,

View File

@ -469,16 +469,16 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
match delta { match delta {
MouseScrollDelta::LineDelta(_columns, lines) => { MouseScrollDelta::LineDelta(_columns, lines) => {
let new_scroll_px = lines * self.ctx.size_info().cell_height; let new_scroll_px = lines * self.ctx.size_info().cell_height;
self.scroll_terminal(new_scroll_px as i32); self.scroll_terminal(new_scroll_px as f64);
}, },
MouseScrollDelta::PixelDelta(lpos) => { MouseScrollDelta::PixelDelta(lpos) => {
match phase { match phase {
TouchPhase::Started => { TouchPhase::Started => {
// Reset offset to zero // Reset offset to zero
self.ctx.mouse_mut().scroll_px = 0; self.ctx.mouse_mut().scroll_px = 0.;
}, },
TouchPhase::Moved => { TouchPhase::Moved => {
self.scroll_terminal(lpos.y as i32); self.scroll_terminal(lpos.y);
}, },
_ => (), _ => (),
} }
@ -486,14 +486,14 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
} }
} }
fn scroll_terminal(&mut self, new_scroll_px: i32) { fn scroll_terminal(&mut self, new_scroll_px: f64) {
let height = self.ctx.size_info().cell_height as i32; let height = self.ctx.size_info().cell_height as f64;
if self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) { if self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) {
self.ctx.mouse_mut().scroll_px += new_scroll_px; self.ctx.mouse_mut().scroll_px += new_scroll_px;
let code = if new_scroll_px > 0 { 64 } else { 65 }; let code = if new_scroll_px > 0. { 64 } else { 65 };
let lines = (self.ctx.mouse().scroll_px / height).abs(); let lines = (self.ctx.mouse().scroll_px / height).abs() as i32;
for _ in 0..lines { for _ in 0..lines {
self.mouse_report(code, ElementState::Pressed); self.mouse_report(code, ElementState::Pressed);
@ -505,7 +505,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
.contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL) .contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL)
&& !self.ctx.modifiers().shift() && !self.ctx.modifiers().shift()
{ {
let multiplier = i32::from( let multiplier = f64::from(
self.ctx self.ctx
.config() .config()
.scrolling .scrolling
@ -514,8 +514,8 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
); );
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier; self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
let cmd = if new_scroll_px > 0 { b'A' } else { b'B' }; let cmd = if new_scroll_px > 0. { b'A' } else { b'B' };
let lines = (self.ctx.mouse().scroll_px / height).abs(); let lines = (self.ctx.mouse().scroll_px / height).abs() as i32;
let mut content = Vec::with_capacity(lines as usize * 3); let mut content = Vec::with_capacity(lines as usize * 3);
for _ in 0..lines { for _ in 0..lines {
@ -525,7 +525,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
} }
self.ctx.write_to_pty(content); self.ctx.write_to_pty(content);
} else { } else {
let multiplier = i32::from(self.ctx.config().scrolling.multiplier()); let multiplier = f64::from(self.ctx.config().scrolling.multiplier());
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier; self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
let lines = self.ctx.mouse().scroll_px / height; let lines = self.ctx.mouse().scroll_px / height;
@ -953,8 +953,8 @@ mod tests {
height: 51.0, height: 51.0,
cell_width: 3.0, cell_width: 3.0,
cell_height: 3.0, cell_height: 3.0,
padding_x: 0.0, padding_x: 0.,
padding_y: 0.0, padding_y: 0.,
dpr: 1.0, dpr: 1.0,
}; };