Merge pull request #735 from metajack/overscroll-tomaka

Add phases to wheel events.
This commit is contained in:
Paul Rouget 2016-03-04 01:28:43 +01:00
commit e843206c13
5 changed files with 19 additions and 10 deletions

View file

@ -42,10 +42,10 @@ use std::sync::Mutex;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::ops::Deref; use std::ops::Deref;
use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused, TouchpadPressure};
use events::ElementState::{Pressed, Released}; use events::ElementState::{Pressed, Released};
use events::MouseButton; use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput};
use events; use events::Event::{MouseWheel, Closed, Focused, TouchpadPressure};
use events::{self, MouseButton, TouchPhase};
pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor}; pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
pub use self::headless::HeadlessContext; pub use self::headless::HeadlessContext;
@ -891,7 +891,12 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
LineDelta(scale_factor * nsevent.scrollingDeltaX() as f32, LineDelta(scale_factor * nsevent.scrollingDeltaX() as f32,
scale_factor * nsevent.scrollingDeltaY() as f32) scale_factor * nsevent.scrollingDeltaY() as f32)
}; };
Some(MouseWheel(delta)) let phase = match nsevent.phase() {
NSEventPhaseMayBegin | NSEventPhaseBegan => TouchPhase::Started,
NSEventPhaseEnded => TouchPhase::Ended,
_ => TouchPhase::Moved,
};
Some(MouseWheel(delta, phase))
}, },
NSEventTypePressure => { NSEventTypePressure => {
Some(TouchpadPressure(nsevent.pressure(), nsevent.stage())) Some(TouchpadPressure(nsevent.pressure(), nsevent.stage()))

View file

@ -1,5 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use TouchPhase;
use Event as GlutinEvent; use Event as GlutinEvent;
use ElementState; use ElementState;
use MouseButton; use MouseButton;
@ -98,7 +99,8 @@ pub fn translate_event(
WlPointerAxis::HorizontalScroll => { WlPointerAxis::HorizontalScroll => {
MouseScrollDelta::PixelDelta(0.0, amplitude as f32) MouseScrollDelta::PixelDelta(0.0, amplitude as f32)
} }
} },
TouchPhase::Moved
), surface)) ), surface))
} else { } else {
None None
@ -107,4 +109,4 @@ pub fn translate_event(
}, },
_ => None _ => None
} }
} }

View file

@ -134,12 +134,13 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
winapi::WM_MOUSEWHEEL => { winapi::WM_MOUSEWHEEL => {
use events::Event::MouseWheel; use events::Event::MouseWheel;
use events::MouseScrollDelta::LineDelta; use events::MouseScrollDelta::LineDelta;
use events::TouchPhase;
let value = (wparam >> 16) as i16; let value = (wparam >> 16) as i16;
let value = value as i32; let value = value as i32;
let value = value as f32 / winapi::WHEEL_DELTA as f32; let value = value as f32 / winapi::WHEEL_DELTA as f32;
send_event(window, MouseWheel(LineDelta(0.0, value))); send_event(window, MouseWheel(LineDelta(0.0, value), TouchPhase::Moved));
0 0
}, },

View file

@ -201,7 +201,7 @@ impl XInputEventHandler {
} else { } else {
-1.0 -1.0
}; };
Some(MouseWheel(LineDelta(0.0, delta))) Some(MouseWheel(LineDelta(0.0, delta), TouchPhase::Moved))
} else { } else {
// emulated button event from a touch/smooth-scroll // emulated button event from a touch/smooth-scroll
// event. Ignore these events and handle scrolling // event. Ignore these events and handle scrolling
@ -235,7 +235,8 @@ impl XInputEventHandler {
} }
if scroll_delta.0.abs() > 0.0 || scroll_delta.1.abs() > 0.0 { if scroll_delta.0.abs() > 0.0 || scroll_delta.1.abs() > 0.0 {
Some(MouseWheel(LineDelta(scroll_delta.0 as f32, scroll_delta.1 as f32))) Some(MouseWheel(LineDelta(scroll_delta.0 as f32, scroll_delta.1 as f32),
TouchPhase::Moved))
} else { } else {
let new_cursor_pos = (event_data.event_x, event_data.event_y); let new_cursor_pos = (event_data.event_x, event_data.event_y);
if new_cursor_pos != self.current_state.cursor_pos { if new_cursor_pos != self.current_state.cursor_pos {

View file

@ -31,7 +31,7 @@ pub enum Event {
MouseMoved((i32, i32)), MouseMoved((i32, i32)),
/// A mouse wheel movement or touchpad scroll occurred. /// A mouse wheel movement or touchpad scroll occurred.
MouseWheel(MouseScrollDelta), MouseWheel(MouseScrollDelta, TouchPhase),
/// An event from the mouse has been received. /// An event from the mouse has been received.
MouseInput(ElementState, MouseButton), MouseInput(ElementState, MouseButton),