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
Add cursor grab for web target #2025
Conversation
I have implemented this independent of winit, and enabling pointer grab causes this call to throw a nasty error: https://github.com/rust-windowing/winit/blob/master/src/platform_impl/web/web_sys/canvas/pointer_handler.rs#L82-L84. We likely would need to disable this call when cursor grab is enabled.
|
Would not the correct way be to not have an expect in fallible code? The other way is if we could accurately predict that the state was actually that the pointer is already locked, that would solve your specific case, but since I do not know which ways that the pointerlock function can fail, its not a very good fix. I mean, unfortunately in web, elements are shared in an unsafe manner, making it hard to have full control. As you say, you can do JS calls on the element and rust code will not ( i believe ) have a chance to react to it? |
That sounds like a reasonable plan, I'll fork winit tonight and disable the expect to see what happens. |
@TotalKrill I just checked out your branch and disabled the expect there, and everything works as we expect. So with that one change I think this PR is ready to go. |
+ resolving the merge conflict for |
Im actually not entirely sure just removing the expect, I rather dislike silent errors Would a log::error! be okay to add after the set_pointer_capture() call? like this: let e = canvas.set_pointer_capture(event.pointer_id());
if !e.is_ok() {
log::error!("{:?}", e);
} |
ad4d1e2
to
4f11b67
Compare
The issue with a log is that the error will occur every single time you click the mouse when the cursor is grabbed. That would unnecessarily spam the logs. I don't think there's a situation where this could fail that we really care that it fails. |
4f11b67
to
40235bb
Compare
40235bb
to
bc9314f
Compare
I added a comment there and modified the commit message to be a bit more explicit |
After coming back to this PR, I've come to the conclusion that the PR is fine as-is, although I'd like to test it myself before approving it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work fine when I tested it.
Note that the chagelog entry will end up under the wrong release after merging. I suggest merging the latest |
code would crash if handling pointer capture outside of winit on every mouse click we swallow the error since we could not think of a case where this would fail in a way that would want to handle that it fails
I rebased the branch on top of master to get rid of the merge conflicts. Hope you don't mind :) I'll merge this in a bit. |
I definitely don't mind, in fact I am thankful 👍 |
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to users