-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Replace winit's synthetic events by our own key tracking #14379
base: main
Are you sure you want to change the base?
Conversation
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.
Code looks good to me!
Will this fix the issue of the Alt key "sticking" when alt-tabbing out of the browser running a WASM build? Logic seems like it should so long as WASM builds correctly track window focus. |
Yep, this should fix it. |
@richchurcher @SpecificProtagonist can I have your review over here please? |
I updated it for #12372, though I have a couple concerns on reliability:
|
Extra release events should generally be safe enough.
I think this is broadly fine.
Emitting it in both would be good. |
Fair. They are now emitted in both streams 👍 |
Objective
Defocusing a window while a key is held (such as when Alt+tabbing), will currently send a key release on X11 and Windows. This is likely the behavior that most people expect.
However it's synthetic events from winit are unimplemented for WASM and some other platforms. (See rust-windowing/winit#1272).
While we can implement it upstream, there is also some doubt about the synthetic events API as a whole (rust-windowing/winit#3543), so I propose to do it in bevy directly for now.
Solution
This PR implements key tracking in bevy directly so we can synthesize our own key release events across all platforms.
Note regarding X11 specifically:
main
, pressing a keyboard shortcut to unfocus the window (Ctrl + Super + ArrowRight
in my case) will yield the following events:To me the behavior of this branch is more expected than
main
, becausemain
produces anArrowRight
release without producing a press first.Testing
Tested in WASM and X11 with