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

bevy::window::Window should support setting & Querying Focus status #1327

Closed
huhlig opened this issue Jan 27, 2021 · 1 comment
Closed

bevy::window::Window should support setting & Querying Focus status #1327

huhlig opened this issue Jan 27, 2021 · 1 comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Feature A new feature, making something new possible

Comments

@huhlig
Copy link
Contributor

huhlig commented Jan 27, 2021

What problem does this solve or what need does it fill?

Currently the window status is not easily available without tracking window events in a separate resource.

What solution would you like?

Add a new system to bevy_window to process WindowFocused Events and keep track of which window is focused at any given time. Also create a new Window Command to force a window be brought to the front and focused.

What alternative(s) have you considered?

Maintaining a separate Resource and System to process these events. The workaround is not insurmountable and this feature is simply a quality of life improvement.

Example

fn look_around_system(
    mut windows: ResMut<Windows>,
    mouse_button: Res<Input<MouseButton>>,
    mouse_motion: Res<Events<MouseMotion>>,
) {
    let window = windows.get_primary_mut().unwrap();
    if window.is_focused() && mouse_button.pressed(MouseButton::Right) {
        for event in state.reader_motion.iter(&mouse_motion) {
            // Look Around with Camera
        }
    }
}
@karroffel karroffel added C-Feature A new feature, making something new possible A-Windowing Platform-agnostic interface layer to run your app in labels Jan 30, 2021
cart pushed a commit that referenced this issue Feb 13, 2021
…he window and related system (#1386)

* Simple Implementation to address #1327 by adding a focused field to the window and related system

* Changing Window update function from bevy_window to bevy_winit.

* Removing unused imports.
@nicopap
Copy link
Contributor

nicopap commented Apr 18, 2023

bevy_winit now updates the Window::focused component (

window.focused = focused;
) So it's trivial to read the focus state of any window without managing mutable internal state.

@nicopap nicopap closed this as completed Apr 18, 2023
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
Projects
None yet
Development

No branches or pull requests

3 participants