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

MouseMotion not working in browser as intended #11232

Closed
miketwenty1 opened this issue Jan 6, 2024 · 13 comments
Closed

MouseMotion not working in browser as intended #11232

miketwenty1 opened this issue Jan 6, 2024 · 13 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds
Milestone

Comments

@miketwenty1
Copy link

miketwenty1 commented Jan 6, 2024

Bevy version

main branch as of: #11231
Desktop / chrome / Wasm

What you did

Have a minimum viable system:

pub fn mouse_system(
    mut mouse_motion_events: EventReader<MouseMotion>,
    mouse: Res<ButtonInput<MouseButton>>,
) {
    for event in mouse_motion_events.read() {
        info!("1-{:#?}", event);
        if mouse.pressed(MouseButton::Middle) || mouse.pressed(MouseButton::Left) {
            info!("2-{:#?}", mouse);
        }
    }
}

This system doesn't register mouse motion until the screen has been "messed" with. Such that the screen is resized or you switch in and out of the screen after the bevy app loads.

You can see my whole code base here:
https://github.com/miketwenty1/bevy_broken

What went wrong

Here is a demo showing that I click in the button in the canvas and it still doesn't register mouse motion events.
the info!()'s only appear in the console after I resize the screen. After that I can click in the screen and then it registers the mouse motion events.
https://github.com/bevyengine/bevy/assets/7761473/cdb1f6a4-6630-4a67-b161-a77e58313d38

@miketwenty1 miketwenty1 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 6, 2024
@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more A-Windowing Platform-agnostic interface layer to run your app in O-Web Specific to web (WASM) builds and removed S-Needs-Triage This issue needs to be labelled labels Jan 6, 2024
@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Jan 6, 2024
@alice-i-cecile
Copy link
Member

I suspect this is related to #11052: smells like a winit / winit integration bug.

@daxpedda
Copy link
Contributor

daxpedda commented Jan 6, 2024

This looks like a bug in Winit.
Apparently Winit doesn't detect the canvas to be focused, which is why it doesn't send any device events.

Strangely enough I can only reproduce this in Bevy, Winit examples work fine.
But AFAICT Bevy doesn't mess with the canvas at all, so I will have to continue digging.

@daxpedda
Copy link
Contributor

daxpedda commented Jan 6, 2024

Should be fixed in rust-windowing/winit#3369 and will be backported to v0.29.10.

@miketwenty1
Copy link
Author

@daxpedda how do I take advantage of this for my bevy app?

@daxpedda
Copy link
Contributor

You have to wait until v0.29.10 gets released or port rust-windowing/winit#3369 yourself.
The intention is to get the next patch released soon.

@alice-i-cecile
Copy link
Member

Going to close as fixed (since it appears to be on main). If it still doesn't work there, or after the next release, please reopen this!

@miketwenty1
Copy link
Author

@alice-i-cecile I'm pointed to main and still have the same issue after using this commit 64a15f1

I still need to switch tabs or change change screen size in order to capture the mouse motion events for desktop/wasm.

@mockersf
Copy link
Member

it's waiting on a patch release of winit that didn't happen yet

@miketwenty1
Copy link
Author

miketwenty1 commented Jan 14, 2024

@mockersf is it this one?
rust-windowing/winit@d39528a
If not could you link the PR for tracking?

@mockersf
Copy link
Member

You have to wait until v0.29.10 gets released or port rust-windowing/winit#3369 yourself.

The intention is to get the next patch released soon.

This one

@miketwenty1
Copy link
Author

@mockersf you rock.

Note if I point to main for winit it will break bevy_winit right now.. but doing the specific commit mockersf referenced seems to solve this issue. if anyone else wants a temporary work around, I believe it's safe to add this to your cargo toml. Only tested against bevy main though, not 0.12.1.

[patch.crates-io]
winit = { git = "https://github.com/rust-windowing/winit.git", rev = "798c205cef1aa0c92eb43bef537583ce5b1ad1fb" }

To let you know of breaking changes on main right now, as I believe they'll need to be fixed for next winit patch, hope this helps:

error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
   --> /..../.cargo/git/checkouts/bevy-f7ffde730c324c74/5c6b7d5/crates/bevy_winit/src/lib.rs:783:18
    |
783 |     event_loop: &EventLoopWindowTarget<()>,
    |                  ^^^^^^^^^^^^^^^^^^^^^---- help: remove these generics
    |                  |
    |                  expected 0 generic arguments
    |
note: struct defined here, with 0 generic parameters
   --> /..../.cargo/git/checkouts/winit-c2fdb27092aba5a7/14b418a/src/event_loop.rs:51:12
    |
51  | pub struct EventLoopWindowTarget {
    |            ^^^^^^^^^^^^^^^^^^^^^

error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
  --> /..../.cargo/git/checkouts/bevy-f7ffde730c324c74/5c6b7d5/crates/bevy_winit/src/system.rs:38:18
   |
38 |     event_loop: &EventLoopWindowTarget<()>,
   |                  ^^^^^^^^^^^^^^^^^^^^^---- help: remove these generics
   |                  |
   |                  expected 0 generic arguments
   |
note: struct defined here, with 0 generic parameters
  --> /..../.cargo/git/checkouts/winit-c2fdb27092aba5a7/14b418a/src/event_loop.rs:51:12
   |
51 | pub struct EventLoopWindowTarget {
   |            ^^^^^^^^^^^^^^^^^^^^^

error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
  --> /..../.cargo/git/checkouts/bevy-f7ffde730c324c74/5c6b7d5/crates/bevy_winit/src/winit_windows.rs:43:41
   |
43 |         event_loop: &winit::event_loop::EventLoopWindowTarget<()>,
   |                                         ^^^^^^^^^^^^^^^^^^^^^---- help: remove these generics
   |                                         |
   |                                         expected 0 generic arguments
   |

@daxpedda
Copy link
Contributor

Winit v0.29.10 is out now.
Let me know if something is amiss!

@miketwenty1
Copy link
Author

works without patching in winit verison now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

4 participants