Skip to content
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

Allow the creation of a Window in a not focused state #9208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Selene-Amanita
Copy link
Member

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 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 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.

@Selene-Amanita Selene-Amanita added C-Feature A new feature, making something new possible A-Windowing Platform-agnostic interface layer to run your app in A-Animation Make things move and change over time and removed A-Animation Make things move and change over time labels Jul 19, 2023
@Selene-Amanita Selene-Amanita added this to the 0.12 milestone Jul 19, 2023
@Selene-Amanita Selene-Amanita added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Jul 19, 2023
///
/// ## Platform-specific
///
/// - Android / iOS / X11 / Wayland: Can't be spawned unfocused.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it just at spawn time that it's not possible? can the window be set as unfocused?

Copy link
Member Author

@Selene-Amanita Selene-Amanita Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I didn't think about checking that.

Setting the window focused through code is not possible for "iOS / Android / Web / Wayland" so a different subset of platforms. I'll commit that later. https://docs.rs/winit/latest/winit/window/struct.Window.html#method.focus_window

Also I think it can never be set unfocused through code, here in Bevy's code:

            if window.focused != cache.window.focused && window.focused {
                winit_window.focus_window();
            }

If set to false later it will just be ignored? I need to mention that too.

What I wrote is only at spawn time yes: https://docs.rs/winit/latest/winit/window/struct.WindowBuilder.html#method.with_active

Maybe I can put a link to winit's doc for those two methods here, so people can check if Bevy's doc is outdated and more platforms are supported some day?

Copy link
Member Author

@Selene-Amanita Selene-Amanita Jul 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clarified that in this commit: 1e61bb6

Note that I think (didn't test to verify) that if it is set (from focused) to false, or set (from unfocused) to true on an unsupported platform, it will just be desynced. I can try to fix that in this PR but I think it would be better in a follow-up PR.

@alice-i-cecile alice-i-cecile removed this from the 0.12 milestone Sep 30, 2023
@Selene-Amanita Selene-Amanita added this to the 0.13 milestone Oct 1, 2023
@alice-i-cecile alice-i-cecile removed this from the 0.13 milestone Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Feature A new feature, making something new possible M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants