[Merged by Bors] - Allow closing windows at runtime#3575
[Merged by Bors] - Allow closing windows at runtime#3575DJMcNab wants to merge 7 commits intobevyengine:mainfrom
Conversation
alice-i-cecile
left a comment
There was a problem hiding this comment.
Looks good! Well-engineered and useful. I carefully reviewed the whole thing, but all I could find were a couple nits.
ff3b0d0 to
25da101
Compare
25da101 to
1f835c1
Compare
4f4d042 to
e5d5be4
Compare
|
@superdump, once you're happy with this, feel free to merge it in. |
|
I still want to finish cleaning up the docs. E.g. there's a sentence fragment remaining. Edit: I think it's now ready for final review/merge |
| /// If true, this plugin will add [`close_when_requested`] to [`CoreStage::Update`]. | ||
| /// If this system (or a replacement) is not running, the close button will have no effect. | ||
| /// This may surprise your users. It is recommended to leave this setting as `true`. | ||
| pub close_when_requested: bool, |
There was a problem hiding this comment.
I'm not sure this field should exist. I agree with you that it's unintuitive behavior to set this to false; when would app developers want to do this?
There was a problem hiding this comment.
For example, if the user has unsaved changes, it's traditional to give an 'unsaved changes' warning window.
There was a problem hiding this comment.
Ah, got it. In that case, this should be exposed as a resource: that behavior needs to be able to be changed dynamically.
There was a problem hiding this comment.
Not really? If a developer wants this functionality, they can easily enough add it themselves. This is merely making sure the default behaviour is correct, and we give an escape hatch for when people need more complicated logic.
That is, I don't really want to encourage disabling this, but I want to make the option available.
crates/bevy_winit/src/lib.rs
Outdated
| bevy_window::WindowCommand::Close => { | ||
| let window = winit_windows.remove_window(id); | ||
| // Close the window | ||
| drop(window); |
There was a problem hiding this comment.
Why do we need this explicit drop call? Shouldn't this just happen automatically at the end of the scope?
There was a problem hiding this comment.
I'm not sure. I think I was trying to clarify that the drop is what actually closes the operating system window. Since Window owns that window, I thought it better to be explicit about the side effects, and we can be sure that this drops at the expected time.
There was a problem hiding this comment.
Hmm. I think I'd prefer to just call winit_windows.remove_window(id) and have a comment explaining this mechanism.
alice-i-cecile
left a comment
There was a problem hiding this comment.
One blocking question about the necessity of the close_when_requested field.
I would also love to see tests for this, but I don't think that's feasible yet.
superdump
left a comment
There was a problem hiding this comment.
Looks good to me. I tested multiple_windows, hit esc twice, both windows closed and the app exited. Very nice!
|
bors r+ |
# Objective Fixes #3180, builds from #2898 ## Solution Support requesting a window to be closed and closing a window in `bevy_window`, and handle this in `bevy_winit`. This is a stopgap until we move to windows as entites, which I'm sure I'll get around to eventually. ## Changelog ### Added - `Window::close` to allow closing windows. - `WindowClosed` to allow reacting to windows being closed. ### Changed Replaced `bevy::system::exit_on_esc_system` with `bevy::window::close_on_esc`. ## Fixed The app no longer exits when any window is closed. This difference is only observable when there are multiple windows. ## Migration Guide `bevy::system::exit_on_esc_system` has been removed. Use `bevy::window::close_on_esc` instead. `CloseWindow` has been removed. Use `Window::close` instead. The `Close` variant has been added to `WindowCommand`. Handle this by closing the relevant window.
|
Build failed: |
Make the rest of bevy work with multiple windows Remove exit_on_esc Add suggested docs
Since their brokeness isn't my fault
|
bors r+ |
# Objective Fixes #3180, builds from #2898 ## Solution Support requesting a window to be closed and closing a window in `bevy_window`, and handle this in `bevy_winit`. This is a stopgap until we move to windows as entites, which I'm sure I'll get around to eventually. ## Changelog ### Added - `Window::close` to allow closing windows. - `WindowClosed` to allow reacting to windows being closed. ### Changed Replaced `bevy::system::exit_on_esc_system` with `bevy::window::close_on_esc`. ## Fixed The app no longer exits when any window is closed. This difference is only observable when there are multiple windows. ## Migration Guide `bevy::input::system::exit_on_esc_system` has been removed. Use `bevy::window::close_on_esc` instead. `CloseWindow` has been removed. Use `Window::close` instead. The `Close` variant has been added to `WindowCommand`. Handle this by closing the relevant window.
# Objective Fixes bevyengine#3180, builds from bevyengine#2898 ## Solution Support requesting a window to be closed and closing a window in `bevy_window`, and handle this in `bevy_winit`. This is a stopgap until we move to windows as entites, which I'm sure I'll get around to eventually. ## Changelog ### Added - `Window::close` to allow closing windows. - `WindowClosed` to allow reacting to windows being closed. ### Changed Replaced `bevy::system::exit_on_esc_system` with `bevy::window::close_on_esc`. ## Fixed The app no longer exits when any window is closed. This difference is only observable when there are multiple windows. ## Migration Guide `bevy::input::system::exit_on_esc_system` has been removed. Use `bevy::window::close_on_esc` instead. `CloseWindow` has been removed. Use `Window::close` instead. The `Close` variant has been added to `WindowCommand`. Handle this by closing the relevant window.
# Objective Fixes bevyengine#3180, builds from bevyengine#2898 ## Solution Support requesting a window to be closed and closing a window in `bevy_window`, and handle this in `bevy_winit`. This is a stopgap until we move to windows as entites, which I'm sure I'll get around to eventually. ## Changelog ### Added - `Window::close` to allow closing windows. - `WindowClosed` to allow reacting to windows being closed. ### Changed Replaced `bevy::system::exit_on_esc_system` with `bevy::window::close_on_esc`. ## Fixed The app no longer exits when any window is closed. This difference is only observable when there are multiple windows. ## Migration Guide `bevy::input::system::exit_on_esc_system` has been removed. Use `bevy::window::close_on_esc` instead. `CloseWindow` has been removed. Use `Window::close` instead. The `Close` variant has been added to `WindowCommand`. Handle this by closing the relevant window.
# Objective Fixes bevyengine#3180, builds from bevyengine#2898 ## Solution Support requesting a window to be closed and closing a window in `bevy_window`, and handle this in `bevy_winit`. This is a stopgap until we move to windows as entites, which I'm sure I'll get around to eventually. ## Changelog ### Added - `Window::close` to allow closing windows. - `WindowClosed` to allow reacting to windows being closed. ### Changed Replaced `bevy::system::exit_on_esc_system` with `bevy::window::close_on_esc`. ## Fixed The app no longer exits when any window is closed. This difference is only observable when there are multiple windows. ## Migration Guide `bevy::input::system::exit_on_esc_system` has been removed. Use `bevy::window::close_on_esc` instead. `CloseWindow` has been removed. Use `Window::close` instead. The `Close` variant has been added to `WindowCommand`. Handle this by closing the relevant window.
# Objective - Avoid unbounded HashMap growth for opening/closing windows. ## Solution - Remove map entry in `WinitWindows::remove_window`. ## Migration Guide - `WinitWindows::get_window_entity` now returns `None` after a window is closed, instead of a dead entity. --- ## Comments The comment this PR replaces was added in #3575. Since `get_window_entity` now returns an `Entity` instead of a `WindowId`, this no longer seems useful. Note that `get_window_entity` is only used [here](https://github.com/bevyengine/bevy/blob/56bcbb097552b45e3ff48c48947ed8ee4e2c24b1/crates/bevy_winit/src/lib.rs#L436), immediately followed by a warning if the entity returned doesn't exist.
Objective
Fixes #3180, builds from #2898
Solution
Support requesting a window to be closed and closing a window in
bevy_window, and handle this inbevy_winit.This is a stopgap until we move to windows as entites, which I'm sure I'll get around to eventually.
Changelog
Added
Window::closeto allow closing windows.WindowClosedto allow reacting to windows being closed.Changed
Replaced
bevy::system::exit_on_esc_systemwithbevy::window::close_on_esc.Fixed
The app no longer exits when any window is closed. This difference is only observable when there are multiple windows.
Migration Guide
bevy::input::system::exit_on_esc_systemhas been removed. Usebevy::window::close_on_escinstead.CloseWindowhas been removed. UseWindow::closeinstead.The
Closevariant has been added toWindowCommand. Handle this by closing the relevant window.