Skip to content

Commit

Permalink
Add correct window to touch pointers. (#297)
Browse files Browse the repository at this point in the history
* Add correct window to touch pointers.

* Cleanup and add changelog

---------

Co-authored-by: Aevyrie <aevyrie@gmail.com>
  • Loading branch information
NthTensor and aevyrie committed Mar 3, 2024
1 parent a5970ff commit d638ba0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# UNRELEASED

- Added: support for touch inputs across multiple windows.
- Changed: simplified debug settings and examples. Debug settings can be changed with the
`DebugPickingMode` resource.
- Fixed: replaced uses of `.insert` with `.try_insert`, where they could potentially panic.
Expand Down
19 changes: 8 additions & 11 deletions crates/bevy_picking_input/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_utils::{
tracing::{debug, info},
HashMap, HashSet,
};
use bevy_window::{PrimaryWindow, Window, WindowRef};
use bevy_window::{PrimaryWindow, WindowRef};

use bevy_picking_core::{
events::PointerCancel,
Expand All @@ -24,7 +24,7 @@ use bevy_picking_core::{
pub fn touch_pick_events(
// Input
mut touches: EventReader<TouchInput>,
windows: Query<(Entity, &Window), With<PrimaryWindow>>,
primary_window: Query<Entity, With<PrimaryWindow>>,
// Local
mut location_cache: Local<HashMap<u64, TouchInput>>,
// Output
Expand All @@ -36,15 +36,12 @@ pub fn touch_pick_events(
for touch in touches.read() {
let pointer = PointerId::Touch(touch.id);
let location = Location {
target: RenderTarget::Window(WindowRef::Primary)
.normalize(Some(
match windows.get_single() {
Ok(w) => w,
Err(_) => continue,
}
.0,
))
.unwrap(),
target: match RenderTarget::Window(WindowRef::Entity(touch.window))
.normalize(primary_window.get_single().ok())
{
Some(target) => target,
None => continue,
},
position: touch.position,
};
match touch.phase {
Expand Down

0 comments on commit d638ba0

Please sign in to comment.