Fix TouchPhase::Ended reporting on Wayland

When all the receive from the compositor is `TouchEvent::Down` and
`TouchEvent::Up` for the same id, we would record the touch position in
the touch_points vector the first time. On `TouchEvent::Up` we'd find it
and report `TouchPhase::Ended` with that location. The next time we
receive `TouchEvent::Down` for the same id, we'd however unconditionally
append a new `TouchPoint` to `inner.touch_points`, with the new
position. On release however we'd find the earlier point and report its
location, which basically means that `TouchPhase::Ended` always and
forever reported the location of the very first touch down event.

Instead, this patch updates an existing touch point location with the
same id on `TouchDown`.

Fixes #1996
This commit is contained in:
Simon Hausmann 2022-04-11 19:13:28 +02:00 committed by GitHub
parent aac28d24ac
commit a58400a82c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -33,6 +33,8 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, fix race issue creating fullscreen windows with `WindowBuilder::with_fullscreen` - On Windows, fix race issue creating fullscreen windows with `WindowBuilder::with_fullscreen`
- On Android, `virtual_keycode` for `KeyboardInput` events is now filled in where a suitable match is found. - On Android, `virtual_keycode` for `KeyboardInput` events is now filled in where a suitable match is found.
- Added helper methods on `ControlFlow` to set its value. - Added helper methods on `ControlFlow` to set its value.
- On Wayland, fix `TouchPhase::Ended` always reporting the location of the first touch down, unless the compositor
sent a cancel or frame event.
# 0.26.1 (2022-01-05) # 0.26.1 (2022-01-05)

View file

@ -44,9 +44,15 @@ pub(super) fn handle_touch(
window_id, window_id,
); );
inner // For `TouchEvent::Up` we don't receive a position, so we're tracking active
.touch_points // touch points. Update either a known touch id or register a new one.
.push(TouchPoint::new(surface, position, id)); if let Some(i) = inner.touch_points.iter().position(|p| p.id == id) {
inner.touch_points[i].position = position;
} else {
inner
.touch_points
.push(TouchPoint::new(surface, position, id));
}
} }
TouchEvent::Up { id, .. } => { TouchEvent::Up { id, .. } => {
let touch_point = match inner.touch_points.iter().find(|p| p.id == id) { let touch_point = match inner.touch_points.iter().find(|p| p.id == id) {