Added InputSource
as an ID for input event sources
#10769
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Solution
InputSource
as a platform and library agnostic identifier for input-like events. This type is purely an identifier with no inherit meaning beyond its self comparison. It is up to the writers of input events to provide any additional meaning to theseInputSource
field, disambiguating the source of the event.Changelog
InputSource
identifier type.InputSources
resource for creatingInputSource
IDs. SinceInputSource
is purely a unique ID,InputSources
is just a counter.source: InputSource
field.Migration Guide
source
field of typeInputSource
. If you don't require it when reading, discard its value (e.g., during pattern matching). If writing one of these input events, use theInputSources
resource to create anInputSource
ID that you must manage.Tasks
winit::event::Event::DeviceEvent
's, not justWindowEvent::DeviceEvent
(these are confusingly different). Currently this only provides meaningful disambiguation forGamepad
events, andMouseMotion
(at least on my test platform).winit
provides aDeviceId
withWindowEvent
's, but for whatever cause (Windows,winit
, etc.), the ID provided for those events is always for the "primary" device. Whereas,DeviceEvent
events do include the specific device. This can currently be best observed in themouse_input_events
example, which will disambiguateMouseMotion
, but notMouseButtonInput
. I think the solution to this is to duplicate the event types (similar toCursorPosition
vsMouseDelta
).Entity
by an arbitrary value (e.g., awinit
DeviceId
component), and registering a new input source would require world access for allocating anEntity
. But, it could be powerful for adding arbitrary metadata (e.g.,GamepadInfo
) to input sources.Notes
Inputs
resources to provide this extra information right now to keep the scope of changes small. Providing this information on the input events is, in my opinion, the bare minimum to allow a Bevy user to utilise multiple mice, keyboards, etc.Gamepad
type to contain anInputSource
instead of ausize
as its ID.