mirror of
https://github.com/alacritty/alacritty.git
synced 2025-04-14 17:53:03 -04:00
Support trackpad scrolling
Linebased scrolling is still unsupported (need a mouse to test with).
This commit is contained in:
parent
90e0a759e8
commit
adf02b5049
2 changed files with 57 additions and 2 deletions
14
src/event.rs
14
src/event.rs
|
@ -96,7 +96,19 @@ impl<N: input::Notify> Processor<N> {
|
|||
glutin::Event::Focused(true) => {
|
||||
let mut terminal = self.terminal.lock();
|
||||
terminal.dirty = true;
|
||||
}
|
||||
},
|
||||
glutin::Event::MouseWheel(scroll_delta, touch_phase) => {
|
||||
let terminal = self.terminal.lock();
|
||||
let processor = &mut self.input_processor;
|
||||
let notifier = &mut self.notifier;
|
||||
|
||||
processor.on_mouse_wheel(
|
||||
notifier,
|
||||
scroll_delta,
|
||||
touch_phase,
|
||||
&terminal
|
||||
);
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
45
src/input.rs
45
src/input.rs
|
@ -28,6 +28,7 @@ use std::borrow::Cow;
|
|||
use copypasta::{Clipboard, Load};
|
||||
use glutin::{ElementState, VirtualKeyCode, MouseButton};
|
||||
use glutin::{Mods, mods};
|
||||
use glutin::{TouchPhase, MouseScrollDelta};
|
||||
|
||||
use index::{Line, Column};
|
||||
use config::Config;
|
||||
|
@ -53,6 +54,7 @@ pub struct Mouse {
|
|||
x: u32,
|
||||
y: u32,
|
||||
left_button_state: ElementState,
|
||||
scroll_px: i32,
|
||||
}
|
||||
|
||||
impl Default for Mouse {
|
||||
|
@ -60,7 +62,8 @@ impl Default for Mouse {
|
|||
Mouse {
|
||||
x: 0,
|
||||
y: 0,
|
||||
left_button_state: ElementState::Pressed
|
||||
left_button_state: ElementState::Pressed,
|
||||
scroll_px: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -288,6 +291,46 @@ impl Processor {
|
|||
self.mouse_report(3, notifier, terminal);
|
||||
}
|
||||
|
||||
pub fn on_mouse_wheel<N: Notify>(
|
||||
&mut self,
|
||||
notifier: &mut N,
|
||||
delta: MouseScrollDelta,
|
||||
phase: TouchPhase,
|
||||
terminal: &Term
|
||||
) {
|
||||
match delta {
|
||||
MouseScrollDelta::LineDelta(_columns, _lines) => {
|
||||
unimplemented!();
|
||||
},
|
||||
MouseScrollDelta::PixelDelta(_x, y) => {
|
||||
match phase {
|
||||
TouchPhase::Started => {
|
||||
// Reset offset to zero
|
||||
self.mouse.scroll_px = 0;
|
||||
},
|
||||
TouchPhase::Moved => {
|
||||
self.mouse.scroll_px += y as i32;
|
||||
let size = terminal.size_info();
|
||||
let height = size.cell_height as i32;
|
||||
|
||||
while self.mouse.scroll_px.abs() >= height {
|
||||
let button = if self.mouse.scroll_px > 0 {
|
||||
self.mouse.scroll_px -= height;
|
||||
64
|
||||
} else {
|
||||
self.mouse.scroll_px += height;
|
||||
65
|
||||
};
|
||||
|
||||
self.mouse_report(button, notifier, terminal);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mouse_input<N: Notify>(
|
||||
&mut self,
|
||||
state: ElementState,
|
||||
|
|
Loading…
Add table
Reference in a new issue