Skip to content

Add DeviceEvent::MouseMove on web platform to support pointer lock - #1827

Merged
elliegoldstein merged 6 commits into
rust-windowing:masterfrom
willcrichton:master
Feb 16, 2021
Merged

elliegoldstein merged 6 commits into
rust-windowing:masterfrom
willcrichton:master

Conversation

@willcrichton

Copy link
Copy Markdown
Contributor

I'm using winit with web/wasm via Bevy. Bevy relies on DeviceEvent::MouseMotion events to compute mouse movement deltas, and DeviceEvent::MouseMotion was not implemented for the web platform. WindowEvent::CursorMoved events didn't work for my use case because the x/y didn't update as the cursor moved when locked. I added a MouseMotion event to the web platform that uses the movement_x/y fields. I tested that my changes work within a Bevy web app.

pointer_lock_small mp4

I'm not sure if this is the "Device movement events" entry in the "Input handling" feature matrix?

@alvinhochun

Copy link
Copy Markdown
Contributor

Looks ok-ish to me (haven't tested yet)

@ryanisaacg perhaps you can give this a look if you have time?

Comment thread CHANGELOG.md Resolved
@elliegoldstein

Copy link
Copy Markdown
Contributor

LGTM

@willcrichton

willcrichton commented Feb 16, 2021 •

Copy link
Copy Markdown
Contributor Author

Would y'all be ok to merge this PR if everything looks good? (cc @alvinhochun )

@elliegoldstein
elliegoldstein merged commit 7e0c6ee into rust-windowing:master Feb 16, 2021
@creikey

creikey commented May 29, 2021

Copy link
Copy Markdown

Should this close this issue #1792 ?

@maroider

maroider commented May 29, 2021 •

Copy link
Copy Markdown
Member

Probably.

@TotalKrill

Copy link
Copy Markdown
Contributor

I found a way to make this compatible with bevy 0.5 from crates.io, it requires you to patch winit that is used in all bevy related assets. I created a branch that contains @willcrichtons implementation, and on top of that added some dummy-fixes that enables the latest version of winit, with all the fixes included to be patched on top of bevy 0.5. Meaning that all addon crates also works with this ( as far as i can tell).

It only requires two lines to the Cargo.toml file of your project

TLDR: Add the below to your Cargo.toml to enable cursor grab in web, for bevy 0.5 projects.

[patch.crates-io]
winit = { git  = "https://github.com/TotalKrill/winit.git", branch = "dummy-feature", version = "0.24" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants