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: Improved multi-touch #1783

Merged
merged 7 commits into from Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 43 additions & 43 deletions FEATURES.md
Expand Up @@ -166,61 +166,61 @@ Legend:
- ❓: Unknown status

### Windowing
|Feature |Windows|MacOS |Linux x11 |Linux Wayland |Android|iOS |WASM |
|-------------------------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|Window initialization |✔️ |✔️ |▢[#5] |✔️ |▢[#33]|▢[#33] |✔️ |
|Providing pointer to init OpenGL |✔️ |✔️ |✔️ |✔️ |✔️ |✔️ |**N/A**|
|Providing pointer to init Vulkan |✔️ |✔️ |✔️ |✔️ |✔️ ||**N/A**|
|Window decorations |✔️ |✔️ |✔️ |▢[#306] |**N/A**|**N/A**|**N/A**|
|Window decorations toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|Window resizing |✔️ |▢[#219]|✔️ |▢[#306] |**N/A**|**N/A**|✔️ |
|Window resize increments |❌ ||❌ |❌ |❌ ||**N/A**|
|Window transparency |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|N/A |
|Window maximization |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|Window maximization toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|Window minimization |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|Fullscreen |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |✔️ |
|Fullscreen toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |✔️ |
|Exclusive fullscreen |✔️ |✔️ |✔️ |**N/A** ||✔️ |**N/A**|
|HiDPI support |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |✔️ \*1|
|Popup windows |❌ ||❌ |❌ |❌ ||**N/A**|
| Feature | Windows | MacOS | Linux x11 | Linux Wayland | Android | iOS | WASM |
francesca64 marked this conversation as resolved.
Show resolved Hide resolved
| -------------------------------- | ------- | ------- | --------- | ------------- | ------- | ------- | ------- |
| Window initialization | ✔️ | ✔️ | ▢[#5] | ✔️ | ▢[#33] | ▢[#33] | ✔️ |
| Providing pointer to init OpenGL | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** |
| Providing pointer to init Vulkan | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | **N/A** |
| Window decorations | ✔️ | ✔️ | ✔️ | ▢[#306] | **N/A** | **N/A** | **N/A** |
| Window decorations toggle | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | **N/A** | **N/A** |
| Window resizing | ✔️ | ▢[#219] | ✔️ | ▢[#306] | **N/A** | **N/A** | ✔️ |
| Window resize increments | | | ❌ | ❌ | | | **N/A** |
| Window transparency | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | **N/A** | N/A |
| Window maximization | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | **N/A** | **N/A** |
| Window maximization toggle | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | **N/A** | **N/A** |
| Window minimization | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | **N/A** | **N/A** |
| Fullscreen | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | ✔️ | ✔️ |
| Fullscreen toggle | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | ✔️ | ✔️ |
| Exclusive fullscreen | ✔️ | ✔️ | ✔️ | **N/A** | | ✔️ | **N/A** |
| HiDPI support | ✔️ | ✔️ | ✔️ | ✔️ | ▢[#721] | ✔️ | ✔️ \*1 |
| Popup windows | | | ❌ | ❌ | | | **N/A** |

\*1: `WindowEvent::ScaleFactorChanged` is not sent on `stdweb` backend.

### System information
|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|---------------- | ----- | ---- | ------- | ----------- | ----- | ------- | -------- |
|Monitor list |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |**N/A**|
|Video mode query |✔️ |✔️ |✔️ |✔️ ||✔️ |**N/A**|
| Feature | Windows | MacOS | Linux x11 | Linux Wayland | Android | iOS | WASM |
| ---------------- | ------- | ----- | --------- | ------------- | ------- | --- | ------- |
| Monitor list | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | ✔️ | **N/A** |
| Video mode query | ✔️ | ✔️ | ✔️ | ✔️ | | ✔️ | **N/A** |

### Input handling
|Feature |Windows |MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|----------------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|Mouse events |✔️ |▢[#63] |✔️ |✔️ |**N/A**|**N/A**|✔️ |
|Mouse set location |✔️ |✔️ |✔️ ||**N/A**|**N/A**|**N/A**|
|Cursor grab |✔️ |▢[#165] |▢[#242] |✔️ |**N/A**|**N/A**|❓ |
|Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ |
|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |❌ |
|Touch pressure |✔️ |❌ ||||✔️ |❌ |
|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |❌ |
|Keyboard events |✔️ |✔️ |✔️ |✔️ |||✔️ |
|Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ |
|Raw Device Events |▢[#750] |▢[#750] |▢[#750] ||||❓ |
|Gamepad/Joystick events |❌[#804] |❌ |||||❓ |
|Device movement events |❓ |❓ |❓ ||||❓ |
| Feature | Windows | MacOS | Linux x11 | Linux Wayland | Android | iOS | WASM |
| ----------------------- | ------- | ------- | --------- | ------------- | ------- | ------- | ------- |
| Mouse events | ✔️ | ▢[#63] | ✔️ | ✔️ | **N/A** | **N/A** | ✔️ |
| Mouse set location | ✔️ | ✔️ | ✔️ | | **N/A** | **N/A** | **N/A** |
| Cursor grab | ✔️ | ▢[#165] | ▢[#242] | ✔️ | **N/A** | **N/A** | ❓ |
| Cursor icon | ✔️ | ✔️ | ✔️ | ✔️ | **N/A** | **N/A** | ✔️ |
| Touch events | ✔️ | | ✔️ | ✔️ | ✔️ | ✔️ | ❌ |
| Touch pressure | ✔️ | | | | | ✔️ | ❌ |
| Multitouch | ✔️ | | ✔️ | ✔️ | ✔️ | ✔️ | ❌ |
| Keyboard events | ✔️ | ✔️ | ✔️ | ✔️ | | | ✔️ |
| Drag & Drop | ▢[#720] | ▢[#720] | ▢[#720] | ❌[#306] | **N/A** | **N/A** | ❓ |
| Raw Device Events | ▢[#750] | ▢[#750] | ▢[#750] | | | | ❓ |
| Gamepad/Joystick events | ❌[#804] | | | | | | ❓ |
| Device movement events | | ❓ | | | | | ❓ |

### Pending API Reworks
Changes in the API that have been agreed upon but aren't implemented across all platforms.

|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|------------------------------ | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|New API for HiDPI ([#315] [#319]) |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |❓ |
|Event Loop 2.0 ([#459]) |✔️ |✔️ ||✔️ ||✔️ |❓ |
|Keyboard Input ([#812]) ||||❌ |❌ ||❓ |
| Feature | Windows | MacOS | Linux x11 | Linux Wayland | Android | iOS | WASM |
| --------------------------------- | ------- | ----- | --------- | ------------- | ------- | --- | ---- |
| New API for HiDPI ([#315] [#319]) | ✔️ | ✔️ | ✔️ | ✔️ | ▢[#721] | ✔️ | ❓ |
| Event Loop 2.0 ([#459]) | ✔️ | ✔️ | | ✔️ | | ✔️ | ❓ |
| Keyboard Input ([#812]) | | | | ❌ | | ❌ | ❓ |

### Completed API Reworks
|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|------------------------------ | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
| Feature | Windows | MacOS | Linux x11 | Linux Wayland | Android | iOS | WASM |
| ------- | ------- | ----- | --------- | ------------- | ------- | --- | ---- |

[#165]: https://github.com/rust-windowing/winit/issues/165
[#219]: https://github.com/rust-windowing/winit/issues/219
Expand Down
102 changes: 86 additions & 16 deletions src/platform_impl/android/mod.rs
Expand Up @@ -180,47 +180,117 @@ impl<T: 'static> EventLoop<T> {
let device_id = event::DeviceId(DeviceId);
match &event {
InputEvent::MotionEvent(motion_event) => {
let phase = match motion_event.action() {
match motion_event.action() {
MotionAction::Down | MotionAction::PointerDown => {
Some(event::TouchPhase::Started)
let pointer = motion_event
.pointer_at_index(motion_event.pointer_index());
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: event::TouchPhase::Started,
location,
id: pointer.pointer_id() as u64,
force: None,
},
),
};

call_event_handler!(
event_handler,
self.window_target(),
control_flow,
event
);
}
MotionAction::Up | MotionAction::PointerUp => {
Some(event::TouchPhase::Ended)
}
MotionAction::Move => Some(event::TouchPhase::Moved),
MotionAction::Cancel => {
Some(event::TouchPhase::Cancelled)
}
_ => None, // TODO mouse events
};

if let Some(phase) = phase {
for pointer in motion_event.pointers() {
let pointer = motion_event
.pointer_at_index(motion_event.pointer_index());
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,
phase: event::TouchPhase::Ended,
location,
id: pointer.pointer_id() as u64,
force: None,
},
),
};

call_event_handler!(
event_handler,
self.window_target(),
control_flow,
event
);
}
}
MotionAction::Move => {
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: event::TouchPhase::Moved,
location,
id: pointer.pointer_id() as u64,
force: None,
},
),
};
call_event_handler!(
event_handler,
self.window_target(),
control_flow,
event
);
}
}
MotionAction::Cancel => {
for pointer in motion_event.pointers() {
let location = PhysicalPosition {
x: pointer.x() as _,
francesca64 marked this conversation as resolved.
Show resolved Hide resolved
y: pointer.y() as _,
};

let event = event::Event::WindowEvent {
window_id,
event: event::WindowEvent::Touch(
event::Touch {
device_id,
phase: event::TouchPhase::Moved,
francesca64 marked this conversation as resolved.
Show resolved Hide resolved
location,
id: pointer.pointer_id() as u64,
force: None,
},
),
};
call_event_handler!(
event_handler,
self.window_target(),
control_flow,
event
);
}
}
_ => (), // TODO mouse events
};
}
InputEvent::KeyEvent(_) => {} // TODO
};
Expand Down