Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: map hover events to their winit equivalents. #3898

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,6 @@ changelog entry.

### Fixed

- On Android, map hover events to their winit equivalents. These events
are required for accessibility.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like an addition, not a "bugfix".

- On Orbital, `MonitorHandle::name()` now returns `None` instead of a dummy name.
33 changes: 32 additions & 1 deletion src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction};
use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction, MotionEvent};
use android_activity::{
AndroidApp, AndroidAppWaker, ConfigurationRef, InputStatus, MainEvent, Rect,
};
Expand Down Expand Up @@ -306,6 +306,20 @@ impl EventLoop {
self.pending_redraw = pending_redraw;
}

fn handle_cursor_moved_event<A: ApplicationHandler>(
&self,
event: &MotionEvent<'_>,
window_id: window::WindowId,
device_id: event::DeviceId,
app: &mut A,
) {
let pointer = event.pointer_at_index(event.pointer_index());
let position = PhysicalPosition { x: pointer.x() as _, y: pointer.y() as _ };
trace!("Input event {device_id:?}, CursorMoved, pos={position:?}");
let event = event::WindowEvent::CursorMoved { device_id, position };
app.window_event(&self.window_target, window_id, event);
}

fn handle_input_event<A: ApplicationHandler>(
&mut self,
android_app: &AndroidApp,
Expand All @@ -325,6 +339,23 @@ impl EventLoop {
MotionAction::Up | MotionAction::PointerUp => Some(event::TouchPhase::Ended),
MotionAction::Move => Some(event::TouchPhase::Moved),
MotionAction::Cancel => Some(event::TouchPhase::Cancelled),
MotionAction::HoverMove => {
self.handle_cursor_moved_event(motion_event, window_id, device_id, app);
None
},
MotionAction::HoverEnter => {
trace!("Input event {device_id:?}, CursorEntered");
let event = event::WindowEvent::CursorEntered { device_id };
app.window_event(&self.window_target, window_id, event);
self.handle_cursor_moved_event(motion_event, window_id, device_id, app);
None
},
MotionAction::HoverExit => {
trace!("Input event {device_id:?}, CursorLeft");
let event = event::WindowEvent::CursorLeft { device_id };
app.window_event(&self.window_target, window_id, event);
None
},
_ => {
None // TODO mouse events
},
Expand Down