-
-
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
Fix window spawning triggering ButtonInput<KeyCode>::just_pressed/just_released #12372
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 |
560082e
to
d7bcb8e
Compare
#13696 resolved the question of how we should handle synthetic events and #13678 changed what we do on window focus loss. I've reworked this to take these into account. This also means the logic that needs a unit test is gone; an integration test with actual input would still be helpful, but we don't have the setup for that. |
@SpecificProtagonist sorry to be a pain, any chance you could update your branch to make it a tad easier to review? Be nice to get this one into 0.15 🙂 |
I note that this and #14379 are doing related things, though I'm not quite sure of the subtleties around whether one makes the other redundant 🤔 |
Well spotted – both remove handling of synthetic key releases. However that PR still sets |
…t_released (bevyengine#12372) # Objective Fix bevyengine#12273 ## Solution – Only emit `KeyboardFocusLost` when the keyboard focus is lost – ignore synthetic key releases too, not just key presses (as they're already covered by `KeyboardFocusLost`) --- ## Changelog ### Fixed - Don't trigger `ButtonInput<KeyCode>::just_pressed`/`just_released` when spawning a window/focus moving between Bevy windows
I'm still receiving KeyboadFocusLost intermittently when switching between bevy windows 😕 I think this happens because sometimes the app processes events after one window lost focus, but just before the other window gained focus. 1728136435.mp4 |
Objective
Fix #12273
Solution
– Only emit
KeyboardFocusLost
when the keyboard focus is lost– ignore synthetic key releases too, not just key presses (as they're already covered by
KeyboardFocusLost
)Changelog
Fixed
ButtonInput<KeyCode>::just_pressed
/just_released
when spawning a window/focus moving between Bevy windows