-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix window spawning triggering ButtonInput<KeyCode>::just_pressed/just_released #12372
base: main
Are you sure you want to change the base?
Fix window spawning triggering ButtonInput<KeyCode>::just_pressed/just_released #12372
Conversation
Does this fix obsolete #12367 ? |
No, but it means I can leave out the "Currently this happens even if the focus switches from one Bevy window to another (for example because a new window was just spawned)" sentence. |
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.
On board with this behavior, but I'd like to avoid accumulating tech debt here. Can you please factor out the new filtering code into a function and add some tests for it? :)
The other question I have is: "why should this be in bevy_input
, rather than filtering events at the very top-level in bevy_winit
? That will save us work, and more importantly, ensure our data doesn't desynchronize.
Will do!
These events could be useful when reading |
@UkoeHB @aevyrie @mockersf any strong opinions here? I'm fine to leave this as a more scoped fix for now, especially with the logic extracted and tested. |
|
Sounds like that would be best.
Does anyone know how Bevy behaves on other platforms – when a user holds a key, Bevy loses focus, and then the user releases the key, at what point does |
Hi, I'm on macOS 14.3.1 x86 exercising the fn keyboard_input_system(keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.just_pressed(KeyCode::KeyA) {
info!("'A' just pressed");
}
if keyboard_input.just_released(KeyCode::KeyA) {
info!("'A' just released");
}
if keyboard_input.just_pressed(KeyCode::ShiftLeft) {
info!("'Shift' just pressed");
}
if keyboard_input.just_released(KeyCode::ShiftLeft) {
info!("'Shift' just released");
}
} The output is always pairs of press and release. I haven't been able to provoke two presses in a row (for the same key) or two releases in a row. However, if I press
Also if If one presses Exercising some of the same scenarios with the I hope this helps explain some of the behavior on macOS. Let me know if there are specific scenarios you'd like to see exercised. |
Thanks! Troublesome. Could you try the reverse (pressing A while not focused, then focusing the window)? And could you try this with also spawning a new window? …
info!("'A' just pressed");
commands.spawn(Window::default());
… Looks like it's a bit more work to be consistent across platforms. What behavior do we both want and support? For normal keys, maybe we need to deliberately interpret window focus loss as releasing all keys (and gaining focus as pressing the relevant ones). No idea what to do about modifier keys. |
Winit issue: rust-windowing/winit#3575 |
Sure thing. Pressing Spawning another window works fine for the |
Objective
Fix #12273
Solution
Filter out synthetic event from focus moving from one Bevy window to another.
Changelog
Fixed
ButtonInput<KeyCode>::just_pressed
/just_released
when spawning a window/focus moving between Bevy windows