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

Make CursorGrabMode a State #17920

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

Conversation

Atlas16A
Copy link

Objective

Keeping various systems from running when the window isn't viewed/holding the mouse such as player movement requires needless extra steps.

Solution

Makes it so that users can use cursor grab mode as a state to control system runs.

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@Atlas16A Atlas16A added the D-Trivial Nice and easy! A great choice to get started with Bevy label Feb 18, 2025
@mockersf
Copy link
Member

It's possible to have several windows with different CursorGrabMode. What would the state mean in this case?

I would rather not have this in Bevy, and it's easy enough for an application that needs this to newtype CursorGrabMode and handle it as a state on its own.

@rparrett
Copy link
Contributor

A couple other potential issues:

  • Users would need to synchronize their window's state with this state. This seems awkward.
  • This is a three-variant enum where you most likely only care about two variants, but need to deal with all three if you're managing the cursor in a cross-platform way.

You can probably get your desired behavior with a run condition.

app.add_systems(Update, some_system.run_if(cursor_grabbed));

fn cursor_grabbed(windows: Query<&Window, With<PrimaryWindow>>) -> bool {
    for window in &windows {
        return window.cursor_options.grab_mode != CursorGrabMode::None;
    }
    false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants