-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Refactor window creation logic #22088
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
Refactor window creation logic #22088
Conversation
|
I think, if possible, the change to remove all the custom_user_event and generic stuff should be in a separate PR. The main reason for this is if we ever find a user that does need it then it's easier to only revert that change instead of all your changes together. |
That's not easily possible, this change uses the generic in |
|
Ah, your comment said you were happy to re-add it so I interpreted that as being easy to do 😅 |
It is easy, but it would have to build on top of this PR, as the 2 things conflict. I'd prefer if we figure out what we want first so I can make this PR do it, instead of having 2 conflicting PRs. |
|
winit apparently agrees with me, as they have also removed the generic user messages in the beta for version 0.31, see https://github.com/rust-windowing/winit/blob/master/winit/src/changelog/v0.31.md?plain=1#L77 |
IceSentry
left a comment
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.
Alright, well, I can't think of a reason to keep it anyway so LGTM.
This needs a migration guide though
atlv24
left a comment
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.
nice improvement
tychedelia
left a comment
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.
Thanks, this code is always gnarly.
Objective
Fixes #21948
Currently we tell winit to spawn any new
Windows during theabout_to_waitlifecycle method, but that's unreliable: if no new events appear while we're already waiting it could take an arbitrarily long time, or no new events could appear at all so we never spawn the window. This is especially bad when going from 0 to 1Windows, as many events are related to the existing window.Solution
Check for new windows in
resumedfor the initial window (which is also what winit examples do) and inuser_eventfor new windows.I also did some other improvements while I was investigating this:
Added<Window>query filter intoCreateWindowParams, as the logic didn't make sense with any other filter.EventLoopProxyWrapperresource when the plugin builds instead of inside thewinit_runner. This currently makes no practical difference, but in another version of this PR I had a crash because the observer tried to use the resource before the runner started. It's also a more natural way to do it.WinitPluginno longer generic, and removed thecustom_user_eventexample. The functionality it provides (being able to send events into bevy from the outside) only works in one direction, and I don't see why it needs to go via winit instead of a dedicated plugin with channels.If this feature is useful for reasons I've missed then I'm happy to re-add it.edit: winit is removing custom user events in 0.31, which made me even more confident it's the right direction for us too.Testing
Run different examples and see that the window spawns in a timely fashion, edit the
multiple_windowsexample as in #21948 and see that the window spawns.