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 not breaking across lines
- Crash when parsing DCS escape with more than 16 parameters
- Ignoring of slow touchpad scrolling
### Removed

View File

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

View File

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