From 5700359a617d42b3674d59fe45fd19ed3676595d Mon Sep 17 00:00:00 2001 From: Max de Danschutter <43446207+maxded@users.noreply.github.com> Date: Sat, 28 Nov 2020 17:41:11 +0100 Subject: [PATCH] Android: support multi-touch (#1776) --- CHANGELOG.md | 3 +- src/platform_impl/android/mod.rs | 54 ++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaeebeaf..c588aceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ # Unreleased -- On Windows, fix bug causing message boxes to appear delayed. - On Android, calling `WindowEvent::Focused` now works properly instead of always returning false. - On Windows, fix alt-tab behaviour by removing borderless fullscreen "always on top" flag. - On Windows, fix bug preventing windows with transparency enabled from having fully-opaque regions. @@ -17,6 +16,8 @@ - **Breaking:** On macOS, removed `WindowExt::request_user_attention`, use `Window::request_user_attention`. - **Breaking:** On X11, removed `WindowExt::set_urgent`, use `Window::request_user_attention`. - On Wayland, default font size in CSD increased from 11 to 17. +- On Windows, fix bug causing message boxes to appear delayed. +- On Android, support multi-touch. # 0.23.0 (2020-10-02) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index eae00d19..ddd1eb96 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -181,37 +181,45 @@ impl EventLoop { match &event { InputEvent::MotionEvent(motion_event) => { let phase = match motion_event.action() { - MotionAction::Down => Some(event::TouchPhase::Started), - MotionAction::Up => Some(event::TouchPhase::Ended), + MotionAction::Down | MotionAction::PointerDown => { + Some(event::TouchPhase::Started) + } + MotionAction::Up | MotionAction::PointerUp => { + Some(event::TouchPhase::Ended) + } MotionAction::Move => Some(event::TouchPhase::Moved), MotionAction::Cancel => { Some(event::TouchPhase::Cancelled) } _ => None, // TODO mouse events }; - let pointer = motion_event.pointer_at_index(0); - let location = PhysicalPosition { - x: pointer.x() as _, - y: pointer.y() as _, - }; if let Some(phase) = phase { - let event = event::Event::WindowEvent { - window_id, - event: event::WindowEvent::Touch(event::Touch { - device_id, - phase, - location, - id: 0, - force: None, - }), - }; - call_event_handler!( - event_handler, - self.window_target(), - control_flow, - event - ); + for pointer in motion_event.pointers() { + let location = PhysicalPosition { + x: pointer.x() as _, + y: pointer.y() as _, + }; + + let event = event::Event::WindowEvent { + window_id, + event: event::WindowEvent::Touch( + event::Touch { + device_id, + phase, + location, + id: pointer.pointer_id() as u64, + force: None, + }, + ), + }; + call_event_handler!( + event_handler, + self.window_target(), + control_flow, + event + ); + } } } InputEvent::KeyEvent(_) => {} // TODO