-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Reduce usage of PrimaryWindow
#18362
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
Comments
@viridia is there a reason why And API-wise there, would y'all prefer a required Or perhaps: A required |
The question, as posed, seems kind of abstract - do you have a concrete use case in mind? I'll be honest, in all my years of playing and making games, I have never experienced a game that used more than one window, so it's hard for me to know exactly how multiple windows ought to behave in a game context. However, I have used non-game productivity apps that had more than one window. In these cases, there was only one input focus - that is, only one window could have focus at a time, and only one widget within that window could have focus. So it makes sense to me that input focus would be a singleton. Focus behavior isn't really something that applications are supposed to make up for themselves; rather, it's part of the general user interface guidelines for the operating system (the Macintosh Computer Interface Guidelines had a long chapter on this, however that book is no longer in print). And most operating systems assume that there is one keyboard input device active at any given time, or at the very least, if there are multiple keyboard input devices (like a separate numpad) they are all being controlled by the same user. Mostly I tried to model things on the browser / JavaScript APIs for managing focus, since that's what I know best. The usage of PrimaryWindow is a bit trickier here: mainly it's only meant to be used as a fallback when no widget has focus, so we have somewhere to bubble events to. However, it could also be changed to use whichever window has focus; but at the time I did not know how to get that information from winit. |
I think my point with making focus window-relative is that when switching between windows (e.g. two text-boxes in two Firefox windows), you want to keep whatever item is focused focused, regardless of the window itself loosing focus. But perhaps I'm misunderstanding the design of In any case, you're correct that multi-window support is rare in games. |
Preserving focus when switching windows is a reasonable thing to want, I agree. However, making focus a non-global puts a heavy burden on widget authors. Most widgets just want to know, "am I focused or not?" so that they can draw themselves differently when that is true. Widgets don't generally have knowledge of what window contains them, to answer the question "am I focused" they would need to walk up the hierarchy, find the target camera component, use that to look up the window, etc. This makes it a lot more complicated. |
Bevy has multi-window support by modelling each window as an entity, and then (heavily handwaving) delegating to Winit for the rest. The user can then choose:
World
, to allow e.g. running multiple instances of their game (not really supported yet, but I assume this is roughly how we'd go about it).This is all great, but unfortunately, some functionality uses the
PrimaryWindow
to implement their windowing. This is basically never desired, as it locks that piece of functionality to only being available in a single window. This issue is intended to track removing instances of this, to improve multi-window support.I've condensed the usages of
PrimaryWindow
to essentially the following:bevy_render::camera::RenderTarget::normalize
should be changed to not need the primary window. Affectsbevy_core_pipeline
,bevy_picking
,bevy_sprite
andbevy_ui
.bevy_input_focus::InputFocus
(and possiblyInputFocusVisible
) should be madeComponent
s on the windowEntity
instead ofResource
s. Affectsbevy_winit
's ability to update accessibility nodes.bevy_text
: , seems to be a remnant of Support window independent UI scaling #5621.A few previous efforts in this vein:
PrimaryWindow
regardless of target #14945To be clear: I'm not advocating we get rid of
PrimaryWindow
, it can be useful for the user, and it's useful for controlling the close behaviour inbevy_window
(also discussed in #13698). But we should avoid using it internally in Bevy (perhaps even add it as a Clippydisallowed-types
?).The text was updated successfully, but these errors were encountered: