bevy/crates/bevy_winit/src
Benjamin Brienen 818a8fe154
Allow unfocused window creation (#19237)
# Objective

Allow creating a new window without it being focused, when `Window`'s
`focused` is `false.
## Solution

Use `winit`'s `WindowBuilder`'s `with_active` method

## Notes

- `winit`'s doc lists [redox's
`Orbital`](https://gitlab.redox-os.org/redox-os/orbital) as an
unsupported platform, but since Bevy doesn't officially support this
platform, I didn't put it in the documentation.

- I only tested on Linux, which is an unsupported platform. I can give
you a test code if you want to test on another platform.

- I initially put a line
[here](https://github.com/bevyengine/bevy/blob/v0.11.0/crates/bevy_winit/src/system.rs#L72)
to set the Bevy `Window`'s `focused` to `winit_window.has_focus()` after
window creation to avoid the case where `with_active` is not supported,
the window is spawned focused, no `WindowFocused` event is triggered,
and Bevy `Window` would be desynced from winit's window. But after
testing on Linux (which doesn't support `with_active`) it seems like at
that point `has_focus` returns `false` and the event is triggered, so I
removed it. Do you think I should add it back to be safe?

## Changelog

- A new unfocused `Window` can be created by setting `focused` to
`false`.

## Migration Guide

- If a `Window` is spawned with `focused` set to `false`, it will now
start not focused on supported platforms.

Adopted from #9208

---------

Co-authored-by: Sélène Amanita <selene.amanita@net-c.com>
Co-authored-by: Sélène Amanita <134181069+Selene-Amanita@users.noreply.github.com>
Co-authored-by: atlv <email@atlasdostal.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2025-05-26 20:05:33 +00:00
..
accessibility.rs Remove remaining internal use of !Send resources (#18386) 2025-05-06 22:23:59 +00:00
converters.rs Expose deferred screen edges setting for ios devices (#18729) 2025-04-30 21:24:53 +00:00
cursor.rs Expose CustomCursorUrl (#19006) 2025-05-06 05:23:48 +00:00
custom_cursor.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
lib.rs Remove remaining internal use of !Send resources (#18386) 2025-05-06 22:23:59 +00:00
state.rs Add WakeUp event to App (#19212) 2025-05-26 19:26:26 +00:00
system.rs Remove remaining internal use of !Send resources (#18386) 2025-05-06 22:23:59 +00:00
winit_config.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
winit_monitors.rs Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
winit_windows.rs Allow unfocused window creation (#19237) 2025-05-26 20:05:33 +00:00