From 7886ff9acdbc4961359725536c1a15e2cbb3d4f5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 2 Mar 2016 16:13:13 -0800 Subject: [PATCH] Add phases to wheel events. Needed for apps to support overscroll on the Mac. --- src/api/cocoa/mod.rs | 13 +++++++++---- src/api/wayland/events.rs | 6 ++++-- src/api/win32/callback.rs | 3 ++- src/api/x11/input.rs | 5 +++-- src/events.rs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index abcd7354..db3f7498 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -42,10 +42,10 @@ use std::sync::Mutex; use std::ascii::AsciiExt; use std::ops::Deref; -use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed, Focused, TouchpadPressure}; use events::ElementState::{Pressed, Released}; -use events::MouseButton; -use events; +use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput}; +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::headless::HeadlessContext; @@ -891,7 +891,12 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option { LineDelta(scale_factor * nsevent.scrollingDeltaX() 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 => { Some(TouchpadPressure(nsevent.pressure(), nsevent.stage())) diff --git a/src/api/wayland/events.rs b/src/api/wayland/events.rs index 8b180205..5e0c3fd0 100644 --- a/src/api/wayland/events.rs +++ b/src/api/wayland/events.rs @@ -1,5 +1,6 @@ use std::collections::HashSet; +use TouchPhase; use Event as GlutinEvent; use ElementState; use MouseButton; @@ -98,7 +99,8 @@ pub fn translate_event( WlPointerAxis::HorizontalScroll => { MouseScrollDelta::PixelDelta(0.0, amplitude as f32) } - } + }, + TouchPhase::Moved ), surface)) } else { None @@ -107,4 +109,4 @@ pub fn translate_event( }, _ => None } -} \ No newline at end of file +} diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index 0215c9f9..2d10699d 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -134,12 +134,13 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, winapi::WM_MOUSEWHEEL => { use events::Event::MouseWheel; use events::MouseScrollDelta::LineDelta; + use events::TouchPhase; let value = (wparam >> 16) as i16; let value = value as i32; 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 }, diff --git a/src/api/x11/input.rs b/src/api/x11/input.rs index 2ebc9897..a05b22e1 100644 --- a/src/api/x11/input.rs +++ b/src/api/x11/input.rs @@ -201,7 +201,7 @@ impl XInputEventHandler { } else { -1.0 }; - Some(MouseWheel(LineDelta(0.0, delta))) + Some(MouseWheel(LineDelta(0.0, delta), TouchPhase::Moved)) } else { // emulated button event from a touch/smooth-scroll // 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 { - 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 { let new_cursor_pos = (event_data.event_x, event_data.event_y); if new_cursor_pos != self.current_state.cursor_pos { diff --git a/src/events.rs b/src/events.rs index ecc10418..8049c167 100644 --- a/src/events.rs +++ b/src/events.rs @@ -31,7 +31,7 @@ pub enum Event { MouseMoved((i32, i32)), /// A mouse wheel movement or touchpad scroll occurred. - MouseWheel(MouseScrollDelta), + MouseWheel(MouseScrollDelta, TouchPhase), /// An event from the mouse has been received. MouseInput(ElementState, MouseButton),