aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-11-24 19:50:34 -0800
committerJoe Wilm <joe@jwilm.com>2016-12-11 20:23:41 -0800
commitadf02b5049f644e56033834e948481f199e6bb6a (patch)
treed8d5024e695ce6348b005118e58fc11686ae81e4 /src
parent90e0a759e8e55952ada459914f9958d50eab04fe (diff)
downloadalacritty-adf02b5049f644e56033834e948481f199e6bb6a.tar.gz
alacritty-adf02b5049f644e56033834e948481f199e6bb6a.zip
Support trackpad scrolling
Linebased scrolling is still unsupported (need a mouse to test with).
Diffstat (limited to 'src')
-rw-r--r--src/event.rs14
-rw-r--r--src/input.rs45
2 files changed, 57 insertions, 2 deletions
diff --git a/src/event.rs b/src/event.rs
index b220ae2c..2656db72 100644
--- a/src/event.rs
+++ b/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
+ );
+ },
_ => (),
}
}
diff --git a/src/input.rs b/src/input.rs
index 2e90ee20..e266dbbc 100644
--- a/src/input.rs
+++ b/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,