Add input event callback to DisplayServerHeadless
#92806
Merged
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.
This adds input capabilities to
DisplayServerHeadless
. by simply adding an input event callback to it, in pretty much the exact same way as howDisplayServerMock
does it, while also removing the now redundant one fromDisplayServerMock
.This could perhaps be considered a mildly controversial change, seeing as how input handling is tied to windows in the eyes of the display server API, but in the interest of sparking a discussion about it, here it is.
The motivation for this isn't too complicated: When dealing with things like unit tests that run on a headless CI, it can be desirable to manually inject input events (with something like
Input.parse_input_event
) in order to test the input code paths, or perhaps simulate an actual user more accurately.This is technically possible already by relying on
Viewport.push_input
instead, but there you run into the problem that's mentioned in its documentation, namely that input emulation (likeinput_devices/pointing/emulate_touch_from_mouse
) doesn't exist in that context, leaving you to having to recreate/copy this emulation into your own code instead, which is somewhat unfortunate and potentially brittle. This emulation also can't be added toViewport.push_input
since that's in turn used byInput.parse_input_event
, so you'd end up not only with double emulation, but emulated events themselves triggering further emulation.The much simpler solution to this seems to be to just add an input event callback to
DisplayServerHeadless
, allowing you to useInput.parse_input_event
and its emulation just fine.