bevy/crates/bevy_winit/src
Knar 1e3ecbefdb
Handle failed cursor grab mode changes so that the cursor grab mode change can be attempted again (#16293)
# Objective

- Currently when you attempt to change the cursor_grab_mode it caches
the new value whether the cursor grab succeeded or failed. This change
handles the Result being returned by set_cursor_grab and changes the
cursor_grab_mode back to the cached version in case of an Error.
- Creates a way to handle #16237 and #16238

## Solution

- I changed the signature of winit_windows attempt_grab to return the
Result<(), ExternalError> that winit set_cursor_grab returns. The system
that calls attempt_grab now checks if there's an error returned, and if
there is it sets the grab_mode back to the cached version (similar to
what hit_test does a few lines down).

## Testing

- I tested using this system that previously would not correctly lock
the mouse on Ubuntu/x11
```
pub fn lock_mouse(mut primary_window: Query<&mut Window, With<PrimaryWindow>>) {
    let window = &mut primary_window.single_mut();
    if window.focused {
        window.cursor_options.grab_mode = CursorGrabMode::Confined;
    } else {
        window.cursor_options.grab_mode = CursorGrabMode::None;
    }
}
```
- I only tested on Ubuntu with x11
2024-11-09 23:30:57 +00:00
..
accessibility.rs Remove accesskit re-export from bevy_a11y (#16257) 2024-11-08 21:01:16 +00:00
converters.rs Correctly feature gate custom_cursor (#16093) 2024-11-02 01:47:32 +00:00
cursor.rs properly flag using CustomCursor::Url in wasm (#16255) 2024-11-06 13:14:12 +00:00
lib.rs Correctly feature gate custom_cursor (#16093) 2024-11-02 01:47:32 +00:00
state.rs Correctly feature gate custom_cursor (#16093) 2024-11-02 01:47:32 +00:00
system.rs Handle failed cursor grab mode changes so that the cursor grab mode change can be attempted again (#16293) 2024-11-09 23:30:57 +00:00
winit_config.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
winit_monitors.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
winit_windows.rs Handle failed cursor grab mode changes so that the cursor grab mode change can be attempted again (#16293) 2024-11-09 23:30:57 +00:00