MouseButton and KeyBoard events should contain WindowID #4649
Labels
A-Input
Player input via keyboard, mouse, gamepad, and more
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
Milestone
What problem does this solve or what need does it fill?
if i have Primary and Secondary windows for my app/game, and lets say Primary window is in focus. if i click on Secondary window, we will get a CursorLeft / FocusLost for Primary window, CursorEntered / FocusGain for Secondary Window. and in the global event reader for MouseButtonInput, we will get a Press/Release events due to the click. The issue is that I have no way of knowing which window the click belongs to?
The usecase is integration of bevy_egui mvlabat/bevy_egui#61 .
a simple alternative use case would be PrimaryWindow containing a 3d game player, and W pressed on primary window might mean to move player forward. but on Secondary Window, we might have a Map or something, and pressing W might mean to move the map center towards south so that we can browser at the further north part of the map. W pressed event means different things for different windows.
What solution would you like?
The easiest would be to have WindowID attached to the MouseButtonInput and Keyboard events just like CursorEntered/Left or Focus events. winit provides that. glfw provides that. sdl2 provides that. so, its the easiest workaround at the moment to just let people deal with manual events. but to go above and beyond, bevy can provide alternative functions like https://docs.rs/bevy/latest/bevy/input/struct.Input.html#method.pressed which take the windowID as another argument to query the input state of Secondary windows, rather than just the primary or global keyboard state.
What alternative(s) have you considered?
timestamps
glfw and sdl2 provide timestamps for events which can be used to order the events and check whether the click happened after the cursor Left or before it. then, based on that whether a specific click should be sent to secondary or primary window. well, there might be a little more work to do like checking if there's a release before press event, in which case the release might belong to the previous window's press etc... but idk what you would do with winit as it doesn't provide timestamps.
ignore corner cases
during the frame that focus shifts from one window to another, just consider ALL clicks or other events to belong to the second window. it will lead to some corner case bugs, but time is scarce resource and this might not be worth the effort.
Additional context
There's two problems mentioned here:
The text was updated successfully, but these errors were encountered: